2
load("USA_data.RData")
attach(USA_data)
yo<-ts(YO, start= 1960, frequency=1)
io<-ts(IO, start= 1960, frequency=1)
lnyo<-log(yo)
lnio<-log(io)
llnio<-embed(lnyo, dimension = 2)
llnyo<-embed(lnio, dimension = 2)
dlnio <- diff(lnio)
dlnyo <- diff(lnyo)
llnio0 <- llnio[, 1]
llnio1 <- llnio[, 2]
llnyo0<-llnyo[,1]
llnyo1<-llnyo[ ,2]
ts.plot(dlnio)

ts.plot(dlnyo)

library(bootUR)
adflnio<- adf(dlnio, deterministics = "intercept")
adflnio
##
## Two-step ADF test (with intercept) on a single time series
##
## data: dlnio
## null hypothesis: Series has a unit root
## alternative hypothesis: Series is stationary
##
## estimate largest root statistic p-value
## dlnio 0.1038 -7.088 1.362e-07
acf(dlnio)

acf(dlnyo)

unio<- boot_union(dlnio)
## Progress: |------------------|
## ********************
unio
##
## AWB bootstrap union test on a single time series
##
## data: dlnio
## null hypothesis: Series has a unit root
## alternative hypothesis: Series is stationary
##
## estimate largest root statistic p-value
## dlnio NA -3.179 0
unyo<- boot_union(dlnyo)
## Progress: |------------------|
## ********************
unyo
##
## AWB bootstrap union test on a single time series
##
## data: dlnyo
## null hypothesis: Series has a unit root
## alternative hypothesis: Series is stationary
##
## estimate largest root statistic p-value
## dlnyo NA -2.136 0
#They are both stationary
ts.plot(dlnyo)

3
library(vars)
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
VAR_data <- data.frame(dlnio, dlnyo)
var1 <- VAR(VAR_data, p = 1)
summary(var1)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: dlnio, dlnyo
## Deterministic variables: const
## Sample size: 62
## Log Likelihood: 281.251
## Roots of the characteristic polynomial:
## 0.2753 0.06856
## Call:
## VAR(y = VAR_data, p = 1)
##
##
## Estimation results for equation dlnio:
## ======================================
## dlnio = dlnio.l1 + dlnyo.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dlnio.l1 0.04046 0.25950 0.156 0.877
## dlnyo.l1 0.22867 0.81124 0.282 0.779
## const 0.02643 0.01878 1.407 0.165
##
##
## Residual standard error: 0.06551 on 59 degrees of freedom
## Multiple R-Squared: 0.01209, Adjusted R-squared: -0.02139
## F-statistic: 0.3612 on 2 and 59 DF, p-value: 0.6984
##
##
## Estimation results for equation dlnyo:
## ======================================
## dlnyo = dlnio.l1 + dlnyo.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dlnio.l1 -0.028858 0.081175 -0.356 0.723477
## dlnyo.l1 0.303444 0.253767 1.196 0.236576
## const 0.021731 0.005875 3.699 0.000478 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.02049 on 59 degrees of freedom
## Multiple R-Squared: 0.05281, Adjusted R-squared: 0.0207
## F-statistic: 1.645 on 2 and 59 DF, p-value: 0.2018
##
##
##
## Covariance matrix of residuals:
## dlnio dlnyo
## dlnio 0.004292 0.00117
## dlnyo 0.001170 0.00042
##
## Correlation matrix of residuals:
## dlnio dlnyo
## dlnio 1.0000 0.8712
## dlnyo 0.8712 1.0000
#insignificant as they are stationary
#R2 vlues demonstrate the lack of fit
plot(var1)


4
rvar1<-resid(var1)
rvar1io<-rvar1[,1]
rvar1yo<-rvar1[,2]
plot(rvar1io, type="l")

#No, I don't
plot(rvar1yo, type="l")

#No, I don't
acf(rvar1)

# I do not think so as I do not see any relationship between lags, just some seemingly random spikes.
ccf(x = rvar1io, y = rvar1yo)

5
VARselect(VAR_data)
## $selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 2 2 2 2
##
## $criteria
## 1 2 3 4 5
## AIC(n) -1.456264e+01 -1.484336e+01 -1.478655e+01 -1.475538e+01 -1.464435e+01
## HQ(n) -1.447686e+01 -1.470040e+01 -1.458641e+01 -1.449805e+01 -1.432984e+01
## SC(n) -1.433959e+01 -1.447160e+01 -1.426610e+01 -1.408622e+01 -1.382649e+01
## FPE(n) 4.738394e-07 3.581796e-07 3.798662e-07 3.932843e-07 4.419311e-07
## 6 7 8 9 10
## AIC(n) -1.450847e+01 -1.454636e+01 -1.445019e+01 -1.443074e+01 -1.434377e+01
## HQ(n) -1.413678e+01 -1.411749e+01 -1.396413e+01 -1.388749e+01 -1.374335e+01
## SC(n) -1.354191e+01 -1.343110e+01 -1.318623e+01 -1.301807e+01 -1.278241e+01
## FPE(n) 5.104106e-07 4.970402e-07 5.555801e-07 5.777715e-07 6.462885e-07
#2 2
var2 <- VAR(VAR_data, p = 2)
summary(var2)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: dlnio, dlnyo
## Deterministic variables: const
## Sample size: 61
## Log Likelihood: 293.108
## Roots of the characteristic polynomial:
## 0.4371 0.4371 0.3181 0.3181
## Call:
## VAR(y = VAR_data, p = 2)
##
##
## Estimation results for equation dlnio:
## ======================================
## dlnio = dlnio.l1 + dlnyo.l1 + dlnio.l2 + dlnyo.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dlnio.l1 -0.14211 0.25030 -0.568 0.57245
## dlnyo.l1 1.00804 0.79941 1.261 0.21254
## dlnio.l2 0.39657 0.24749 1.602 0.11471
## dlnyo.l2 -2.16972 0.79215 -2.739 0.00825 **
## const 0.05943 0.02142 2.775 0.00749 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.06156 on 56 degrees of freedom
## Multiple R-Squared: 0.1604, Adjusted R-squared: 0.1004
## F-statistic: 2.675 on 4 and 56 DF, p-value: 0.04107
##
##
## Estimation results for equation dlnyo:
## ======================================
## dlnyo = dlnio.l1 + dlnyo.l1 + dlnio.l2 + dlnyo.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dlnio.l1 -0.045898 0.083467 -0.550 0.58458
## dlnyo.l1 0.372803 0.266581 1.398 0.16749
## dlnio.l2 0.041679 0.082532 0.505 0.61554
## dlnyo.l2 -0.179285 0.264161 -0.679 0.50013
## const 0.023644 0.007141 3.311 0.00163 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.02053 on 56 degrees of freedom
## Multiple R-Squared: 0.06593, Adjusted R-squared: -0.000788
## F-statistic: 0.9882 on 4 and 56 DF, p-value: 0.4216
##
##
##
## Covariance matrix of residuals:
## dlnio dlnyo
## dlnio 0.003790 0.0011509
## dlnyo 0.001151 0.0004215
##
## Correlation matrix of residuals:
## dlnio dlnyo
## dlnio 1.0000 0.9106
## dlnyo 0.9106 1.0000
# now dlnyo.l2 is 12 is significant.
rvar2<-resid(var2)
rvar2io<-rvar2[,1]
rvar2yo<-rvar2[,2]
plot(rvar2io, type="l")

#No, I don't
plot(rvar2yo, type="l")

#No, I don't
acf(rvar2)

# I do not think so as I do not see any relationship between lags, just some seemingly random spikes.
ccf(x = rvar2io, y = rvar2yo)

6
#φp,12= 0, φp,21= 0
causality(x = var1, cause = "dlnyo")$Granger
##
## Granger causality H0: dlnyo do not Granger-cause dlnio
##
## data: VAR object var1
## F-Test = 0.079455, df1 = 1, df2 = 118, p-value = 0.7785
# No granger causality
causality(x = var1, cause = "dlnio")$Granger
##
## Granger causality H0: dlnio do not Granger-cause dlnyo
##
## data: VAR object var1
## F-Test = 0.12639, df1 = 1, df2 = 118, p-value = 0.7228
# No granger causality
# They have same p values
causality(x = var2, cause = "dlnyo")$Granger
##
## Granger causality H0: dlnyo do not Granger-cause dlnio
##
## data: VAR object var2
## F-Test = 3.9259, df1 = 2, df2 = 112, p-value = 0.0225
causality(x = var2, cause = "dlnio")$Granger
##
## Granger causality H0: dlnio do not Granger-cause dlnyo
##
## data: VAR object var2
## F-Test = 0.24643, df1 = 2, df2 = 112, p-value = 0.782
# No
# Yes, same p values
7
# How does a variable response to a shock meaning a sudden change in erros
irf_var2 <- irf(var2, ortho = F)
plot(irf_var2)

