How to Stack the Equations of a VAR
Guide 1 of 4 in the series Getting Started with Bayesian VARs
Based on Bayesian Macroeconometrics (Chan, forthcoming)
[ Full guide on GitHub ]
A VAR is a system of regressions in which every equation has the same regressors, and it can be stacked in two ways. The matrix form Y = ZA+U keeps one column per equation, and the stacked form y = Xβ+ε is one long linear regression. The posterior under the natural conjugate prior is written in the first form, and that under the independent prior in the second. In this guide we build both forms from generated data with bvar.util.build_lags and bvar.util.surform2, check that they give the same likelihood, and show that least squares equation by equation is already generalized least squares for the whole system. Then we drop regressors from one equation and see what changes. Throughout, the coefficients are estimated by least squares; in How to Draw the VAR Coefficients under the Minnesota Prior we place a prior on them.
The steps
- Build the Regressors
- The Matrix Form
- The Stacked Form
- Generalized Least Squares and the Kronecker Shortcut

Figure 1: The nonzero entries of Z (left) and of X (right) for the first four periods. Row t of Z is xt'; block t of X has n = 3 rows, and its row i holds xt' in the seven columns of equation i.
Try it
In MATLAB, from the root of a copy of bvar-toolkit, run the script that prints every number and draws every figure of the guide:
run guides/var_stacking/guide.m
In this series
Next: How to Draw the VAR Coefficients under the Minnesota Prior