Basic Regression Analysis with Time Series Data (Chapter 10)

Comments will follow…

setwd('...')
rm(list=ls())

library('foreign')


download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/phillips.dta','phillips.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/intdef.dta','intdef.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/prminwge.dta','prminwge.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/fertil3.dta','fertil3.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/barium.dta','barium.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/fair.dta','fair.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/hseinv.dta','hseinv.dta',mode="wb")

# Example 10.1
phillips<-read.dta('phillips.dta')

lm.10.1<-lm(inf ~ unem, data=phillips)
summary(lm.10.1)

# Example 10.2
intdef<-read.dta('intdef.dta')

lm.10.2<-lm(i3 ~ inf + def, data=intdef)
summary(lm.10.2)

# Example 10.3
prminwge<-read.dta('prminwge.dta')

lm.10.3<-lm(lprepop ~ lmincov + lusgnp, data=prminwge)
summary(lm.10.3)

# Example 10.4
fertil3<-read.dta('fertil3.dta')

lm.10.4.1<-lm(gfr ~ pe + ww2 + pill, data=fertil3)
summary(lm.10.4.1)

lm.10.4.2<-lm(gfr ~ pe + pe_1 + pe_2 + ww2 + pill, data=fertil3)
summary(lm.10.4.2)

# Joint significance of pe values
lm.10.4.2res<-lm(gfr ~ ww2 + pill, data=fertil3,subset=(is.na(pe_2)==FALSE))
anova(lm.10.4.2,lm.10.4.2res)

# Joint significance of lagged pe values
lm.10.4.2res2<-lm(gfr ~ pe + ww2 + pill, data=fertil3,subset=(is.na(pe_2)==FALSE))
anova(lm.10.4.2,lm.10.4.2res2)

# Standard error of the long run propensity
with(fertil3,{
 p1p0<-pe_1-pe
 p2p1<-pe_2-pe_1
 print(summary(lm(gfr ~ pe + p1p0 + p2p1 + ww2 + pill)))})

# Example 10.5
barium<-read.dta('barium.dta')

lm.10.5<-lm(lchnimp ~ lchempi + lgas + lrtwex + befile6 + affile6 + afdec6, data=barium)
summary(lm.10.5)

# Example 10.6
fair<-read.dta('fair.dta')

with(fair,{
 pg<-partyWH*gnews
 pi<-partyWH*inf
 lm.10.6<-lm(demvote ~ partyWH + incum + pg + pi)
 summary(lm.10.6)
})
# Slightly different results since the book uses 20 observations to 1992.
# The results are the same when we drop the last observation.
with(fair[fair$year!=1996,],{
 pg<-partyWH*gnews
 pi<-partyWH*inf
 lm.10.6<-lm(demvote ~ partyWH + incum + pg + pi)
 summary(lm.10.6)
})

# Example 10.7
hseinv<-read.dta('hseinv.dta')

lm.10.7.1<-lm(linvpc ~ lprice, data=hseinv)
summary(lm.10.7.1)

lm.10.7.2<-lm(linvpc ~ lprice + t, data=hseinv)
summary(lm.10.7.2)

# Example 10.8
fertil3<-read.dta('fertil3.dta')

lm.10.8.1<-lm(gfr ~ pe + ww2 + pill + t, data=fertil3)
summary(lm.10.8.1)

lm.10.8.2<-lm(gfr ~ pe + ww2 + pill + t + tsq, data=fertil3)
summary(lm.10.8.2)

# Example 10.9
prminwge<-read.dta('prminwge.dta')

lm.10.9<-lm(lprepop ~ lmincov + lusgnp + t, data=prminwge)
summary(lm.10.9)

# Obtain results by detrending
with(prminwge,{
 yu<-lm(lprepop ~ t)$resid
 x1u<-lm(lmincov ~ t)$resid
 x2u<-lm(lusgnp ~ t)$resid
 summary(lm(yu ~ x1u + x2u - 1))
})

# Example 10.10
hseinv<-read.dta('hseinv.dta')

with(hseinv,{
 dtr.linvpc<-lm(linvpc ~ t)$resid
 summary(lm(dtr.linvpc ~ lprice + t))
})

# Example 10.11
barium<-read.dta('barium.dta')

lm.10.11<-lm(lchnimp ~ lchempi + lgas + lrtwex + befile6 + affile6 + afdec6 +
 feb + mar + apr + may + jun + jul + aug + sep + oct + nov + dec, data=barium)
lm.10.11res<-lm(lchnimp ~ lchempi + lgas + lrtwex + befile6 + affile6 + afdec6, data=barium)
anova(lm.10.11,lm.10.11res)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s