############### # Time Series # ############### library(wooldridge) # ls("package:wooldridge") data(fertil3, package='wooldridge') fertil3[1:5,c("gfr","pe","year","pill")] # time series plot par(mfrow = c(1, 2)) plot(gfr~year,data=fertil3,type="l") plot(pe~year,data=fertil3,type="l") # static model summary(lm(gfr~pe+ww2+pill,data=fertil3))$coef # DL model and multicollinearity n = nrow(fertil3) fertil3$pelag1 = c(NA,fertil3$pe[1:(n-1)]) fertil3$pelag2 = c(NA,NA,fertil3$pe[1:(n-2)]) summary(lm(gfr~pe+pelag1+pelag2+ww2+pill,data=fertil3))$coef m = lm(gfr~pe+pelag1+pelag2+ww2+pill,data=fertil3) library("car") linearHypothesis(m, c("pe=0", "pelag1=0","pelag2=0")) summary(lm(pe~pelag1+pelag2,data=fertil3))$r.squared # restricted DL model linearHypothesis(m, c("pe=pelag1", "pe=pelag2")) fertil3$z=fertil3$pe+fertil3$pelag1+fertil3$pelag2 summary(lm(gfr~z+ww2+pill,data=fertil3))$coef # LRP and transformed regression fertil3$dpe1 = fertil3$pe-fertil3$pelag1 fertil3$dpe2 = fertil3$pe-fertil3$pelag2 summary(lm(gfr~pe+dpe1+dpe2+ww2+pill,data=fertil3))$coef # ADL model fertil3$gfrlag1 = c(NA,fertil3$gfr[1:(n-1)]) summary(lm(gfr~gfrlag1+pe+ww2+pill,data=fertil3))$coef # AR(1) model summary(lm(gfr~gfrlag1,data=fertil3))$coef co = coef(lm(gfr~gfrlag1,data=fertil3)) cat("one-step ahead forecast is", co[2]*fertil3$gfr[72],"\n") cat("two-step ahead forecast is", co[2]*co[2]*fertil3$gfr[72],"\n")