I have a data frame with 30 columns and want to run linear regressions over all columns. I did this with the lapply() function:
my_lms <- lapply(1:30, function(x) lm(ts[,x] ~ v, data = ts))
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:
lapply(my_lms, coeftest, vcov. = NeweyWest)
But this gives me the error message: Error in if (ncol(x) == 1) { : Argument has length 0
Thanks
reproducible example: ts is a time series with index prices and a dummy variable for summer/winter month (the original dataset contains 30 indices and I want to do a linear regression for every index on the dummy variable)
library(zoo)
library(lmtest)
library(sandwich)
ts <- structure(c(4.29528246942341, 6.74996509842245, 3.17792454063952,
-1.28018252107232, 3.49874815433011, -2.80982508373651, 3.47182334545917,
5.95818170603837, -0.704348332266147, 1.61214679329347, 9.13286793976806,
-0.43878198350602, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1),
index = structure(c(604627200,607305600, 609724800, 612576000, 615168000,
617846400, 620524800, 623030400, 625795200, 628387200, 630892800, 633744000),
tzone = "UTC", tclass = "Date"), class = c("xts", "zoo"), .indexCLASS = "Date", .indexTZ = "UTC",
tclass = "Date", tzone = "UTC", .Dim = c(12L, 2L), .Dimnames = list(NULL, c("S.P.GSCI.Commodity.Total.Return", "dum")))
reg <- lapply(1:1, function(x) lm(ts[,x] ~ dum, data = ts))
sum <- lapply(reg, summary)
test <- lapply(reg, coeftest, vcov. = NeweyWest)
sandwich_2.5-0
,lmtest_0.9-36
, andzoo_1.8-3
- MrFlick