if(!require(wooldridge)) install.packages(“wooldridge”) if(!require(lmtest)) install.packages(“lmtest”) if(!require(sandwich)) install.packages(“sandwich”) if(!require(car)) install.packages(“car”)
library(wooldridge) library(lmtest) library(sandwich) library(car)
data(“lawsch85”) str(lawsch85) summary(lawsch85)
model1 <- lm(salary ~ rank + LSAT + GPA, data = lawsch85) summary(model1)
coeftest(model1, vcov = vcovHC(model1, type=“HC1”))
linearHypothesis(model1, c(“LSAT = 0”, “GPA = 0”), vcov=vcovHC(model1,type=“HC1”))
Interpretation:
rank is typically negative and
significant: better-ranked schools (lower rank number) have higher
median salaries.model2 <- lm(salary ~ rank + LSAT + GPA + clsize + faculty, data = lawsch85) summary(model2)
linearHypothesis(model2, c(“clsize = 0”, “faculty = 0”), vcov=vcovHC(model2,type=“HC1”))
Interpretation:
data(“k401ksubs”) single <- subset(k401ksubs, fsize == 1)
n_single <- nrow(single)
n_single
Interpretation: Number of single-person households is r n_single.
model3 <- lm(nettfa ~ inc + age, data = single) summary(model3)
coeftest(model3, vcov=vcovHC(model3,type=“HC1”))
Interpretation:
b2 <- coef(model3)[“age”] se_b2 <- sqrt(diag(vcovHC(model3,type=“HC1”)))[“age”] t_stat <- (b2 - 1)/se_b2 p_val <- pt(t_stat, df.residual(model3)) # one-sided lower-tail t_stat p_val
Interpretation: Reject H0 at 1% level if p-value < 0.01.
model4 <- lm(nettfa ~ inc, data = single) summary(model4)
cbind(Multiple_reg=coef(model3)[“inc”], Simple_reg=coef(model4)[“inc”])
Interpretation: