bh2019-oil-svar-python: Baumeister & Hamilton (2019) Oil SVAR in Python
Overview
bh2019-oil-svar-python is an independent, open-source Python translation of the MATLAB replication code for:
Baumeister, Christiane, and James D. Hamilton. 2019. “Structural Interpretation of Vector Autoregressions with Incomplete Identification: Revisiting the Role of Oil Supply and Demand Shocks.” American Economic Review 109(5): 1873-1910.
The official MATLAB package is on the AEA Data and Code Repository (openICPSR project 113108). This repository re-implements it in NumPy and SciPy, with a Numba-accelerated historical decomposition, keeps a 1:1 mapping to the original .m files, and validates the output against the published results.
- GitHub: github.com/nkoutoun/bh2019-oil-svar-python
- License: MIT for the translation code. The redistributed input data remain subject to their original terms.
Installation
conda env create -f environment.yml
conda activate bh19
Or, with pip:
pip install -e .[dev]
What Is Replicated
One command-line script per paper object, each mapped to the original MATLAB source:
| Script | Paper object |
|---|---|
01_baseline_mcmc.py | Posterior sampler, baseline 4-variable oil-market SVAR |
02_figure7_prior_posterior.py | Figure 7; Table 3, panels A and B |
03_figure8_irf_table3.py | Figure 8; Table 3, panels C to E; Table 2 posterior column |
04_figure9_10_hd_table4.py | Figures 9 and 10; Table 4, baseline row |
05_table2_prior_probs.py | Table 2, prior column |
06_figure6_cross_country.py | Figure 6, cross-country gasoline demand |
07_kaer_figures1_2.py | Figures 1 and 2, Kilian (2009) revisited |
08_km12_figures3_4.py | Figures 3 and 4, Kilian and Murphy (2012) revisited |
Every MCMC script takes --draws, --burn, --seed, --outdir, and --quick, so the whole pipeline can be smoke-tested in about a minute before committing to a paper-scale run of 2,000,000 draws.
Validation
At paper scale the Python posterior reproduces Table 3, column 1, of the original paper on all five checks:
| Magnitude (Table 3, col. 1) | Published | Obtained |
|---|---|---|
| Panel A, oil supply elasticity | 0.15 (0.09, 0.22) | 0.155 (0.115, 0.211) |
| Panel B, oil demand elasticity | -0.35 (-0.51, -0.24) | -0.335 (-0.429, -0.255) |
| Panel C, supply shock to activity, 12m | -0.50 (-0.91, -0.17) | -0.479 (-0.827, -0.164) |
| Panel D, consumption-demand shock to activity, 12m | 0.13 (-0.14, 0.44) | 0.151 (-0.118, 0.458) |
| Panel E, inventory-demand shock to activity, 12m | -0.36 (-0.81, 0.07) | -0.328 (-0.750, 0.080) |
Table 2 sign probabilities and Table 4 episode contributions match as well. The Python chain samples the identical posterior with a different random-number generator than MATLAB, so agreement holds up to Monte Carlo error and publication rounding, not draw-by-draw identity. Full details and tolerances are in VALIDATION.md.
Relation to My Research
Identification in oil markets is close to my own work on how global oil supply shocks transmit across U.S. state economies, in Shale Production and the Transmission of Oil Supply Shocks. Porting the Baumeister and Hamilton framework to Python puts a Bayesian SVAR with informative priors on elasticities in the hands of researchers and students who do not work in MATLAB, and the docstrings name the exact MATLAB routine each function translates so the two codebases can be read side by side.
Attribution
This is an independent translation. It was not written, reviewed, or endorsed by Christiane Baumeister or James D. Hamilton, and any translation errors are mine alone. Please cite the original paper and consult the official replication package for the authoritative implementation.