0

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.

Cloft X
  • 141
  • 7
  • one option is to construct it manually, then pass it to stargazer with `summary=FALSE`. That might be against the spirit of what you were going for though – Mark Jul 03 '23 at 10:09
  • the output is also awfully similar to `gtsummary`'s tables, so that is another option – Mark Jul 03 '23 at 10:12
  • 1
    The reason I am being rigid in this regard is that I am using the `add.lines` parameter in `stargazer` to add some information in my table, which I may not be able to do if I automate a table construct manually. – Cloft X Jul 03 '23 at 10:14

1 Answers1

1

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 
-----------------------------------------------
Marco
  • 2,368
  • 6
  • 22
  • 48
  • I'm accepting this as an answer because I realize my question is quite poor, that the rigid expectation of doing something in R with only a particular tool is not the right approach. – Cloft X Jul 05 '23 at 12:58
  • 1
    Thank you very much for the feedback. As others noted, `stargazer` is good, but old. `modelsummary` offers great new possibilities. Please provide minimal data in future questions. – Marco Jul 05 '23 at 12:59