#ESTIMATIONS TIME VARYING BOHN TEST

#############
library(mgcv)
#############

# run alg_dataimport.txt first!

# prepare the dataset
dat.pan.w<-read.csv("dat_pan_w1.csv")

dat.pan.w<-pdata.frame(dat.pan.w,index=c("idn","time"))
dat.pan.w$nfl.l1<-lag(dat.pan.w$nfl)
dat.pan.w$vol.l1<-lag(dat.pan.w$vol)
dat.pan.w$tdd.l1<-lag(dat.pan.w$tdd)
dat.pan.w$reeru.l1<-lag(dat.pan.w$reeru)
dat.pan.w$nfl.d1<-diff(dat.pan.w$nfl)
write.csv(dat.pan.w,"dat_pan_w.csv",row.names=F)
dat.pan.w<-read.csv("dat_pan_w.csv")

dat.w.north<-subset(dat.pan.w, id=="bd" | id=="fr" | id=="fn" | id=="bg" | id=="nl" | id=="oe")
dat.w.south<-subset(dat.pan.w, id=="it" | id=="es" | id=="pt")
dat.w.nonemu<-subset(dat.pan.w, id=="uk" | id=="sd" | id=="no" | id=="dk")


#ESTIMATION BOHN VOL

#how does the response of ta to nfl change with volatility in the real exchange rate for the northern and southern block?
gam.w.north<-gam(ta~s(vol,by=nfl.l1)+tdd.l1+reeru.l1-1,data=dat.w.north); summary(gam.w.north)
gam.w.south<-gam(ta~s(vol,by=nfl.l1)+tdd.l1+reeru.l1-1,data=dat.w.south); summary(gam.w.south)
gam.w.nonemu<-gam(ta~s(vol,by=nfl.l1)+tdd.l1+reeru.l1-1,data=dat.w.nonemu); summary(gam.w.nonemu)


#plot for north and south and nonemu
postscript("bohn_splines_rhovol.eps", paper="special", width=8, height=2.5, horizontal=FALSE)
par(mfrow=c(1,3),mar=c(4, 4, 2, 1) )
plot(gam.w.north,ylab="rho(v)",xlab="v",main="North",ylim=c(-0.1,0.07))
plot(gam.w.south,ylab="rho(v)",xlab="v",main="South",ylim=c(-0.1,0.07))
plot(gam.w.nonemu,ylab="rho(v)",xlab="v",main="non-EMU",ylim=c(-0.1,0.07))
dev.off()











