Econ 508
Econometrics Group
Home | Faculty | Students | Alumni | Courses | Research | Reproducibility | Lab | Seminars | Economics | Statistics | Fame
Applied Econometrics - Fall 2011

 Lecture 9 Figure 1: R code


 
 

                   

        # Figures to illustrate the difference between forecasting in Trend
        # Stationary and Unit Root Models for Lecture 9 of 508
        u <- rnorm(120)
        s <- 1:120
        y <- .3*s+5*filter(u,c(.95,-.1),"recursive",init=rnorm(2))
        fit0 <- arima0(y,order=c(2,0,0),xreg=s)
        fit1 <- arima0(y,order=c(2,1,0),xreg=s,include.mean=T)
        fore0 <- predict(fit0,n.ahead=44,newxreg=121:164)
        fore1 <- predict(fit1,n.ahead=44,newxreg=121:164)
        pdf("fig1R.pdf",width=6.0,height=4)
        par(mfrow=c(1,2))
        ts.plot(y,fore0$pred,fore0$pred+2*fore0$se, fore0$pred-2*fore0$se,
        gpars=list(lty=c( 1,2,3,3)))
        abline(fit0$coef[3:4],lty=2)
        ts.plot(y,fore1$pred,fore1$pred+2*fore1$se, fore1$pred-2*fore1$se,
        gpars=list(lty=c( 1,2,3,3)))
        abline(c(0,fit1$coef[3]),lty=2)

        dev.off()

 

 Last update: September 21, 2012 .  Send comments to: gu17@uiuc.edu