Markov-Switching VAR

Python · R · Part 11 of the VAR arc — data-discovered regimes

Overview

Part 11 of the VAR arc: discrete regimes, discovered by the data. Part 5's time-varying-parameter VAR let the economy's dynamics drift smoothly. But some changes are not gradual — they are switches: the economy flips between a calm state and a turbulent one, between expansion and recession. The Markov-switching VAR (Hamilton 1989; Krolzig 1997) models exactly that — the VAR's parameters jump between a small number of regimes governed by a latent Markov chain the data infer. Where Part 10 imposed the Great-Moderation break to identify shocks, the MS-VAR is handed no dates at all: it discovers the regimes, and rediscovers 1984 on its own. Built from scratch with a Gibbs sampler whose centrepiece is the forward-filter–backward-sample of the hidden regime path.

yt=cSt+B1yt1++Bpytp+εt,εtN(0,ΣSt),Pjk=Pr(St=kSt1=j)y_t = c_{S_t} + B_1 y_{t-1} + \dots + B_p y_{t-p} + \varepsilon_t, \quad \varepsilon_t\sim\mathcal N(0,\Sigma_{S_t}), \qquad P_{jk}=\Pr(S_t=k\mid S_{t-1}=j)

An MSIH-VAR and its forward-filter–backward-sample Gibbs

An MSIH-VAR — switching intercept and covariance, constant autoregressive dynamics — where St{1,,K}S_t\in\{1,\dots,K\} is a latent Markov chain with transition matrix PP whose diagonal governs how persistent the regimes are. The from-scratch Gibbs sampler cycles three blocks: (1) the regime path S1:TS_{1:T} by forward-filter–backward-sample — run the Hamilton filter forward (predict Pr(Sty1:t1)\Pr(S_t\mid y_{1:t-1}) through PP, update with each regime's VAR likelihood), then sample backwards STS_T then StSt+1S_t\mid S_{t+1} down to t=1t=1 — the discrete-state analogue of the Carter–Kohn smoother; (2) the parameters — given SS, each regime's intercept and covariance are conjugate Normal / inverse-Wishart draws and the constant lag matrix a GLS draw across regimes; (3) the transition matrix PP — each row a Dirichlet draw from the counted transitions. Label-switching is fixed by ordering regimes by volatility (calm vs turbulent), on the same monetary system as Parts 4/10 (GDP growth, inflation, funds rate), K=2K=2, p=2p=2.

Results

The Great Moderation, rediscovered without a date. The turbulent (high-volatility) regime is active 40% of the time before 1984 but only 3% after — the model draws the Great-Moderation line on its own, precisely where Part 10 had to assume it, and the calm regime once entered essentially never leaves (bar 2008). Turbulent = volatile and recessionary: the turbulent regime carries 2–4× the shock volatility of the calm one (GDP-growth std 5.1 vs 2.4) and its smoothed probability spikes in the NBER recessions (mean 0.57 in recessions vs 0.13 in expansions) and across the high-inflation 1970s — the postwar economy's "stress" state. Persistence differs sharply: the transition matrix implies the calm regime lasts ~26 quarters on average and the turbulent one ~6 — long stable stretches punctuated by shorter bouts of turbulence. Switches, not drift: where Part 5 asked how much has the world drifted?, the MS-VAR answers which regime are we in right now?, delivering a probabilistic, dated chronology of postwar macro that a smooth-drift model cannot — and acting as an endogenous break detector that locates the Great Moderation with no prior information. Together, Parts 5, 10 and 11 span the ways a VAR can be non-constant: smooth drift, imposed regimes, and data-discovered regimes. Cross-checked in R (MSwM).

Notebooks

Downloads

References