newey-west different than R? #1655

jseabold opened this Issue May 3, 2014 · 4 comments


None yet

3 participants

jseabold commented May 3, 2014

I haven't looked at (or thought about) anything but comparing the answers.


I didn't compare with R, only with Stata for the unit tests

new = results.get_robustcov_results(cov_type='HAC',maxlags=1, use_correction=True, use_t=True)
replicates the pandas results (except we have alpha=0.1 by default for confint)

I don't have any idea about the difference to R, I never checked it. IIRC, I never tried to figure out how to get sandwiches in R. Difference to R in HAC bse of the constant is relatively large.
Also I've never seen a special treatment of the constant in any HAC paper.

Unit tests are mostly against Stata.

Unit tests for hac against Gretl use
cov_hac = sw.cov_hac_simple(res, nlags=4, use_correction=False)
at decimal=5

kdiether commented May 4, 2014

It's the same; I went and checked (not that I know R at all); R has what I would consider a strange default here. It looks like you need to pass the following to get the same as statsmodels: prewhite=FALSE


a <- matrix(c(1,3,5,7,4,5,6,4,7,8,9))
b <- matrix(c(3,5,6,2,4,6,7,8,7,8,9))

temp.lm = lm(a ~ b)

temp.summ <- summary(temp.lm)
temp.summ$coefficients <- unclass(coeftest(temp.lm, 
               vcov. = NeweyWest(temp.lm,lag=1,prewhite=FALSE)))

print (temp.summ$coefficients)


             Estimate Std. Error   t value  Pr(>|t|)
(Intercept) 2.0576208  2.6605060 0.7733945 0.4591196
b           0.5594796  0.4007965 1.3959193 0.1962142
[1] "t test of coefficients"

@kdiether Thanks for finding this

Good to know, prewhitening and recoloring is not yet available in statsmodels
Also I haven't looked closely enough at optimal window length selection to start implementing it.

What the defaults for the options for various sandwich robust standard errors should be is still a bit open.


closing this, since there is no difference given the right options.

Defaults for the various sandwiches, robust covariances are still a bit open for rethinking.
But even Stata across functions and across user supplied functions is not always consistent. Additionally, the best choice often depends on the application and the data.

@josef-pkt josef-pkt closed this May 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment