I have a data.table with annual returns and 2 explanatory variables for 25 different equity portfolios. I would like to estimate the same lm
model for each of 25 portfolios where the standard errors are NeweyWest-corrected. So far, I'm runnning the model on each portfolio with group_by
from dplyr
and then correct the standard errors with coeftest
from the lmtest
package plus NeweyWest
from the sandwich
package, summarized with tidy
from the broom
package:
library(dplyr)
library(broom)
library(lmtest)
library(sandwich)
regressions <- data %>%
group_by(Portfolio) %>%
do({fit = lm(Portfolio_return ~ x1 + x2, data = .)
tidy(coeftest(fit, vcov. = NeweyWest(fit, prewhite = FALSE)))
})
The questions I have:
The code gives me the coefficients plus p-values, but how do I get all the other summary stats like r2, F-test etc for all the models after the NeweyWest adjustment? I like
tidy
,glance
andaugment
from from thebroom
package but when I runregressions %>% glance(fit)
I get fatal error and R crashes.How can I summarize all the stats (like coefficients, p-values, R2) for all 25 models in one
data.table
ordata.frame
?
Thanks a lot!