Get coefficients estimated by maximum likelihood into a stargazer table

后端 未结 3 1448
天涯浪人
天涯浪人 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条回答
  •  猫巷女王i
    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)

提交回复
热议问题