[R] NeweyWest in sandwich-package

Achim Zeileis Achim.Zeileis at uibk.ac.at
Fri Apr 18 11:22:44 CEST 2014


On Thu, 17 Apr 2014, Katharina Mersmann wrote:

> This post was nearly what I was searching for.
>
> Im actually trying to reproduce my Stata results in R and don?t overcome 
> the problem of the NeweyWest Estimators. I have quarterly PanelData
>
> In Stata i used:
>
> newey y x, lag(4) force
>
> In R this should be
>
> reg1.2<-lm(y~x)
> coeftest(reg1.2, df = Inf, vcov = NeweyWest(reg1.2, lag = 4,prewhite=0))
>
> but i get slightly different Std. Dev. and P-values.
>
> Do i use the wrong command? Or the wrong specification?

It's hard to say what is the source of the differences without a 
reproducible example. The most obvious candidate is a degrees of freedom 
adjustment, though. By default, NeweyWest() divides by n, the sample size. 
But some implementations also use division by n-k, where k is the number 
of estimated parameters. So maybe

coeftest(reg1.2, df = Inf,
   vcov = NeweyWest(reg1.2, lag = 4, prewhite = 0, adjust = TRUE))

replicates the Stata results exactly?

Note though that the literature usually recommends automatic bandwidth 
selection and prewhitening (as implemented in the defaults of NeweyWest). 
I'm not sure whether there are results for the degrees of freedom 
adjustment.


>
>
>
>
> Thanks a lot for your suggestions!
>
> Katie
>
>
>
>
>
>
>
>
>
> Achim Zeileis-4 wrote
>
>> On Sun, 27 Jun 2010, Jurica Brajkovi? wrote:
>
>>
>
>>> I want to calculate Newey West robust standard error using NeweyWest.
>
>>> Comparing the results to what I get in STATA, in order to get the same
>
>>> results in I need to specify "prewhite=0". Can someone explain what this
>
>>> prewhite command means?
>
>>
>
>> It controls whether autocorrelation in the estimating functions should be
>
>> removed/reduced by using a VAR model.
>
>>
>
>> ?NeweyWest says:
>
>>
>
>> prewhite: logical or integer. Should the estimating functions be
>
>>            prewhitened? If 'TRUE' or greater than 0 a VAR model of order
>
>>            'as.integer(prewhite)' is fitted via 'ar' with method '"ols"'
>
>>            and 'demean = FALSE'. The default is to use VAR(1)
>
>>            prewhitening.
>
>>
>
>> The "Details" section adds:  To obtain the estimator described in Newey &
>
>> West (1987), prewhitening has to be suppressed.
>
>>
>
>> References can also be found on the manual page as well as in Section 3.2
>
>> of vignette("sandwich", package = "sandwich").
>
>> Z
>
>>
>
>>>
>
>>>
>
>>> Thanks
>
>>>
>
>>>
>
>>>    [[alternative HTML version deleted]]
>
>>>
>
>>> ______________________________________________
>
>>>
>
>
>
>> R-help@
>
>
>
>>  mailing list
>
>>>  <https://stat.ethz.ch/mailman/listinfo/r-help>
> https://stat.ethz.ch/mailman/listinfo/r-help
>
>>> PLEASE do read the posting guide
>
>>>  <http://www.R-project.org/posting-guide.html>
> http://www.R-project.org/posting-guide.html
>
>>> and provide commented, minimal, self-contained, reproducible code.
>
>>>
>
>>
>
>> ______________________________________________
>
>
>
>> R-help@
>
>
>
>>  mailing list
>
>>  <https://stat.ethz.ch/mailman/listinfo/r-help>
> https://stat.ethz.ch/mailman/listinfo/r-help
>
>> PLEASE do read the posting guide
>
>>  <http://www.R-project.org/posting-guide.html>
> http://www.R-project.org/posting-guide.html
>
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
>
>
>
> 	[[alternative HTML version deleted]]
>
>




More information about the R-help mailing list