{"schemaVersion":2,"courseId":"var","module":{"id":"var-from-ar1-to-var","title":"1 · From AR(1) to VAR (joint dynamics)","summary":"How stacking several AR equations into one system lets each variable depend on the lagged values of all the others.","stages":[{"type":"read","title":"One series at a time: AR(1)","html":"<h2>Recap: the AR(1) model</h2><p>A single time series <em>y</em> follows an <strong>autoregression of order 1</strong> when today's value is a constant plus a fraction of yesterday's value plus noise:</p><p class=\"katexish\">yₜ = c + φ·yₜ₋₁ + εₜ</p><p>The coefficient <code>φ</code> is the <em>persistence</em>: if φ = 0.8, a shock today still leaves 0.8 of itself tomorrow, 0.64 the day after, and so on, decaying geometrically. The series is <strong>stationary</strong> (it doesn't wander off to infinity) precisely when <code>|φ| &lt; 1</code>.</p><h3>The problem AR(1) ignores</h3><p>Real economic variables move <em>together</em>. Interest rates respond to inflation; inflation responds to past output; output responds to past rates. An AR(1) on inflation alone pretends inflation only listens to its own past — it is deaf to everything else. We need a model where each variable can depend on the recent past of <em>every</em> variable.</p><div class=\"callout\"><b>Key idea.</b> A VAR is just several AR equations estimated jointly, where the right-hand side of <em>every</em> equation contains the lags of <em>every</em> variable in the system.</div>","id":"var-from-ar1-to-var-01","skillIds":["var.var-stationarity"],"estimatedMinutes":6,"difficulty":"advanced","prerequisiteStageIds":[]},{"type":"read","title":"Stacking equations into a VAR(1)","html":"<h2>The VAR(1) system</h2><p>Take two series, <code>y1</code> and <code>y2</code>. A VAR(1) writes one equation for each:</p><p class=\"katexish\">y1ₜ = c₁ + a₁₁·y1ₜ₋₁ + a₁₂·y2ₜ₋₁ + ε1ₜ</p><p class=\"katexish\">y2ₜ = c₂ + a₂₁·y1ₜ₋₁ + a₂₂·y2ₜ₋₁ + ε2ₜ</p><p>Collect the variables into a vector <code>Yₜ = (y1ₜ, y2ₜ)′</code> and the coefficients into a 2×2 matrix <strong>A</strong>. The whole system becomes one compact line:</p><p class=\"katexish\">Yₜ = c + A·Yₜ₋₁ + εₜ</p><p>The matrix entries have crisp meanings:</p><ul><li><strong>Diagonal</strong> <code>a₁₁, a₂₂</code> — each variable's own <em>persistence</em> (like φ in AR(1)).</li><li><strong>Off-diagonal</strong> <code>a₁₂, a₂₁</code> — the <em>spillover</em> from one variable's past into the other's present. These are exactly what a single-equation AR throws away.</li></ul><h3>When is a VAR stable?</h3><p>The univariate rule <code>|φ| &lt; 1</code> generalizes: a VAR(1) is stationary when every <strong>eigenvalue of A</strong> has modulus less than 1. The eigenvalues are the multivariate analogue of φ — they govern how shocks decay through the coupled system.</p><div class=\"callout\"><b>Key idea.</b> Diagonal = memory of yourself; off-diagonal = how you push the other variable around. Stability is governed by the eigenvalues of <strong>A</strong>, not the individual entries.</div>","id":"var-from-ar1-to-var-02","skillIds":["var.var-lag-selection"],"estimatedMinutes":6,"difficulty":"advanced","prerequisiteStageIds":["var-from-ar1-to-var-01"]},{"type":"code","title":"Simulate and recover a VAR(1)","note":"We build data from a known 2×2 matrix A, then let statsmodels recover it. Compare the printed coefficients to the true A.","code":"import numpy as np, pandas as pd\nfrom statsmodels.tsa.api import VAR\nrng = np.random.default_rng(0)\n\n# True coefficient matrix: strong own-persistence, modest spillovers\nA = np.array([[0.6, 0.2],\n              [0.1, 0.5]])\nprint('eigenvalues |.| =', np.round(np.abs(np.linalg.eigvals(A)), 3), '(all < 1 => stable)')\n\nn = 1000\nY = np.zeros((n, 2))\nfor t in range(1, n):\n    Y[t] = A @ Y[t-1] + rng.normal(0, 1, 2)\n\ndf = pd.DataFrame(Y, columns=['y1', 'y2'])\nres = VAR(df).fit(maxlags=1)\n\nprint('\\nTrue A:\\n', A)\nprint('\\nEstimated A (res.coefs[0]):\\n', np.round(res.coefs[0], 3))\nprint('\\nFull readable summary:')\nprint(res.summary())","id":"var-from-ar1-to-var-03","skillIds":["var.var-stationarity"],"estimatedMinutes":10,"difficulty":"advanced","prerequisiteStageIds":["var-from-ar1-to-var-02"]},{"type":"interactive","title":"Watch the two series co-move","note":"Push up the spillover a₂₁ and see how a wiggle in y1 starts dragging y2 along. Keep diagonals < 1 for stability.","params":[{"name":"a11","label":"y1 persistence a₁₁","min":0,"max":0.95,"step":0.05,"value":0.6},{"name":"a22","label":"y2 persistence a₂₂","min":0,"max":0.95,"step":0.05,"value":0.5},{"name":"a21","label":"spillover y1→y2 (a₂₁)","min":-0.6,"max":0.6,"step":0.05,"value":0.1}],"template":"import numpy as np, matplotlib.pyplot as plt\nrng = np.random.default_rng(0)\nA = np.array([[{{a11}}, 0.2],\n              [{{a21}}, {{a22}}]])\nev = np.max(np.abs(np.linalg.eigvals(A)))\nn = 300\nY = np.zeros((n, 2))\nfor t in range(1, n):\n    Y[t] = A @ Y[t-1] + rng.normal(0, 1, 2)\nplt.figure(figsize=(6,3.7))\nplt.plot(Y[:,0], color='#da9100', lw=1.3, label='y1')\nplt.plot(Y[:,1], color='#6f6b57', lw=1.3, label='y2')\nplt.legend(loc='upper right', fontsize=8)\nstab = 'STABLE' if ev < 1 else 'EXPLOSIVE'\nplt.title(f'max|eigenvalue| = {ev:.2f}  ->  {stab}')","id":"var-from-ar1-to-var-04","skillIds":["var.var-lag-selection"],"estimatedMinutes":8,"difficulty":"advanced","prerequisiteStageIds":["var-from-ar1-to-var-03"]},{"type":"quiz","title":"Check: what makes it a VAR?","prompt":"In the VAR(1) matrix A, what does a non-zero off-diagonal entry a₁₂ represent?","choices":["The persistence of y1 (how much of its own past it keeps)","The effect of last period's y2 on this period's y1","The contemporaneous correlation of the two error terms","The long-run mean of y1"],"answer":1,"hint":"Read off the first equation: y1ₜ = c₁ + a₁₁·y1ₜ₋₁ + a₁₂·y2ₜ₋₁ + ε1ₜ.","explain":"a₁₂ multiplies the lagged value of the OTHER variable (y2ₜ₋₁) in the equation for y1, so it is the cross-variable spillover; own-persistence lives on the diagonal.","id":"var-from-ar1-to-var-05","skillIds":["var.var-stationarity"],"estimatedMinutes":5,"difficulty":"advanced","prerequisiteStageIds":["var-from-ar1-to-var-04"],"variantId":"var-from-ar1-to-var-05-core"},{"type":"quiz","title":"Check: stability","prompt":"A VAR(1) is stationary (stable) when…","choices":["every entry of A is less than 1 in absolute value","the determinant of A is positive","every eigenvalue of A has modulus less than 1","the off-diagonal entries are zero"],"answer":2,"hint":"It is the multivariate version of the AR(1) rule |φ| < 1.","explain":"Stationarity depends on the eigenvalues of A, not the raw entries — a matrix with large entries can still be stable, and one with small entries can be explosive.","id":"var-from-ar1-to-var-06","skillIds":["var.var-lag-selection"],"estimatedMinutes":5,"difficulty":"advanced","prerequisiteStageIds":["var-from-ar1-to-var-05"],"variantId":"var-from-ar1-to-var-06-core"},{"type":"numeric","title":"Does the spillover die out?","prompt":"A shock δ = 1 hits y1 at time 0 in a stable VAR(1) with coefficient matrix A. The horizon-2 response of the system is A²·δ. If A = [[0.5, 0.4],[0.0, 0.5]], enter the horizon-2 response of <b>y1</b> (first component of A²·δ, where δ = (1, 0)′), to two decimals.","answer":0.25,"tol":0.02,"hint":"δ = (1,0)′, so you only need the (1,1) entry of A². For this upper-triangular A that is just 0.5².","explain":"<b>The 'spillover never fades' trap.</b> The horizon-h response is Aʰ·δ; here A²·δ has first component (0.5² + 0.4·0) = 0.25, down from 0.5 at horizon 1 and heading to 0. Because A is stable (both eigenvalues 0.5, modulus < 1), shocks are <em>transitory</em> and decay geometrically. <em>Boundary:</em> if any eigenvalue of A had modulus ≥ 1 the series would be non-stationary and the response would not die out — stability, not the size of the raw entries, is what guarantees decay.","points":20,"id":"var-from-ar1-to-var-07","skillIds":["var.var-stationarity"],"estimatedMinutes":5,"difficulty":"advanced","prerequisiteStageIds":["var-from-ar1-to-var-06"],"variantId":"var-from-ar1-to-var-07-core"}]}}
