a_todd12
a_todd12

Reputation: 550

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?

Upvotes: 1

Views: 2272

Answers (2)

fahmy
fahmy

Reputation: 3672

lmtest::coeftest(model1, vcov = sandwich::vcovHC)[,] %>% 
    as.data.frame() %>% 
    tibble::rownames_to_column(var = "term")

Upvotes: 0

hiddenllama
hiddenllama

Reputation: 66

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))

Upvotes: 5

Related Questions