In order to estimate the VAR model we first need to obtain quarterly time series for real GDP FRED/GDPC1, GDP deflator FRED/GDPDEF and quarterly closing value of S&P 500 Index YAHOO/INDEX_GSPC.
We have to construct two time series:
library(Quandl)
library(vars)
library(stargazer)
Estimation of a bivariate reduced form VAR for \(y_t = (y_{1,t}, y_{2,t})\prime\) for the period 1951, Q1-2014, Q4.
# obtaining data on real GDP, GDP deflator, S&P500
rGDP <- Quandl("FRED/GDPC1", type="zoo")
dGDP <- Quandl("FRED/GDPDEF", type="zoo")
sp500 <- Quandl("YAHOO/INDEX_GSPC", collapse="quarterly", type="zoo")
# constructing log difference of GDP, GDP deflator, S&P500
y1 <- diff(log(rGDP))
dldGDP <- diff(log(dGDP))
dlsp500 <- diff(log(sp500$Close))
y2 <- dlsp500-dldGDP
# now we can plot the graphs both graphs of the time-series
par(mfrow=c(1,2))
plot(y1, xlab="", ylab="", main="y1")
plot(y2, xlab="", ylab="", main="y2")
Using the information so far derived, we can choose a VAR model based on information criterion.
y.Q <- cbind(y1, y2)
y.Q <- window(y.Q, start="1951 Q1", end="2014 Q4")
VARselect(y.Q, lag.max=8, type="const")
## $selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 2 2 1 2
##
## $criteria
## 1 2 3 4
## AIC(n) -1.465126e+01 -1.470486e+01 -1.469229e+01 -1.466603e+01
## HQ(n) -1.461704e+01 -1.464783e+01 -1.461245e+01 -1.456337e+01
## SC(n) -1.456626e+01 -1.456319e+01 -1.449395e+01 -1.441102e+01
## FPE(n) 4.335513e-07 4.109277e-07 4.161332e-07 4.272205e-07
## 5 6 7 8
## AIC(n) -1.464883e+01 -1.462725e+01 -1.461845e+01 -1.459013e+01
## HQ(n) -1.452337e+01 -1.447897e+01 -1.444736e+01 -1.439622e+01
## SC(n) -1.433716e+01 -1.425891e+01 -1.419344e+01 -1.410845e+01
## FPE(n) 4.346529e-07 4.441705e-07 4.481426e-07 4.610779e-07
Based on AIC it is recommended to to choose 2 lags.
var2 <- VAR(y.Q, p=2, type="const")
var2
##
## VAR Estimation Results:
## =======================
##
## Estimated coefficients for equation y1:
## =======================================
## Call:
## y1 = y1.l1 + y2.l1 + y1.l2 + y2.l2 + const
##
## y1.l1 y2.l1 y1.l2 y2.l2 const
## 0.245040169 0.023096767 0.079349334 0.026300396 0.004627771
##
##
## Estimated coefficients for equation y2:
## =======================================
## Call:
## y2 = y1.l1 + y2.l1 + y1.l2 + y2.l2 + const
##
## y1.l1 y2.l1 y1.l2 y2.l2 const
## 0.25605423 0.10650115 -0.81935297 -0.04057338 0.01383567
summary(var2)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: y1, y2
## Deterministic variables: const
## Sample size: 254
## Log Likelihood: 1154.493
## Roots of the characteristic polynomial:
## 0.4454 0.4454 0.304 0.304
## Call:
## VAR(y = y.Q, p = 2, type = "const")
##
##
## Estimation results for equation y1:
## ===================================
## y1 = y1.l1 + y2.l1 + y1.l2 + y2.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## y1.l1 0.2450402 0.0614771 3.986 8.84e-05 ***
## y2.l1 0.0230968 0.0064046 3.606 0.000375 ***
## y1.l2 0.0793493 0.0595434 1.333 0.183872
## y2.l2 0.0263004 0.0065720 4.002 8.29e-05 ***
## const 0.0046278 0.0007233 6.398 7.75e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.008038 on 249 degrees of freedom
## Multiple R-Squared: 0.2309, Adjusted R-squared: 0.2185
## F-statistic: 18.68 on 4 and 249 DF, p-value: 1.91e-13
##
##
## Estimation results for equation y2:
## ===================================
## y2 = y1.l1 + y2.l1 + y1.l2 + y2.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## y1.l1 0.256054 0.609111 0.420 0.6746
## y2.l1 0.106501 0.063457 1.678 0.0945 .
## y1.l2 -0.819353 0.589953 -1.389 0.1661
## y2.l2 -0.040573 0.065115 -0.623 0.5338
## const 0.013836 0.007167 1.931 0.0547 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.07964 on 249 degrees of freedom
## Multiple R-Squared: 0.02087, Adjusted R-squared: 0.00514
## F-statistic: 1.327 on 4 and 249 DF, p-value: 0.2605
##
##
##
## Covariance matrix of residuals:
## y1 y2
## y1 6.46e-05 0.000087
## y2 8.70e-05 0.006342
##
## Correlation matrix of residuals:
## y1 y2
## y1 1.0000 0.1359
## y2 0.1359 1.0000
From the correlation matrix of residuals we can see that the coefficient is 0.1359.
Now we should run the Granger causality tests for both variables.
causality(var2,cause="y1")
## $Granger
##
## Granger causality H0: y1 do not Granger-cause y2
##
## data: VAR object var2
## F-Test = 0.96654, df1 = 2, df2 = 498, p-value = 0.3811
##
##
## $Instant
##
## H0: No instantaneous causality between: y1 and y2
##
## data: VAR object var2
## Chi-squared = 4.6072, df = 1, p-value = 0.03184
causality(var2,cause="y2")
## $Granger
##
## Granger causality H0: y2 do not Granger-cause y1
##
## data: VAR object var2
## F-Test = 15.762, df1 = 2, df2 = 498, p-value = 2.305e-07
##
##
## $Instant
##
## H0: No instantaneous causality between: y2 and y1
##
## data: VAR object var2
## Chi-squared = 4.6072, df = 1, p-value = 0.03184
Observing the results of the tests and p-values we can see that we fail to reject (H0: No instantaneous causality between: y1 and y2) and we reject (H0: y2 do not Granger-cause y1).
Now we have to estimate two restricted VAR models in first remove lags based on the Granger causality test from (b), in the second one remove all variables which have t-statistics lower than 2.
Based on the results of (b) we remove lags from the first model.
B0 <- matrix(1, nrow=2, ncol=5)
B0[2, c(1,3)] <- 0
B0
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 1 1 1 1
## [2,] 0 1 0 1 1
var.r <- restrict(var2, method="manual", resmat=B0)
summary(var2)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: y1, y2
## Deterministic variables: const
## Sample size: 254
## Log Likelihood: 1154.493
## Roots of the characteristic polynomial:
## 0.4454 0.4454 0.304 0.304
## Call:
## VAR(y = y.Q, p = 2, type = "const")
##
##
## Estimation results for equation y1:
## ===================================
## y1 = y1.l1 + y2.l1 + y1.l2 + y2.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## y1.l1 0.2450402 0.0614771 3.986 8.84e-05 ***
## y2.l1 0.0230968 0.0064046 3.606 0.000375 ***
## y1.l2 0.0793493 0.0595434 1.333 0.183872
## y2.l2 0.0263004 0.0065720 4.002 8.29e-05 ***
## const 0.0046278 0.0007233 6.398 7.75e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.008038 on 249 degrees of freedom
## Multiple R-Squared: 0.2309, Adjusted R-squared: 0.2185
## F-statistic: 18.68 on 4 and 249 DF, p-value: 1.91e-13
##
##
## Estimation results for equation y2:
## ===================================
## y2 = y1.l1 + y2.l1 + y1.l2 + y2.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## y1.l1 0.256054 0.609111 0.420 0.6746
## y2.l1 0.106501 0.063457 1.678 0.0945 .
## y1.l2 -0.819353 0.589953 -1.389 0.1661
## y2.l2 -0.040573 0.065115 -0.623 0.5338
## const 0.013836 0.007167 1.931 0.0547 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.07964 on 249 degrees of freedom
## Multiple R-Squared: 0.02087, Adjusted R-squared: 0.00514
## F-statistic: 1.327 on 4 and 249 DF, p-value: 0.2605
##
##
##
## Covariance matrix of residuals:
## y1 y2
## y1 6.46e-05 0.000087
## y2 8.70e-05 0.006342
##
## Correlation matrix of residuals:
## y1 y2
## y1 1.0000 0.1359
## y2 0.1359 1.0000
var.r.s <- restrict(var2, method="ser", thresh=2.0)
summary(var.r.s)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: y1, y2
## Deterministic variables: const
## Sample size: 254
## Log Likelihood: 1150.599
## Roots of the characteristic polynomial:
## 0.2734 0 0 0
## Call:
## VAR(y = y.Q, p = 2, type = "const")
##
##
## Estimation results for equation y1:
## ===================================
## y1 = y1.l1 + y2.l1 + y2.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## y1.l1 0.2734178 0.0577607 4.734 3.70e-06 ***
## y2.l1 0.0226323 0.0064051 3.533 0.000488 ***
## y2.l2 0.0266285 0.0065775 4.048 6.88e-05 ***
## const 0.0050198 0.0006618 7.585 6.55e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.00805 on 250 degrees of freedom
## Multiple R-Squared: 0.5446, Adjusted R-squared: 0.5374
## F-statistic: 74.76 on 4 and 250 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation y2:
## ===================================
## y2 = const
##
## Estimate Std. Error t value Pr(>|t|)
## const 0.01017 0.00501 2.03 0.0434 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.07984 on 253 degrees of freedom
## Multiple R-Squared: 0.01602, Adjusted R-squared: 0.01213
## F-statistic: 4.119 on 1 and 253 DF, p-value: 0.04344
##
##
##
## Covariance matrix of residuals:
## y1 y2
## y1 6.506e-05 8.224e-05
## y2 8.224e-05 6.477e-03
##
## Correlation matrix of residuals:
## y1 y2
## y1 1.0000 0.1267
## y2 0.1267 1.0000
m1 <- var2$varresult
m2 <- var.r$varresult
m3 <- var.r.s$varresult
stargazer(m1$y1, m1$y2, m2$y1, m2$y2, m3$y1, m3$y2,
type="text", column.labels=rep(colnames(y.Q), 3),
dep.var.labels.include=TRUE)
##
## ==========================================================================================================================================================
## Dependent variable:
## --------------------------------------------------------------------------------------------------------------------------------------
## y
## y1 y2 y1 y2 y1 y2
## (1) (2) (3) (4) (5) (6)
## ----------------------------------------------------------------------------------------------------------------------------------------------------------
## y1.l1 0.245*** 0.256 0.245*** 0.273***
## (0.061) (0.609) (0.061) (0.058)
##
## y2.l1 0.023*** 0.107* 0.023*** 0.111* 0.023***
## (0.006) (0.063) (0.006) (0.063) (0.006)
##
## y1.l2 0.079 -0.819 0.079
## (0.060) (0.590) (0.060)
##
## y2.l2 0.026*** -0.041 0.026*** -0.045 0.027***
## (0.007) (0.065) (0.007) (0.063) (0.007)
##
## const 0.005*** 0.014* 0.005*** 0.010* 0.005*** 0.010**
## (0.001) (0.007) (0.001) (0.005) (0.001) (0.005)
##
## ----------------------------------------------------------------------------------------------------------------------------------------------------------
## Observations 254 254 254 254 254 254
## R2 0.231 0.021 0.548 0.029 0.545 0.016
## Adjusted R2 0.219 0.005 0.539 0.017 0.537 0.012
## Residual Std. Error 0.008 (df = 249) 0.080 (df = 249) 0.008 (df = 249) 0.080 (df = 251) 0.008 (df = 250) 0.080 (df = 253)
## F Statistic 18.685*** (df = 4; 249) 1.327 (df = 4; 249) 60.345*** (df = 5; 249) 2.506* (df = 3; 251) 74.756*** (df = 4; 250) 4.119** (df = 1; 253)
## ==========================================================================================================================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
Let’s start with IRFs:
irf <- irf(var2, n.ahead=20)
par(mfcol=c(2,2), cex=0.6)
plot(irf, plot.type="single")
And then FEVD:
fevd <- fevd(var2, n.ahead=40)
fevd[[1]][c(1,4,8,40),]
## y1 y2
## [1,] 1.0000000 0.0000000
## [2,] 0.8607464 0.1392536
## [3,] 0.8591922 0.1408078
## [4,] 0.8591882 0.1408118
fevd[[2]][c(1,4,8,40),]
## y1 y2
## [1,] 0.01847382 0.9815262
## [2,] 0.02623100 0.9737690
## [3,] 0.02642786 0.9735721
## [4,] 0.02642813 0.9735719
plot(fevd)
Now we have to change the order (\(y_1\) and \(y_2\)) and plot the IRFs abd FEVD again.
y.Q2 <- cbind(y2, y1)
y.Q2 <- window(y.Q2, start="1951 Q1", end="2014 Q4")
VARselect(y.Q2, lag.max=8, type="const")
## $selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 2 2 1 2
##
## $criteria
## 1 2 3 4
## AIC(n) -1.465126e+01 -1.470486e+01 -1.469229e+01 -1.466603e+01
## HQ(n) -1.461704e+01 -1.464783e+01 -1.461245e+01 -1.456337e+01
## SC(n) -1.456626e+01 -1.456319e+01 -1.449395e+01 -1.441102e+01
## FPE(n) 4.335513e-07 4.109277e-07 4.161332e-07 4.272205e-07
## 5 6 7 8
## AIC(n) -1.464883e+01 -1.462725e+01 -1.461845e+01 -1.459013e+01
## HQ(n) -1.452337e+01 -1.447897e+01 -1.444736e+01 -1.439622e+01
## SC(n) -1.433716e+01 -1.425891e+01 -1.419344e+01 -1.410845e+01
## FPE(n) 4.346529e-07 4.441705e-07 4.481426e-07 4.610779e-07
Again based on AIC we have to choose lag that is equal to 2.
var22<-VAR(y.Q2,p=2,type="const")
irf2 <- irf(var22, n.ahead=40)
par(mfcol=c(2,2), cex=0.6)
plot(irf2, plot.type="single")
fevd2 <- fevd(var22, n.ahead=40)
fevd2[[1]][c(1,4,8,40),]
## y2 y1
## [1,] 1.0000000 0.000000000
## [2,] 0.9935239 0.006476147
## [3,] 0.9934082 0.006591832
## [4,] 0.9934079 0.006592058
fevd2[[2]][c(1,4,8,40),]
## y2 y1
## [1,] 0.01847382 0.9815262
## [2,] 0.18059627 0.8194037
## [3,] 0.18207471 0.8179253
## [4,] 0.18207906 0.8179209
plot(fevd2)
After the introduction of the reverse order we can notice the differences in the plots. They are not the same, or show similar pattern. So the conclusion is that order matters.