MATLAB Code for Bayesian Inference in VARs, TVP-VARs and TVP-FAVARs


This website contains Matlab code for carrying out Bayesian inference in the models discussed in "Bayesian Multivariate Time Series Methods for Empirical Macroeconomics" by Gary Koop and Dimitris Korobilis. The user is referred to that monograph which is available here

A manual which provides complete technical details (e.g. of posterior conditionals used in MCMC algorithms) is available here.

The programs are set-up so as to produce the empirical illustrations in the monograph. Minor alterations are required (as indicated in the code) for different prior choices, data sets, etc.

Note that code for each model is organized so that the main program is capitalized (e.g. BVAR_GIBBS.m) and functions and scripts called by the main program are in small letters. The easiest thing to do is download the main program and all scripts into one folder.

Note also that most programs are set up to either load in a data set (which is provided) or generate artificial data.

Users may also be interested in knowing that Estima has been running courses using my textbook Bayesian Econometrics (published by Wiley) and has created code using the computer package RATS. You can find find this code by clicking here.

MATLAB Code for Bayesian VARs

  • Code for BVAR where analytical results are available (Natural conjugate, Noninformative or Minnesota Prior) is available here
  • Code for BVARs using independent Normal-Wishart prior with requires Gibbs sampling is available here
  • Code for BVAR with SSVS prior of George, Sun and Ni (2008) is available here.
  • Code for BVAR with variable selection as in Korobilis (2009b) is available here.
  • Complete set of BVAR code for empirical illustration in monograph is available here. This allows for user to select one of six different priors and calculates impulse responses using the identification scheme described in the monograph.

MATLAB Code for TVP-VARs

  • Code for TVP-VAR using the Carter and Kohn (1994) algorithm as implemented in Primiceri (2005) is available here. Note that there are two versions of the program: one is homoskedastic, one has multivariate stochastic volatility of the same sort as Primiceri (2005).
  • Code for TVP-VAR using the Durbin and Koopman (2002) algorithm for state space models is available here. There is only a homoskedastic version of the code.
  • Code for TVP-VAR combined with mixture innovation model as in Koop, Leon-Gonzalez and Strachan (2009) is available here. The program has multivariate stochastic volatility of the same sort as Primiceri (2005).
  • Code for hierarchical TVP-VAR using approach of Chib and Greenberg (1995) is available here. There is only a homoskedastic version of this code.

MATLAB Code for Factor Models

  • Code for static and dynamic factor models is available here.
  • Code for the FAVAR is available here
  • Code for TVP-FAVAR as in Korobilis (2009a) is available here.

MATLAB Code for Dynamic Model Averaging

This code is provided for doing DMA as in the paper:  Forecasting inflation using DMA by Koop and Korobilis. This code is not as clean as the other code on this website, has less explanatory material and may be unsuitable for use by novices. For those trying to replicate our paper, note that the published version of the paper uses a different data set. Also, the tables in the old working paper version linked above have a small error: they present sums of forecast errors squared rather than means. We do not offer any support for this code.

Health warnings:

The programs are reasonably easy to use and follow the empirical examples in our monograph. There is, however, a need for caution. A knowledge of Bayesian econometrics is assumed, including recognition of the potential importance of prior distributions, and MCMC methods are inherently less robust than analytic econometric methods. There is no in-built protection against misuse.

These programs can be freely downloaded for academic purposes. Although every effort has been made to ensure that these programs are error free, we cannot guarantee this. If you find any errors, please let us know (Gary.Koop@strath.ac.uk or dikorobilis@googlemail.com).

We do not offer any support or user help facilities for these programs. These programs were written in MATLAB release 2008 and there may be minor incompatibilities with earlier versions. Note in particular that our programs use cell arrays which were not included in very old versions of MATLAB.