0
votes

I have a data frame with 126 columns and want to run linear regressions over all columns. I did this with the lapply() function:

my_lms <- lapply(1:126, function(x) df[,x] ~ df$x1))

Again with the lapply() function I get the summary statistics:

lapply(my_lms, summary)

My question is how to get the same summary statistics using Newey-West errors?

I tried:

coeftest(my_lms, vcov. = NeweyWest)

but this gives me the error message:
Error in UseMethod("estfun") : no applicable method for 'estfun' applied to an object of class "list"

Thanks

1
lapply(my_lms, coeftest, vcov. = NeweyWest) ?Stéphane Laurent

1 Answers

0
votes

Stephane is exactly right, but I thought writing an explanatio nmight be needed. Your my_lms object is a list with each item in the list being a nested-object with the proper class for the coeftest function. However, the coeftest function doesn't have the machinery for serial extraction for the "master list". So you need to use lapply again with the coeftest being the functional argument. Extra parameters can be passed to coeftest using lappy's "triple dots" mechanism: Quoted material from the ?lapply page

Usage

lapply(X, FUN, ...)

lapply(my_lms, coeftest, vcov. = NeweyWest)