'Extracting coeftest results into a data frame

I'm trying to extract model coefficients from R into a data frame that I can then combine into one large dataset with some other model results from Stata.

Using coeftest from lmtest, I tried this:

model_1_coef <- lmtest::coeftest(model1, vcov = sandwich::vcovHC) 

This seems to just create an object of class 'coeftest', and coercing it into a data frame using as.data.frame returned the error "cannot coerce class '"coeftest"' to a data.frame.

Any ideas on what to try next?



Solution 1:[1]

I had the same problem and finally used a little workaround:

model_1_coef_df <- as.data.frame(model_1_coef[,])

or, using dplyr syntax:

model_1_coef_df <- model_1_coef[,] %>% 
as_tibble() %>%
mutate(variable = rownames(model_1_coef))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hiddenllama