# R 3.0.1 # Ex4_Pepper_R.txt rm(list=ls()) library("tseries") library("zoo") library("dynlm") library("urca") library("vars") library("AER") data("PepperPrice") # Plots plot(PepperPrice, plot.type= "single", col =1:2 ) # series legend("topleft", c("black", "white"), bty = "n" , col =1:2, lty = rep(1,2) ) plot(PepperPrice[,"black"],PepperPrice[,"white"]) # scatter #adf.test( log(PepperPrice[, "white"])) #adf.test( diff( log(PepperPrice[, "white"]) ) ) ##Dickey-Fuller Unit root test: level and 1st difference # tau* test for H0: (1-rho) = 0 in various models # phi1 test for H0: const=0 and (1-rho) = 0 in model w const/drift # phi3 test for H0: no trend and (1-rho) = 0 in trend model ## type = "none" or "drift" or "trend" ## selectlags= "Fixed" or "AIC", ... ## relevant statistic: tau w.df <- ur.df( log(PepperPrice[, "white"]) , type="drift", lags=5, selectlags="AIC") summary(w.df) dw.df <- ur.df( diff(log(PepperPrice[, "white"])) , type="drift", lags=5, selectlags="AIC") summary(dw.df) b.df <- ur.df( log(PepperPrice[, "black"]) , type="drift", lags=5, selectlags="AIC") summary(b.df) db.df <- ur.df( diff(log(PepperPrice[, "black"])) , type="drift", lags=5, selectlags="AIC") summary(db.df) ##Cointegration - test # spec="transitory" is our specification: Delta x_t = ... Pi x_(t-1) ... # const in Delta x always included # help("ca.jo-class") reference: ci_test@Z0 ## type = c("eigen", "trace"), ... tests ## ecdet = c("none", "const", "trend") ... deterministic part ## (K-1) no of lags of Delta x included pepper.jo <- ca.jo( log(PepperPrice) , ecdet = "none", type = "trace", K=2, spec="transitory") # with ecdet="none" r=1 signif summary(pepper.jo) pepper.jo <- ca.jo( log(PepperPrice) , ecdet = "none", type = "eigen", K=2, spec="transitory") # with ecdet="none" r=1 signif summary(pepper.jo) ## CI VAR pepper.civar <- cajorls(pepper.jo, r = 1) # r ... chosen coint rank summary(pepper.civar$rlm) # No t-values for beta, AIC pepper.civar$beta # ect error correction term #pix <- pepper.jo@ZK %*% t(pepper.jo@PI) # Pi * x(t-1) #varlevel <- vec2var(pepper.jo, r=1) # coeff matrices of the lagged endogenous vars ## EXERCISE: # (1) Repeat all single steps and comment. # (2) Write down the estimated CIVAR.