### Week 6: Problems with Errors ### Code from class ## load "dailcorrected.dta" from Benoit and Marsh AJPS 2008 library(lmtest) dail <- read.dta("dailcorrected.dta") ## run the basic model m1 <- lm(votes1st ~ spend_total*incumb, data=dail) # inspect for heteroskedasticity - residuals v. fitted plot plot(m1, which=1) ## tests for heteroskedasticity library(lmtest) gqtest(m1) # Goldfeld-Quandt test bptest(m1) # Breusch-Pagan test ## White's heteroskedasticity-robust SEs library(car) coef(summary(m1)) Var(m1) sqrt(diag(Var(m1))) vc.hccm <- hccm(m1) vc.hccm sqrt(diag(vc.hccm))