More on Specification and Data Issues (Chapter 9)

Comments will follow…

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

library('foreign')

download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/crime1.dta','crime1.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/hprice1.dta','hprice1.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/wage2.dta','wage2.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/crime2.dta','crime2.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/rdchem.dta','rdchem.dta',mode="wb")
download.file('http://fmwww.bc.edu/ec-p/data/wooldridge/infmrt.dta','infmrt.dta',mode="wb")

# Example 9.1
crime1<-read.dta('crime1.dta')
lm.9.1.1<-lm(narr86 ~ pcnv + avgsen + tottime + ptime86 + qemp86 + inc86 + black + hispan, data=crime1)
summary(lm.9.1.1)
# Seems to be an error in the book.
# Although all coefficients and their standard errors are equal
# the intercept term is 0.569 instead of 0.596.

lm.9.1.2<-lm(narr86 ~ pcnv + avgsen + tottime + ptime86 + qemp86 + inc86 + black + hispan +
 pcnvsq + pt86sq + inc86sq, data=crime1)
summary(lm.9.1.2)

anova(lm.9.1.1,lm.9.1.2)

# Example 9.2
hprice1<-read.dta('hprice1.dta')

lm.9.2.1<-lm(price ~ lotsize + sqrft + bdrms, data=hprice1)
fit2.1<-lm.9.2.1$fitted.values^2
fit3.1<-lm.9.2.1$fitted.values^3
lm.9.2.1.reset<-lm(price ~ lotsize + sqrft + bdrms + fit2.1 + fit3.1, data=hprice1)
anova(lm.9.2.1,lm.9.2.1.reset)


lm.9.2.2<-lm(lprice ~ llotsize + lsqrft + bdrms, data=hprice1)
fit2.2<-lm.9.2.2$fitted.values^2
fit3.2<-lm.9.2.2$fitted.values^3
lm.9.2.2.reset<-lm(lprice ~ llotsize + lsqrft + bdrms + fit2.2 + fit3.2, data=hprice1)
anova(lm.9.2.2,lm.9.2.2.reset)

# Table 9.2
wage2<-read.dta('wage2.dta')

lm.t9.2.1<-lm(lwage ~ educ + exper + tenure + married + south + urban + black, data=wage2)
summary(lm.t9.2.1)

lm.t9.2.2<-lm(lwage ~ educ + exper + tenure + married + south + urban + 
                black + IQ, data=wage2)
summary(lm.t9.2.2)

lm.t9.2.3<-lm(lwage ~ educ + exper + tenure + married + south + urban + 
                black + IQ + IQ*educ, data=wage2)
summary(lm.t9.2.3)

# Example 9.4
crime2<-read.dta('crime2.dta')

lm.9.4.1<-lm(lcrmrte ~ unem + llawexpc, data=crime2, subset=(d87==1))
summary(lm.9.4.1)

lm.9.4.2<-lm(lcrmrte ~ unem + llawexpc + lcrmrt_1, data=crime2, subset=(d87==1))
summary(lm.9.4.2)

# Example 9.8
rdchem<-read.dta('rdchem.dta')

lm.9.8.1<-lm(rdintens ~ sales + profmarg, data=rdchem)
summary(lm.9.8.1)

# See the outliers
with(rdchem, plot(sales,rdintens,pch=16))

# Test without the biggest firm
lm.9.8.2<-lm(rdintens ~ sales + profmarg, data=rdchem, subset=(sales<30000))
summary(lm.9.8.2)
# Slightly different result as in the book

# Dummy for the biggest firm
big<-as.numeric(rdchem$sales==max(rdchem$sales))
lm.9.8.3<-lm(rdintens ~ sales + profmarg + big, data=rdchem)
summary(lm.9.8.3)

# Dummy for highest rdintens
hi.rdint<-as.numeric(rdchem$rdintens==max(rdchem$rdintens))
lm.9.8.4<-lm(rdintens ~ sales + profmarg + hi.rdint, data=rdchem)
summary(lm.9.8.4)

lm.9.8.5<-lm(rdintens ~ sales + profmarg, data=rdchem,subset=(rdintens<max(rdintens)))
summary(lm.9.8.5)

# Without first and tenth firm
lm.9.8.6<-lm(rdintens ~ sales + profmarg, 
                data=rdchem,subset=(sales<max(sales) & rdintens<max(rdintens)))
summary(lm.9.8.6)
# Slighty different results

lm.9.8.7<-lm(rdintens ~ sales + profmarg + big + hi.rdint, data=rdchem)
summary(lm.9.8.7)

# Example 9.9
rdchem<-read.dta('rdchem.dta')

lm.9.9.1<-lm(lrd ~ lsales + profmarg, data=rdchem)
summary(lm.9.9.1)

# Without the largest firm
lm.9.9.2<-lm(lrd ~ lsales + profmarg, data=rdchem, subset=(lsales<max(lsales)))
summary(lm.9.9.2)

# Example 9.10
infmrt<-read.dta('infmrt.dta')

lm.9.10.1<-lm(infmort ~ lpcinc + lphysic + lpopul, data=infmrt, subset=(year==1990))
summary(lm.9.10.1)

lm.9.10.2<-lm(infmort ~ lpcinc + lphysic + lpopul, data=infmrt, subset=(year==1990 & DC==0))
summary(lm.9.10.2)

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