VAR Exercise Class
VAR Exercise Class
1 / 59
VAR Exercises
1 Stationarity Testing
3 Granger Causality
2 / 59
Exercise 1: Stationarity Testing - Question
3 / 59
Exercise 1.1: Hint
Hint
Key concepts to remember:
A VAR(1) is stationary if all eigenvalues of A1 lie inside the unit circle
Equivalently: |λi | < 1 for all i
For VAR(1): companion form is the same as the coefficient matrix
To find eigenvalues, solve: det(A1 − λI) = 0
a b
Calculation tip: For a 2 × 2 matrix :
c d
√
(a+d)± (a+d)2 −4(ad−bc)
λ1,2 = 2
4 / 59
Exercise 1.1: Solution (Part 1)
Solution
Step 1: Stationarity condition
For a VAR(1), stationarity requires all eigenvalues of A1 to satisfy |λi | < 1.
Step 2: Compute
eigenvalues
0.6 0.2
Let A1 =
0.1 0.5
Characteristic
det(A1 − λI) = 0
equation:
0.6 − λ 0.2
det =0
0.1 0.5 − λ
(0.6 − λ)(0.5 − λ) − (0.2)(0.1) = 0 λ2 − 1.1λ + 0.28 = 0
5 / 59
Exercise 1.1: Solution (Part 2)
Solution
√ √
Using the quadratic formula: λ1,2 = 1.1± 1.21−1.12
2 = 1.1± 0.09
2 = 1.1±0.3
2
λ1 = 1.1+0.3
2 = 0.7, λ2 = 1.1−0.3
2 = 0.4
6 / 59
Exercise 1.2: Stationarity in R - Question
Tasks:
1 Write R code to check the stationarity of this VAR(2) model
2 Interpret the output: what do you look for?
3 What should you do if the model is non-stationary?
7 / 59
Exercise 1.2: Solution
R code for stationarity testing:
1 # Method 1: Using roots () function
2 stability _ roots <- roots ( var _ model )
3 print ( stability _ roots )
4 # Check condition : all roots should be < 1
5 all ( stability _ roots < 1) # Should return TRUE
6 # Method 2: Compute eigenvalues of companion matrix
7 companion _ matrix <- companionMatrix ( var _ model )
8 eigenvalues <- eigen ( companion _ matrix ) $ values
9 modulus <- Mod ( eigenvalues )
0 print ( modulus )
1 # Check : all moduli should be < 1
2 all ( modulus < 1) # Should return TRUE
3 # Visual check
4 plot ( stability _ roots ,
5 main = " Inverse Roots of AR Characteristic Polynomial "
,
6 xlab = " Real Part " , ylab = " Imaginary Part " )
7 symbols (0 , 0 , circles =1 , add = TRUE , inches = FALSE ) 8 / 59
Exercise 1.2: Interpretation
Solution
What to look for:
1 Roots ¡ 1: If roots(var model) returns values all < 1, the system
is stationary
2 Eigenvalues modulus ¡ 1: Equivalently, check |λi | < 1
3 Visual check: In the plot, all points should lie inside the unit circle
If non-stationary:
Check for unit roots in individual series (ADF test)
Consider differencing the data
Test for cointegration (if variables share common trends)
Estimate a Vector Error Correction Model (VECM)
You estimated VAR models with different lag lengths on a dataset with
K = 3 variables and T = 200 observations. The results are:
Questions:
1 Which lag length does each criterion select?
10 / 59
Exercise 2.1: Hint
Hint
Key principles:
Selection rule: Choose p that minimizes the criterion (most
negative for log-likelihood based criteria)
2K 2 p
AIC: Akaike Information Criterion AIC(p) = ln |Σ̃u (p)| + T
BIC: Bayesian/Schwarz Information Criterion
2
BIC(p) = ln |Σ̃u (p)| + K pTln T
Key difference: BIC penalizes additional parameters more heavily
(especially for large T )
Practical advice:
BIC tends to select more parsimonious models (fewer lags)
AIC can be liberal (may overfit)
11 / 59
Exercise 2.1: Solution
Solution
Step 1: Identify optimal lags for each criterion
Looking at the table (bold values indicate minimum):
AIC: Selects p = 2 (most negative: -7.125)
BIC: Selects p = 3 (-6.873)
HQ: Selects p = 2 (-7.059)
FPE: Selects p = 2 (0.0008)
Solution
Step 3: Which criterion to use?
Reasoning:
1 Three out of four criteria agree on p = 2
2 BIC’s selection of p = 3 is marginal (only 0.016 difference from p = 2)
3 Parsimony principle: prefer simpler model when performance is similar
4 p = 2 is more interpretable (quarterly data → half-year dynamics)
Additional checks:
Perform residual diagnostics (serial correlation test)
If p = 2 residuals show autocorrelation → consider p = 3
Check if results are robust across lag specifications
13 / 59
Exercise 2.2: Lag Selection in R - Question
14 / 59
Exercise 2.2: Solution
1 library ( vars )
2 # Load data
3 data ( Canada )
4 # Step 1: Lag selection ( test p = 1 to 10)
5 lag _ select <- VARselect ( Canada , lag . max =10 ,
6 type = " const " )
7 print ( lag _ select $ selection )
8 # AIC ( n ) HQ ( n ) SC ( n ) FPE ( n )
9 # 3 2 1 3
0 # Step 2: Estimate VAR with BIC - selected lag ( p =1)
1 var _ bic <- VAR ( Canada , p =1 , type = " const " )
2 # Step 3: Serial correlation test
3 serial _ test <- serial . test ( var _ bic , lags . pt =10 ,
4 type = " PT . asymptotic " )
5 print ( serial _ test )
6 # Null : No serial correlation up to lag 10
15 / 59
Exercise 2.2: Interpretation
16 / 59
Exercise 3: Granger Causality - Question
Consider a bivariate VAR(2) with GDP growth (gt ) and interest rate (rt ):
gt = 0.3 + 0.5gt−1 + 0.2gt−2 − 0.1rt−1 − 0.05rt−2 + u1t
rt = 1.2 + 0.1gt−1 + 0.05gt−2 + 0.7rt−1 + 0.15rt−2 + u2t
Questions:
1 Does the interest rate Granger-cause GDP growth?
2 Does GDP growth Granger-cause the interest rate?
3 What are the null hypotheses for each test?
4 How would you test these hypotheses?
17 / 59
Exercise 3.1: Hint
Hint
Granger causality definition:
X Granger-causes Y if past values of X help predict Y beyond what past
values of Y alone can predict.
Testing procedure:
1 Write the equation for the “caused” variable
2 Identify coefficients on lags of the “causing” variable
3 Set up null hypothesis: H0 : all those coefficients = 0
4 Use F-test or Wald test
18 / 59
Exercise 3.1: Solution (Part 1)
Solution
Question 1: Does interest rate Granger-cause GDP growth?
Look at the gt equation:
gt = 0.3 + 0.5gt−1 + 0.2gt−2 − 0.1rt−1 − 0.05rt−2 + u1t
Coefficients on rt−1 and rt−2 : −0.1 and −0.05
These are non-zero
Null hypothesis: H0 : βr ,1 = βr ,2 = 0
R −RSSU )/q
Test statistic: F = (RSS
RSSU /(T −k) ∼ F (q, T − k) where q = 2
(number of restrictions), RSSR = restricted sum of squares, RSSU =
unrestricted sum of squares
19 / 59
Exercise 3.1: Solution (Part 2)
Solution
Question 2: Does GDP growth Granger-cause interest rate?
Look at the rt equation:
rt = 1.2 + 0.1gt−1 + 0.05gt−2 + 0.7rt−1 + 0.15rt−2 + u2t
Coefficients on gt−1 and gt−2 : 0.1 and 0.05
These are non-zero
Null hypothesis: H0 : γg ,1 = γg ,2 = 0
Use same F-test procedure
21 / 59
Exercise 3.2: Solution
1 library ( vars )
2 data ( Canada )
3 # Estimate VAR (2)
4 var _ model <- VAR ( Canada , p =2 , type = " const " )
5 # Test : Does employment GC productivity ?
6 gc _ e _ to _ prod <- causality ( var _ model ,
7 cause = " e " )
8 print ( gc _ e _ to _ prod $ Granger )
9 # Test : Does productivity GC employment ?
0 gc _ prod _ to _ e <- causality ( var _ model ,
1 cause = " prod " )
2 print ( gc _ prod _ to _ e $ Granger )
3 # Interpret
4 # H0 : [ cause ] does NOT Granger - cause [ others ]
5 # If p - value < 0.05: Reject H0
6 # = > [ cause ] DOES Granger - cause [ others ]
22 / 59
Exercise 3.2: Interpretation Guide
How to interpret causality() output:
Example output:
Granger causality H0: e do not Granger-cause prod
F-Test:
statistic = 4.521, p-value = 0.012
Interpretation:
p-value = 0.012 < 0.05
Reject H0
Conclusion: Employment does Granger-cause productivity
Important caveats:
1 Granger causality 6= true causality (it’s predictive association)
4 Requires stationarity
23 / 59
Exercise 4: OLS Estimation - Question
You
estimated
a bivariate
VAR(1)
and obtained:
ŷ1t 0.5 0.7 −0.3 y1,t−1
= +
ŷ2t 1.2 0.2 0.6 y2,t−1
Standard errors: SE (â11 ) = 0.08, SE (â12 ) = 0.12, SE (â21 ) = 0.09,
SE (â22 ) = 0.07
Questions:
1 Test whether a11 is significantly different from zero (α = 0.05)
2 Test whether a12 is significantly different from zero
3 Interpret the coefficient a12 = −0.3
4 What does a21 = 0.2 tell you about the relationship?
24 / 59
Exercise 4.1: Hint
Hint
Hypothesis testing for coefficients:
H0 : aij = 0 (no effect)
H1 : aij 6= 0 (significant effect)
âij
Test statistic: t = SE (âij )
Critical value (5% level, two-tailed): |t| > 1.96 (for large T )
Alternatively: p-value < 0.05
Interpretation guide:
aij measures effect of yj,t−1 on yi,t
Positive coefficient: positive relationship
Negative coefficient: negative relationship
Magnitude indicates strength of effect
25 / 59
Exercise 4.1: Solution (Part 1)
Solution
Question 1: Test a11 = 0.7
t11 = SEâ(â1111 ) = 0.08
0.7
= 8.75
|t| = 8.75 > 1.96 (critical value at 5%)
Reject H0
a11 is highly significant
Interpretation: y1,t−1 has strong predictive power for y1t (strong
persistence)
Questions:
1 Which coefficients are significant at 5%?
2 Interpret the coefficient on rate.l1
3 What is the R-squared interpretation in VAR?
28 / 59
Exercise 4.2: Solution
Solution
Question 1: Significant coefficients
const: p = 0.0004 < 0.05 → Significant ***
gdp.l1: p = 0.0001 < 0.05 → Significant ***
inf.l1: p = 0.0402 < 0.05 → Significant *
rate.l1: p = 0.0284 < 0.05 → Significant *
All coefficients are significant at 5% level! Question 2: Interpret
rate.l1 coefficient
Coefficient: −0.124
Interpretation: A 1 percentage point increase in the interest rate in
period t − 1 leads to a 0.124 percentage point decrease in GDP
growth in period t
Economic meaning: Contractionary monetary policy (higher rates)
→ lower economic growth
Statistical significance confirms this effect is not due to chance 29 / 59
Exercise 4.2: R-squared in VAR
Solution
Question 3: R-squared interpretation
In VAR models, each equation has its own R-squared:
R-squared for equation i: Proportion of variance in yit explained by
all lagged variables in the VAR
Range: 0 to 1
Higher R2 → better fit (but watch for overfitting!)
Typical values:
Growth rates, returns: R2 often 0.05–0.30 (low predictability)
Persistent series (e.g., levels): R2 often 0.80–0.99
High R2 doesn’t mean causality!
VAR-specific note:
Focus more on joint significance (F-tests) than individual R2
System-level diagnostics matter more than equation-level fit
30 / 59
Exercise 5: VMA Representation - Question
Consider a simple
VAR(1):
yt = A1 yt−1 + ut
0.5 0
where A1 = (diagonal for simplicity)
0 0.3
Questions:
P∞
1 Write the VMA representation: yt = i=0 Φi ut−i
2 Compute the first three VMA coefficient matrices: Φ0 , Φ1 , Φ2
3 Show that Φi → 0 as i → ∞ (explain why)
What is the cumulative impulse response: ∞
P
i=0 Φi ?
4
31 / 59
Exercise 5.1: Hint
Hint
VAR to VMA transformation:
Starting from: yt = A1 yt−1 + ut
Recursive substitution:
If stationary: yt = ∞ i
P
i=0 A1 ut−i
32 / 59
Exercise 5.1: Solution (Part 1)
Solution
Step 1: VMA representation P
From recursive substitution: yt = ∞
i=0 Φi ut−i
i
where Φi = A1 for VAR(1)
33 / 59
Exercise 5.1: Solution (Part 2)
Solution
Step 3: Show Φi → 0
0.5i
0
For a diagonal matrix: Ai1 =
0 0.3i
As i → ∞: 0.5i → 0 and 0.3i → 0
Because both eigenvalues (0.5 and 0.3) are inside the unit circle
General result: If VAR is stationary (|λj | < 1), then Φi → 0
exponentially fast
Step
P∞ 4: Cumulative
P∞ i impulse response
−1
Φ
i=0 i = i=0 A1 = (I − A1 ) −1
−1 1 − 0.5 0 2 0
For our example: (I − A1 ) = =
0 1 − 0.3 0 1.43
Interpretation: Long-run multiplier — cumulative effect of a shock on
the level of each variable.
34 / 59
Exercise 5.2: Computing VMA in R - Question
35 / 59
Exercise 5.2: Solution
1 library ( vars )
2 data ( Canada )
3 # Estimate VAR (2)
4 var _ model <- VAR ( Canada , p =2 , type = " const " )
5 # Compute VMA matrices ( Phi coefficients )
6 # Phi ( i ) represents effect of shock at t - i on y at t
7 phi _ matrices <- Phi ( var _ model , nstep =10)
8 # phi _ matrices is a 3 D array :
9 # [ variable , shock , horizon ]
0 # Example : Effect of shock to ’e ’ on ’ prod ’ at horizon5
1 effect _ h5 <- phi _ matrices [ " prod " , " e " , 5]
2 print ( effect _ h5 )
3 # Visualize decay
4 horizons <- 0:10
5 effects <- phi _ matrices [ " e " , " e " , ]
6 plot ( horizons , effects , type = " b " ,
7 main = " VMA Coefficient Decay " ,
8 xlab = " Horizon " , ylab = " Phi _ i [1 ,1] " )
9 abline ( h =0 , lty =2 , col = " red " )
36 / 59
Exercise 5.2: Interpretation
Solution
Interpreting VMA coefficients:
The Φi matrices tell us:
[Φi ]jk : Effect of a 1-unit shock to variable k at time t on variable j at
time t + i
Φ0 = I: Contemporaneous impact (shock affects itself immediately)
Φ1 , Φ2 , . . .: Dynamic propagation of shocks over time
What to look for in the plot:
1 Initial response: Φ0 = 1 (by construction)
2 Persistence: How fast do coefficients decay?
Fast decay → shocks dissipate quickly
Slow decay → long-lasting effects
3 Sign patterns:
Always positive → no overshooting
Sign changes → oscillatory response
4 Convergence to zero: Confirms stationarity 37 / 59
Exercise 6: Impulse Response Functions - Question
Questions:
1 Which statements are TRUE? Which are FALSE?
2 For each false statement, explain why and correct it
38 / 59
Exercise 6.1: Solution
Solution
Evaluating each statement:
40 / 59
Exercise 6.2: Hint
Hint
Cholesky decomposition procedure:
σ12 σ12
For Σu =
σ σ22
12
p 0
Find P = 11 such that Σu = PP0
p21 p22
Steps:
q
1 p11 = σ12
σ12
2 p21 = p11
q
3 p22 = σ22 − p21
2
41 / 59
Exercise 6.2: Solution (Part 1)
Solution
Question 1: Interpretation of σ12 = 0.6
Correlation: ρ = √ 0.6 = 0.6
= 0.671
1.0×0.8 0.894
High positive correlation between reduced-form shocks
Shocks tend to move together
Problem: Can’t isolate effect of “just u1 ” or “just u2 ”
42 / 59
Exercise 6.2: Solution (Part 2)
Solution
Question 3: How Cholesky helps
Cholesky decomposes Σu = PP0 with P lower triangular
Define structural shocks: ut = Pεt
By construction: E [εt ε0t ] = I (orthogonal!)
Now can interpret IRFs as responses to εjt (pure shocks)
1.0 0.6
Question 4: Compute Cholesky factor Given: Σu =
0.6 0.8
√
p11 = 1.0 = 1.0
0.6
p21 = = 0.6
1.0
p √ √
p22 = 0.8 − 0.62 = 0.8 − 0.36 = 0.44 = 0.663
1.0 0
P=
0.6 0.663
43 / 59
Exercise 6.2: Verification
Solution
Verify: PP0= Σu
1.0 0 1.0 0.6
0.6 0.663 0 0.663
1.0 × 1.0 + 0 × 0 1.0 × 0.6 + 0 × 0.663
=
0.6 × 1.0 + 0.663 × 0 0.6 × 0.6 + 0.663 × 0.663
1.0 0.6 1.0 0.6
= = X
0.6 0.36 + 0.44 0.6 0.8
Interpretation of P:
Row 1: u1t = 1.0 · ε1t → y1 responds only to first structural shock
Row 2: u2t = 0.6 · ε1t + 0.663 · ε2t → y2 responds to both shocks
Recursive structure: first variable causally prior
44 / 59
Exercise 6.3: Computing IRFs in R - Question
Tasks:
1 Estimate a VAR(2) on the Canada dataset
2 Compute orthogonalized IRFs (Cholesky)
3 Plot the response of prod (productivity) to a shock in e
(employment)
4 Plot IRFs for 20 periods ahead
5 Add confidence bands (bootstrap)
6 Interpret the results
45 / 59
Exercise 6.3: Solution (Part 1)
1 library ( vars )
2 data ( Canada )
3
4 # Step 1: Estimate VAR (2)
5 var _ model <- VAR ( Canada , p =2 , type = " const " )
6
7 # Step 2: Compute orthogonalized IRFs
8 # ortho = TRUE uses Cholesky decomposition
9 # n . ahead =20: 20 periods ahead
0 # boot = TRUE : bootstrap confidence intervals
1 # runs =500: number of bootstrap replications
2 irf _ results <- irf ( var _ model ,
3 impulse = " e " ,
4 response = " prod " ,
5 n . ahead =20 ,
6 ortho = TRUE ,
7 boot = TRUE ,
8 runs =500 ,
9 ci =0.95)
46 / 59
Exercise 6.3: Solution (Part 2)
47 / 59
Exercise 6.3: Solution (Part 3)
1 # Custom plot
2 horizons <- 0:20
3 point _ est <- irf _ results $ irf $ e
4 lower <- irf _ results $ Lower $ e
5 upper <- irf _ results $ Upper $ e
6 plot ( horizons , point _ est , type = " l " ,
lwd =2 ,
7 ylim = range ( c ( lower , upper ) ) ,
8 main = " IRF : Employment -> Productivity "
,
9 xlab = " Horizon " , ylab = " Response " )
0 polygon ( c ( horizons , rev ( horizons ) ) ,
1 c ( lower , rev ( upper ) ) ,
2 col = rgb (0 ,0 ,1 ,0.2) , border = NA )
3 abline ( h =0 , lty =2 , col = " red " )
48 / 59
Exercise 6.3: Interpretation Guide
Solution
How to interpret IRF plots: Key features to identify:
1 Impact effect (horizon 0):
Contemporaneous response
Cholesky: impact depends on ordering
2 Peak response:
When is the maximum effect?
How large is it?
3 Persistence:
How long until IRF returns to zero?
Half-life: horizon when response drops to 50% of peak
4 Shape:
Monotonic decay vs hump-shaped
Overshooting (goes negative after being positive)
5 Statistical significance:
Does confidence band include zero?
If yes at some horizon: effect not significant 49 / 59
Exercise 6.3: Economic Interpretation Example
Solution
Example interpretation: Suppose the IRF shows:
Impact: 0.02 (horizon 0)
Peak: 0.08 at horizon 3
Returns to zero: around horizon 12
Confidence bands: exclude zero for horizons 0–8
Economic story: “A positive 1-standard-deviation shock to employment
leads to:
An immediate increase in productivity of 0.02%
The peak effect of 0.08% occurs after 3 quarters
The effect gradually dissipates, becoming statistically insignificant
after 2 years
This pattern suggests that increased employment boosts productivity
through learning-by-doing and scale effects, but the effect is
temporary” 50 / 59
Bonus Exercise: SVAR Identification
Questions:
1 Under Cholesky ordering (y , π, r ), what does the identification
assume about monetary policy?
2 Is this assumption realistic? Why or why not?
3 Propose an alternative identification strategy
4 What external instrument could you use for monetary policy shocks?
51 / 59
Bonus Exercise: Solution (Part 1)
Solution
Question 1: Cholesky (y , π, r ) assumption Recursive structure:
Implications:
Output shocks affect inflation and interest rate contemporaneously
Inflation shocks affect interest rate contemporaneously (but not
output)
Interest rate shocks affect nothing contemporaneously
Economic interpretation:
Central bank observes yt and πt and sets rt accordingly (within
period)
Monetary policy has no contemporaneous effect on output/inflation
52 / 59
Bonus Exercise: Solution (Part 2)
Solution
Question 2: Is this realistic?
Potential problems:
Information lag: Central bank may not observe yt , πt in real time
(data released with delay)
Decision lag: Monetary policy committee meets periodically (not
continuously)
Financial markets: Interest rate changes affect asset prices,
exchange rates immediately
Expectations: Forward-looking agents react to policy announcements
53 / 59
Bonus Exercise: Solution (Part 3)
Solution
Question 3: Alternative identification
Option 1: Reverse ordering (r , π, y )
Assumes policy affects inflation and output contemporaneously
But then: output can’t affect policy within period (unrealistic!)
Option 2: Sign restrictions
Contractionary policy shock: r ↑, y ↓, π ↓ (at least for some horizons)
Doesn’t impose exact timing of effects
54 / 59
Bonus Exercise: Solution (Part 4)
Solution
Question 4: External instruments (Proxy SVAR)
Idea: Use an instrument Zt correlated with true monetary policy shock
but uncorrelated with other shocks
Candidate instruments:
1 High-frequency identification (Gertler & Karadi, 2015):
1 Stationarity is crucial
Always check before proceeding
Non-stationary VARs can give spurious results
2 Model selection matters
Use multiple criteria
Check residual diagnostics
3 Granger causality 6= true causality
It’s about predictive power, not mechanisms
4 Identification is key for IRFs
Reduced-form shocks are correlated
Need structure to isolate effects
Choice of identification affects conclusions
5 Always provide economic interpretation
Statistical results must connect to economic theory
IRFs tell stories about dynamic adjustment
57 / 59
Practice Recommendations
To master VAR analysis:
1 Replicate classic papers:
Textbooks:
Lütkepohl (2005): New Introduction to Multiple Time Series Analysis
Hamilton (1994): Time Series Analysis
Kilian & Lütkepohl (2017): Structural Vector Autoregressive Analysis
Software:
R: vars, svars, BVAR
Python: [Link]
MATLAB: built-in VAR functions, Uhlig’s toolkit
Datasets:
vars::Canada (practice dataset)
FRED-QD (quarterly macroeconomic database)
Stock & Watson macroeconomic data
59 / 59