rregressionstargazer

Is it possible to separate regression statistics into multiple columns using stargazer?


I realise this might not be a very descriptive question, but I essentially want to know if this question has an answer yet.

I have a regression whose results I'd like to output in a table using stargazer, like so:

> stargazer(model1, type = "text", report = "vcsp", single.row = T)

==========================================
                   Dependent variable:    
               ---------------------------
                          enter           
------------------------------------------
male                 -0.148 (0.148)       
                        p = 0.316         
------------------------------------------
Observations               183            
Log Likelihood         -1,052.273         
==========================================
Note:          *p<0.1; **p<0.05; ***p<0.01

The output I want is this:

======================================================================
                   Dependent variable: enter  
               -------------------------------------------------------
                      coefficient            se             p-value
----------------------------------------------------------------------
male                    -0.148            (0.148)            0.316
----------------------------------------------------------------------
Observations                                183            
Log Likelihood                          -1,052.273         
======================================================================
Note:          *p<0.1; **p<0.05; ***p<0.01

Is there any way to do this using stargazer? Any help is appreciated.


Solution

  • You can collect what you need from your model output into a data.frame and print this with stargazer:

    library(stargazer)
    model<-lm(mpg~disp+factor(cyl), data=mtcars)
    stargazer(model, type="text", omit="cyl")
    
    results <- data.frame(Coefficient = summary(model)$coefficients[,1],
                          Standard_Error = summary(model)$coefficients[,2],
                          p_value = summary(model)$coefficients[,4])
    
    stargazer(results, title="Table 1: Results", summary=F, type = "text")
    
    Table 1: Results
    ===============================================
                 Coefficient Standard_Error p_value
    -----------------------------------------------
    (Intercept)    29.535        1.427         0   
    disp           -0.027        0.011       0.016 
    factor(cyl)6   -4.786        1.650       0.007 
    factor(cyl)8   -4.792        2.887       0.108 
    -----------------------------------------------