[R] Problem with coeftest using Newey West estimator

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Mon Dec 14 12:42:23 CET 2009



On Mon, 14 Dec 2009, Bender, Marina wrote:

>
> Hi,
> As I didn't get a response last week, I try it again.
>
> I want to calculate the t- and p-values for a linear model using the Newey West estimator.
> I tried this Code and it usually worked just fine:
>
>> oberlm <- lm(DYH ~ BIP + Infl + EOil, data=HU_H)
>> coeftest(oberlm, NeweyWest(oberlm, lag=2))
>
> t test of coefficients:
>
>              Estimate Std. Error  t value Pr(>|t|)
> (Intercept)  0.1509950  0.0743832   2.0300 0.179486
> BIP         -5.5131683  1.2536813  -4.3976 0.048016 *
> Infl        -0.0623530  0.0036215 -17.2175 0.003356 **
> EOil         8.6762170  0.0853216 101.6884 9.67e-05 ***
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
>
>
> But then I got an error and I don't understand what it means or even why it occurs now:
>
>> oberlm <- lm(DYI ~ BIP + BrInv_bw + EOil, data=HU_I)
>> coeftest(oberlm, NeweyWest(oberlm, lag=2))
> Fehler in if ((dimension < 1) | (dimension > n)) stop("wrong embedding dimension") :
>  Argument hat L?nge 0
> Zus?tzlich: Warning message:
> In log(det(varE[[m - order.min + 1]])) : NaNs wurden erzeugt
>
> Can anyone understand there the problem is?

No, the information above is not enough to replicate the problem. I tried:

## packages
library("sandwich")
library("lmtest")

## artificial data
set.seed(123)
HU_I <- as.data.frame(matrix(rnorm(40), ncol = 4))
colnames(HU_I) <- c("DYI", "BIP", "BrInv_bw", "EOil")

## fit + test
oberlm <- lm(DYI ~ BIP + BrInv_bw + EOil, data=HU_I)
coeftest(oberlm, NeweyWest(oberlm, lag=2))

So clearly there is something going on on your side that is non-standard 
in some way, e.g., HU_I or one of its columns might be of a non-standard 
class, there might be too few observations or something else. I don't 
know, I haven't seen the error above.

Look at the posting guide which asks you to provide a small reproducible 
example. Trying to find one, often helps you to get closer to the source 
of the problem. traceback() might also help you to get a (partial) 
solution.

Best,
Z

> Best,
> Marina
>
>
>
>
>
>
> 	[[alternative HTML version deleted]]
>
>




More information about the R-help mailing list