Get coefficients estimated by maximum likelihood into a stargazer table

后端 未结 3 1444
天涯浪人
天涯浪人 2021-02-02 05:06

Stargazer produces very nice latex tables for lm (and other) objects. Suppose I\'ve fit a model by maximum likelihood. I\'d like stargazer to produce a lm-like table for my es

相关标签:
3条回答
  • 2021-02-02 05:19

    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$par
    model2.lm$fitted.values <- model2$par["const"] + model2$par["beta"]*df$x
    model2.lm$residuals <- df$y - model2.lm$fitted.values
    stargazer(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)

    0 讨论(0)
  • 2021-02-02 05:25

    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="")
    
    0 讨论(0)
  • 2021-02-02 05:39

    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))
    
    0 讨论(0)
提交回复
热议问题