library(readxl)
data_da <- read_excel("~/data_da.xlsx")
View(data_da)
library("urca")
attach(data_da)
library("tseries")
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
#VECM
library(urca)
#install.packages("vars")
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: lmtest
y=data_da
attach(y)
## The following objects are masked from data_da:
## 
##     CHINA, Date, GDP, LN_CHINA, LN_GDP, LN_REER, LN_TB, REER, TB
z=cbind(LN_TB, LN_REER, LN_GDP, LN_CHINA)
VARselect(z, lag.max = 5, type = "const")
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      5      5      5      5 
## 
## $criteria
##                    1             2             3             4
## AIC(n) -1.526516e+01 -1.613542e+01 -1.739673e+01 -1.875466e+01
## HQ(n)  -1.501674e+01 -1.568828e+01 -1.675086e+01 -1.791007e+01
## SC(n)  -1.464243e+01 -1.501452e+01 -1.577766e+01 -1.663742e+01
## FPE(n)  2.348473e-07  9.875978e-08  2.825493e-08  7.403823e-09
##                    5
## AIC(n) -1.990363e+01
## HQ(n)  -1.886031e+01
## SC(n)  -1.728821e+01
## FPE(n)  2.419842e-09
VARselect(z, lag.max = 5, type = "const")$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      5      5      5      5
cointest<-ca.jo(z, K=5, type = "eigen", ecdet = "const",
                spec = "transitory")
cointest
## 
## ##################################################### 
## # Johansen-Procedure Unit Root / Cointegration Test # 
## ##################################################### 
## 
## The value of the test statistic is: 4.9063 9.0423 10.6001 24.5439
cointest@teststat[4]
## [1] 24.54387
cointest@teststat[3]
## [1] 10.60007
cointest@teststat[2]
## [1] 9.042304
cointest@teststat[1]
## [1] 4.906331
cointest@cval
##          10pct  5pct  1pct
## r <= 3 |  7.52  9.24 12.97
## r <= 2 | 13.75 15.67 20.20
## r <= 1 | 19.77 22.00 26.81
## r = 0  | 25.56 28.14 33.24
vecm <- cajorls(cointest)
vecm$rlm$coefficients[1,1]
## [1] -0.3463835
vecm$rlm$coefficients[1,2]
## [1] -0.006340381
vecm$rlm$coefficients[1,3]
## [1] -0.01023293
vecm$rlm$coefficients[1,4]
## [1] 0.01195659
vecm$beta[1,1]
## [1] 1
vecm$beta[2,1]
## [1] 4.776111
vecm$beta[3,1]
## [1] 1.863192
vecm$beta[4,1]
## [1] -4.260172
vecm$beta
##                  ect1
## LN_TB.l1     1.000000
## LN_REER.l1   4.776111
## LN_GDP.l1    1.863192
## LN_CHINA.l1 -4.260172
## constant    69.521442
library(lmtest)
lntb=diff(data_da$LN_TB)
lnreer=diff(data_da$LN_REER)
grangertest(lntb~lnreer, order=2)
## Granger causality test
## 
## Model 1: lntb ~ Lags(lntb, 1:2) + Lags(lnreer, 1:2)
## Model 2: lntb ~ Lags(lntb, 1:2)
##   Res.Df Df     F Pr(>F)
## 1     71                
## 2     73 -2 0.937 0.3966
grangertest(lnreer~lntb, order=2)
## Granger causality test
## 
## Model 1: lnreer ~ Lags(lnreer, 1:2) + Lags(lntb, 1:2)
## Model 2: lnreer ~ Lags(lnreer, 1:2)
##   Res.Df Df      F Pr(>F)
## 1     71                 
## 2     73 -2 1.1382 0.3262
attach(data_da)
## The following objects are masked from y:
## 
##     CHINA, Date, GDP, LN_CHINA, LN_GDP, LN_REER, LN_TB, REER, TB
## The following objects are masked from data_da (pos = 11):
## 
##     CHINA, Date, GDP, LN_CHINA, LN_GDP, LN_REER, LN_TB, REER, TB
adf.test(LN_GDP)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  LN_GDP
## Dickey-Fuller = -1.2395, Lag order = 4, p-value = 0.8866
## alternative hypothesis: stationary
adf.test(LN_REER)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  LN_REER
## Dickey-Fuller = -2.1346, Lag order = 4, p-value = 0.5206
## alternative hypothesis: stationary
adf.test(LN_TB)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  LN_TB
## Dickey-Fuller = -1.9324, Lag order = 4, p-value = 0.6033
## alternative hypothesis: stationary
adf.test(LN_CHINA)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  LN_CHINA
## Dickey-Fuller = -1.5152, Lag order = 4, p-value = 0.7739
## alternative hypothesis: stationary