How to update summary when using NeweyWest?

Matt Bannert picture Matt Bannert · Jul 14, 2011 · Viewed 8.6k times · Source

I am using NeweyWest standard errors to correct my lm() / dynlm() output. E.g.:

fit1<-dynlm(depvar~covariate1+covariate2)
coeftest(fit1,vcov=NeweyWest)

Coefficients are displayed the way I´d like to, but unfortunately I loose all the regression output information like R squared, F-Test etc. that is displayed by summary. So I wonder how I can display robust se and all the other stuff in the same summary output.

Is there a way to either get everything in one call or to overwrite the 'old' estimates? I bet I just missed something badly, but that is really relevant when sweaving the output.

Test example, taken from ?dynlm.

require(dynlm)
require(sandwich)
data("UKDriverDeaths", package = "datasets")
uk <- log10(UKDriverDeaths)
dfm <- dynlm(uk ~ L(uk, 1) + L(uk, 12))

#shows R-squared, etc.
summary(dfm)

#no such information
coeftest(dfm, vcov = NeweyWest)

btw.: same applies for vcovHC

Answer

Richard Herron picture Richard Herron · Jul 14, 2011

coefficients is just a matrix in the lm (or dynlm) summary object, so all you need to do is unclass the coeftest() output.

library(dynlm)
library(sandwich)
library(lmtest)
temp.lm <- dynlm(runif(100) ~ rnorm(100))
temp.summ <- summary(temp.lm)
temp.summ$coefficients <- unclass(coeftest(temp.lm, vcov. = NeweyWest))