Get coefficients estimated by maximum likelihood into a stargazer table Get coefficients estimated by maximum likelihood into a stargazer table r r

Get coefficients estimated by maximum likelihood into a stargazer table


I was just having this problem and overcame this through the use of the coef se, and omit functions within stargazer... e.g.

stargazer(regressions, ...                     coef = list(... list of coefs...),                     se = list(... list of standard errors...),                     omit = c(sequence),                     covariate.labels = c("new names"),                     dep.var.labels.include = FALSE,                     notes.append=FALSE), file="")


You need to first instantiate a dummy lm object, then dress it up:

#...model2.lm = lm(y ~ ., data.frame(y=runif(5), beta=runif(5), scale=runif(5), degrees.freedom=runif(5)))model2.lm$coefficients <- model2$parmodel2.lm$fitted.values <- model2$par["const"] + model2$par["beta"]*df$xmodel2.lm$residuals <- df$y - model2.lm$fitted.valuesstargazer(model2.lm, se = list(model2.coefs$se), summary=FALSE, type='text')# ===============================================#                         Dependent variable:    #                     ---------------------------#                                  y             # -----------------------------------------------# const                        10.127***         #                               (0.680)          #                                                # beta                         1.995***          #                               (0.024)          #                                                # scale                        3.836***          #                               (0.393)          #                                                # degrees.freedom              3.682***          #                               (1.187)          #                                                # -----------------------------------------------# Observations                    200            # R2                             0.965           # Adjusted R2                    0.858           # Residual Std. Error       75.581 (df = 1)      # F Statistic              9.076 (df = 3; 1)     # ===============================================# Note:               *p<0.1; **p<0.05; ***p<0.01

(and then of course make sure the remaining summary stats are correct)


I don't know how committed you are to using stargazer, but you can try using the broom and the xtable packages, the problem is that it won't give you the standard errors for the optim model

library(broom)library(xtable)xtable(tidy(model1))xtable(tidy(model2))