You are on page 1of 3

raw.data<- read.csv("tobbaco.

csv",header=TRUE)
tobcp<-ts(raw.data$tobcp,start=c(1980,1),frequency=12)
cpi<-ts(raw.data$cpi,start=c(1980,1),frequency=12)
indp<-ts(raw.data$indp,start=c(1980,1),frequency=12)
discrate<-ts(raw.data$discrate,start=c(1980,1),frequency=12)
###########################data transformation 1####################
lcpi<-log(cpi)
lindp<-log(indp)
ltobcp<-log(tobcp)
ldiscrate<-log(discrate)
#############################gaphs#####################################
graph1<- ts.intersect(lindp,lcpi,ldiscrate,ltobcp)
plot(graph1, nc = 4, xlab = "")
require(dynlm)
############################# stationarity test #######################
require(urca)
df.lindp <- ur.df(lindp, type="none", selectlags="AIC")
summary(df.lindp)
df.lcpi <- ur.df(lcpi, type="trend", selectlags="AIC")
summary(df.lcpi)
df.ltobcp <- ur.df(ltobcp, type="trend", selectlags="AIC")
summary(df.ltobcp)
df.ldiscrate <- ur.df(ldiscrate, type="trend", selectlags="AIC")
summary(df.ldiscrate)
###########################data transformation #######################
dlindp <- diff(lindp)
dlcpi <- diff(lcpi)
dltobcp <- diff(ltobcp)
dldiscrate <- diff(ldiscrate)
graph2<- ts.intersect(dlindp,dlcpi, dltobcp, dldiscrate)
plot(graph2, nc = 4, xlab = "")
###################### unit root test ################################
df.dlcpi<- ur.df(dlcpi, type="none", selectlags="AIC")
summary(df.dlcpi)
df.dlindp<- ur.df(dlindp, type="none", selectlags="AIC")
summary(df.dlindp)
df.dltobcp<- ur.df(dltobcp, type="none", selectlags="AIC")
summary(df.dltobcp)
df.dldiscrate<- ur.df(dldiscrate, type="none", selectlags="AIC")
summary(df.dldiscrate)
############################ cointegration test #######################
cidata <- ts.intersect(lindp, lcpi, ldiscrate, ltobcp)
summary(ca.jo(cidata, K=2, type="trace"))
summary(ca.jo(cidata, K=2, type="eigen"))

#################### Granger Causality ################################


require(vars)
causaldata1<- ts.intersect(dltobcp, dlindp)
rfvar <- VAR(causaldata1, ic="AIC")
causality(rfvar, cause="dltobcp")
causality(rfvar, cause="dlindp")
causaldata2<- ts.intersect(dltobcp, dldiscrate)
rfvar <- VAR(causaldata2, ic="AIC")
causality(rfvar, cause="dltobcp")
causality(rfvar, cause="dldiscrate")
causaldata3<- ts.intersect(dltobcp, dlcpi)
rfvar <- VAR(causaldata3, ic="AIC")
causality(rfvar, cause="dltobcp")
causality(rfvar, cause="dlcpi")
causaldata4<- ts.intersect(dlcpi, dlindp)
rfvar <- VAR(causaldata4, ic="AIC")
causality(rfvar, cause="dlcpi")
causality(rfvar, cause="dlindp")
causaldata5<- ts.intersect(dlcpi, dldiscrate)
rfvar <- VAR(causaldata5, ic="AIC")
causality(rfvar, cause="dlcpi")
causality(rfvar, cause="dldiscrate")
causaldata6<- ts.intersect(dlindp, dldiscrate)
rfvar <- VAR(causaldata6, ic="AIC")
causality(rfvar, cause="dlindp")
causality(rfvar, cause="dldiscrate")
######## Impulse Response Functions ####################################
######## Explanation of the restrictions below##########################
###################################Using the following 4X4 B matrix :
################################################################################
#######################
######################################
tobp indp cpi intrate #####
#######################
#####################################
tobp
1
b12
b13
b14
#####
#######################
###################################### indp b21
1
b23
b24
#####
#######################
###################################### cpi
b31 b32
1
b34
#####
#######################
#################################### intrate b41 b42
b43
1
#####
#######################
################################################################################
#######################
vardata<-ts.intersect(ltobcp, lindp, lcpi, ldiscrate)
vecm <- ca.jo(vardata[, c("ltobcp", "lindp", "lcpi", "ldiscrate")], type = "trac
e",
ecdet = "trend", K = 3, spec = "transitory")
#######new
vecm
######## since the VAR has 4 variables I need n(n-1)/2 = 6 restrictions on the p
arameter B matrix #####

SR<-matrix(NA, nrow=4, ncol=4)


SR[4,2]<-0
##### justification: I assume that monetary policy cannot respond
contemporaneously to development in consumer prices and output due to lags in s
tatistical compilations, Sims and Zha (1998)##################
### justification: same as the one above.###############################
SR
LR<-matrix(NA, nrow=4, ncol=4)
LR[2,4]<-0 ################# justification: I assume that output (industrial pro
duction) reacts to monetary policy with a lag, Bernanke and Blinder, (1992).####
#################
LR[3,1]<-0 ################# justification: I assume that consumer price level i
s predetermined, (McCoy, 1997).############
LR[3,2]<-0 ################# justification: I assume that consumer price level i
s predetermined, (McCoy, 1997).############
LR[3,4]<-0 ################# justification: I assume that consumer price level i
s predetermined, (McCoy, 1997).############
LR[4,3]<-0
##
LR
svec <- SVEC(vecm, LR = LR, SR = SR, r = 1, lrtest = FALSE, boot = TRUE,
runs = 1000)
summary(svec)
svec1.irf <- irf(svec,
plot(svec1.irf)
svec2.irf <- irf(svec,
plot(svec2.irf)
svec3.irf <- irf(svec,
plot(svec3.irf)
svec4.irf <- irf(svec,
plot(svec4.irf)
######################

response = "lindp", n.ahead = 36, boot = TRUE)


response = "lcpi", n.ahead = 36, boot = TRUE)
response = "lintrate", n.ahead = 36, boot = TRUE)
response = "ltobp", n.ahead = 36, boot = TRUE
Variance Decomposition #########################

fevd.lindp <- fevd(svec, n.ahead = 36)$lindp


fevd.lindp
fevd.lcpi <- fevd(svec, n.ahead = 36)$lcpi
fevd.lcpi
fevd.lintrate <- fevd(svec, n.ahead = 36)$lintrate
fevd.lintrate
fevd.ltobcp <- fevd(svec, n.ahead = 36)$ltobcp
fevd.ltobcp

You might also like