Computer Code

Newsflash: The second edition of Bayesian econometric methods has now been published.

Click here to purchase the book and here for code and data.

Gary Koop's Page of Matlab Code

This page contains the computer code associated with my monograph, "Bayesian Multivariate Time Series Methods for Empirical Macroeconomics",

Foundations and Trends in Econometrics, co-authored with Dimitris Korobilis along with some Dynamic Model Averaging code. Computer code for a few of my other published papers is given on the research page of this website (look under the specific paper you are interested in).

Dimitris Korobilis also has a code page which includes many interesting models, some relating to co-authored work with me. He also has links to several other websites containing Matlab code for many related models. The same applies to Joshua Chan who has an excellent code page some of which relates to our co-authored work. So if you do not find something you want here, please look at these pages. Florian Huber also has an excellent page of code which includes some of our co-authored work.

Computer code associated with my textbooks, Bayesian Econometrics and Bayesian Econometric Methods is available on the websites of these books.

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. And Boris Demeshev has produced R versions of some of this code. This is available by clicking here.

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

The following programs are set-up so as to produce the empirical illustrations in "Bayesian Multivariate Time Series Methods for Empirical Macroeconomics". 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.

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, JOE) is available here.

    • Code for BVAR with variable selection as in Korobilis (2013,JAE) 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.

UPDATE 2014 in relation to TVP-VARs and TVP-FAVAR:

Note that code which allows estimation of stochastic volatility as in Primiceri (2005) has been amended to take into account the corrigendum of Del Negro and Primiceri (2013) which can be found here

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 (2013) 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.