I'm looping trough several regressions and aim to have a final result with different models, their respective coefficients and statistics, and some general results, as adjusted r squared, AIC and etc. This looping is done considering some subgroups in the database.
As I am using the plm to estimate the results, the broom package produce some nice results to package everything in a neat database. However, their options are kind of limiting. Or do you get the coefficients and their statistics (using tidy - provide p-values, t-statistics etc), or you get the overal model statistics (using glance - provide R-squared, adjusted R-squared, AIC etc).
-Is there a way to have both data without recalculating the regression?
I know I can merge the final result, but this would involve double calculation of each regression, and this is computationally costly. I know that the end result would repeat the aggregated statistics for each line of the coefficients, but I don't mind.
-Also see that my code kind of repeat the estimations of each regression to provide robust estimations, does anyone know a workaround for this?
A MWE follows:
library(dplyr)
library(broom)
library(plm)
library(lmtest)
library(magrittr)
data("Grunfeld")
#To generate coefficients by model
reg<- mutate(Grunfeld,
group = ifelse(firm<6,1,2)) %>%
group_by(., group) %>%
do(
tidy(
coeftest(plm(as.formula(inv ~ value + capital)
,data= .
,model = "pooling"
)
,vcov.= vcovHC(plm(as.formula(inv ~ value + capital)
,data= .
,model = "pooling"
)
,method= "arellano"
)
)
)
)
#To generate r-squared by model
reg<- mutate(Grunfeld,
group = ifelse(firm<6,1,2)) %>%
group_by(., group) %>%
do(
glance(
plm(as.formula(inv ~ value + capital)
,data= .
,model = "pooling"
)
)
)