library("Quandl")
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library("vars")
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
library("gdata")
## gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
## 
## gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.
## 
## Attaching package: 'gdata'
## The following objects are masked from 'package:xts':
## 
##     first, last
## The following object is masked from 'package:stats':
## 
##     nobs
## The following object is masked from 'package:utils':
## 
##     object.size
library("stargazer")
## 
## Please cite as:
##  Hlavac, Marek (2015). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2. http://CRAN.R-project.org/package=stargazer
library("tseries")
pi <- Quandl("FRED/INDPRO", type="zoo")
cpi <- Quandl("FRED/CPIAUCSL", type="zoo")
pi <- window(pi,start="JAN 1947", end="Feb 2016")
cpi <- window(cpi,start="Jan 1947", end="Feb 2016")
lpi <- log(pi)
lcpi <- log(cpi)
dlpi <- diff(lpi,1)
dlcpi <- diff(lcpi,1)
par(mfrow=c(2,2))
plot(lpi,xlab="Period", ylab="Log of PI")
plot(lcpi, xlab="Period", ylab="Log of CPI")
plot(dlpi,xlab="Period", ylab="Diff of log PI")
plot(dlcpi, xlab="Period", ylab="Diff of log CPI")

adf.test(lpi)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  lpi
## Dickey-Fuller = -2.0144, Lag order = 9, p-value = 0.5722
## alternative hypothesis: stationary
adf.test(lcpi)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  lcpi
## Dickey-Fuller = -1.2868, Lag order = 9, p-value = 0.8802
## alternative hypothesis: stationary
adf.test(dlcpi)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dlcpi
## Dickey-Fuller = -3.9607, Lag order = 9, p-value = 0.01096
## alternative hypothesis: stationary

B

y <- cbind(dlpi, dlcpi)
y <- na.trim(y)
y<- sweep(y,2,apply(y,2,mean))
VARselect(y,lag.max=10)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##     10      4      2     10 
## 
## $criteria
##                    1             2             3             4
## AIC(n) -2.125239e+01 -2.129200e+01 -2.131248e+01 -2.132251e+01
## HQ(n)  -2.123916e+01 -2.126994e+01 -2.128160e+01 -2.128280e+01
## SC(n)  -2.121790e+01 -2.123452e+01 -2.123200e+01 -2.121903e+01
## FPE(n)  5.891187e-10  5.662403e-10  5.547638e-10  5.492289e-10
##                    5             6             7             8
## AIC(n) -2.132836e+01 -2.133638e+01 -2.134489e+01 -2.134279e+01
## HQ(n)  -2.127983e+01 -2.127903e+01 -2.127872e+01 -2.126779e+01
## SC(n)  -2.120189e+01 -2.118692e+01 -2.117244e+01 -2.114734e+01
## FPE(n)  5.460237e-10  5.416618e-10  5.370741e-10  5.382056e-10
##                    9            10
## AIC(n) -2.135631e+01 -2.136879e+01
## HQ(n)  -2.127248e+01 -2.127614e+01
## SC(n)  -2.113786e+01 -2.112735e+01
## FPE(n)  5.309843e-10  5.244008e-10
var1 <- VAR(y,p=7, type="const")
summary(var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: dlpi, dlcpi 
## Deterministic variables: const 
## Sample size: 822 
## Log Likelihood: 6452.474 
## Roots of the characteristic polynomial:
## 0.9028 0.7865 0.7371 0.7371 0.7223 0.7223 0.6597 0.6597 0.6512 0.6512 0.6193 0.6193 0.4736 0.4736
## Call:
## VAR(y = y, p = 7, type = "const")
## 
## 
## Estimation results for equation dlpi: 
## ===================================== 
## dlpi = dlpi.l1 + dlcpi.l1 + dlpi.l2 + dlcpi.l2 + dlpi.l3 + dlcpi.l3 + dlpi.l4 + dlcpi.l4 + dlpi.l5 + dlcpi.l5 + dlpi.l6 + dlcpi.l6 + dlpi.l7 + dlcpi.l7 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## dlpi.l1   3.119e-01  3.519e-02   8.865  < 2e-16 ***
## dlcpi.l1  2.182e-01  1.141e-01   1.911  0.05632 .  
## dlpi.l2   9.524e-02  3.679e-02   2.589  0.00981 ** 
## dlcpi.l2 -9.303e-02  1.246e-01  -0.747  0.45544    
## dlpi.l3   8.096e-02  3.699e-02   2.189  0.02891 *  
## dlcpi.l3 -6.987e-04  1.243e-01  -0.006  0.99551    
## dlpi.l4   4.045e-02  3.706e-02   1.091  0.27538    
## dlcpi.l4 -1.110e-01  1.239e-01  -0.896  0.37048    
## dlpi.l5  -7.732e-02  3.688e-02  -2.097  0.03633 *  
## dlcpi.l5 -2.493e-02  1.232e-01  -0.202  0.83973    
## dlpi.l6   1.333e-02  3.684e-02   0.362  0.71752    
## dlcpi.l6 -2.069e-01  1.208e-01  -1.712  0.08721 .  
## dlpi.l7   2.976e-02  3.509e-02   0.848  0.39661    
## dlcpi.l7 -1.086e-01  1.116e-01  -0.973  0.33067    
## const     8.453e-06  3.036e-04   0.028  0.97779    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.008703 on 807 degrees of freedom
## Multiple R-Squared: 0.1932,  Adjusted R-squared: 0.1792 
## F-statistic:  13.8 on 14 and 807 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation dlcpi: 
## ====================================== 
## dlcpi = dlpi.l1 + dlcpi.l1 + dlpi.l2 + dlcpi.l2 + dlpi.l3 + dlcpi.l3 + dlpi.l4 + dlcpi.l4 + dlpi.l5 + dlcpi.l5 + dlpi.l6 + dlcpi.l6 + dlpi.l7 + dlcpi.l7 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## dlpi.l1  -5.826e-03  1.081e-02  -0.539  0.58993    
## dlcpi.l1  4.434e-01  3.506e-02  12.648  < 2e-16 ***
## dlpi.l2   2.907e-02  1.130e-02   2.572  0.01028 *  
## dlcpi.l2  4.396e-02  3.826e-02   1.149  0.25095    
## dlpi.l3   6.764e-03  1.136e-02   0.595  0.55173    
## dlcpi.l3  6.811e-02  3.816e-02   1.785  0.07464 .  
## dlpi.l4  -2.168e-03  1.138e-02  -0.190  0.84897    
## dlcpi.l4  4.042e-02  3.805e-02   1.062  0.28847    
## dlpi.l5  -1.991e-02  1.133e-02  -1.758  0.07912 .  
## dlcpi.l5  5.481e-02  3.784e-02   1.449  0.14785    
## dlpi.l6   2.413e-02  1.131e-02   2.133  0.03323 *  
## dlcpi.l6  5.981e-02  3.711e-02   1.611  0.10746    
## dlpi.l7   3.861e-03  1.077e-02   0.358  0.72017    
## dlcpi.l7  9.329e-02  3.428e-02   2.722  0.00663 ** 
## const    -2.298e-05  9.323e-05  -0.246  0.80537    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.002673 on 807 degrees of freedom
## Multiple R-Squared: 0.4078,  Adjusted R-squared: 0.3975 
## F-statistic: 39.69 on 14 and 807 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##            dlpi     dlcpi
## dlpi  7.575e-05 7.511e-07
## dlcpi 7.511e-07 7.144e-06
## 
## Correlation matrix of residuals:
##          dlpi   dlcpi
## dlpi  1.00000 0.03229
## dlcpi 0.03229 1.00000

C

svar1 <- VAR(y,ic="AIC", lag.max=10)
svar1.r <-BQ(svar1)
summary(svar1.r)
## 
## SVAR Estimation Results:
## ======================== 
## 
## Call:
## BQ(x = svar1)
## 
## Type: Blanchard-Quah 
## Sample size: 819 
## Log Likelihood: 6447.023 
## 
## Estimated contemporaneous impact matrix:
##            dlpi    dlcpi
## dlpi   0.006485 0.005824
## dlcpi -0.001631 0.001978
## 
## Estimated identified long run impact matrix:
##            dlpi   dlcpi
## dlpi   0.015360 0.00000
## dlcpi -0.004352 0.01474
## 
## Covariance matrix of reduced form residuals (*100):
##            dlpi     dlcpi
## dlpi  7.597e-03 9.415e-05
## dlcpi 9.415e-05 6.574e-04

D

var1.irfs <- irf(var1, n.ahead=30, cumulative=T)
par(mfcol=c(2,2))
plot(var1.irfs, plot.type="single")

F

var1.fevd <- fevd(var1, n.ahead=30)
var1.fevd[[1]][c(1,4,8,30)]
## [1] 1.0000000 0.9955300 0.9836736 0.9616605
plot(var1.fevd)

plot(var1.fevd, addbars=8)