2

I like Stargazer quite a bit but am running into some issues trying to report standard errors and confidence intervals all in a single table.

Consider this simple regression as a reproducible example:

set.seed(04152020)
x <- rnorm(100)
y <- 2*x + rnorm(100)
m1 <- lm(y~x)

I can report standard errors and confidence intervals in two separate tables no problem using the ci option.

library(stargazer)
# standard errors
stargazer(m1, type = "text")
# confidence intervals
stargazer(m1, ci = FALSE, type = "text")

A workaround to get them into a single table is to "report" the model twice, but then the coefficients are repeated unnecessarily. For example, the following code:

stargazer(list(m1, m1),
          ci = c(FALSE, TRUE),
          type = "text")

Produces:

==========================================================
                                  Dependent variable:     
                              ----------------------------
                                           y              
                                  (1)           (2)       
----------------------------------------------------------
x                              1.981***       1.981***    
                                (0.110)    (1.766, 2.196) 
                                                          
Constant                       -0.218**       -0.218**    
                                (0.104)   (-0.421, -0.014)
                                                          
----------------------------------------------------------
Observations                      100           100       
R2                               0.769         0.769      
Adjusted R2                      0.766         0.766      
Residual Std. Error (df = 98)    1.032         1.032      
F Statistic (df = 1; 98)      325.893***     325.893***   
==========================================================
Note:                          *p<0.1; **p<0.05; ***p<0.01

Is there a way to put both standard errors and confidence intervals into a single column automatically, like you can do with p-values? E.g. this code:

stargazer(m1,
          ci = c(FALSE, TRUE),
          report = ('vcsp'),
          type = "text")

Produces exactly what I want, but with p-values, and the documentation for the option that allows for it—report—seems to only allow the choice for p-values, as indicated by this question and answer.

===============================================
                        Dependent variable:    
                    ---------------------------
                                 y             
-----------------------------------------------
x                              1.981           
                              (0.110)          
                             p = 0.000         
                                               
Constant                      -0.218           
                              (0.104)          
                             p = 0.039         
                                               
-----------------------------------------------
Observations                    100            
R2                             0.769           
Adjusted R2                    0.766           
Residual Std. Error       1.032 (df = 98)      
F Statistic           325.893*** (df = 1; 98)  
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01
Julian
  • 451
  • 5
  • 14
  • 1
    Note that you shouldn’t use ‘stargazer’, because [‘stargazer’ is an utterly atrocious package](https://www.reddit.com/r/rstats/comments/6o9v9h/whats_your_favorite_relatively_obscure_r_package/dkgw9q1/). Use ‘[modelsummary](https://cran.r-project.org/package=modelsummary)’ or ‘[texreg](https://cran.r-project.org/package=texreg)’ instead, or *literally anything else*. – Konrad Rudolph Apr 15 '21 at 17:16
  • 1
    Yeah... I've been finding it increasingly frustrating to use recently, though it did help initially. – Julian Apr 15 '21 at 17:38

1 Answers1

3

I don't know how to do this in stargazer, but you can easily achieve the desired result with the modelsummary package. (Disclaimer: I am the author.) The

library(modelsummary)

set.seed(04152020)
x <- rnorm(100)
y <- 2*x + rnorm(100)
m1 <- lm(y~x)

modelsummary(m1, statistic = c("std.error", "conf.int"))

enter image description here

You can also do crazy things like this, as described on the website:

modelsummary(models, gof_omit = ".*",
             statistic = c("conf.int",
                           "s.e. = {std.error}", 
                           "t = {statistic}",
                           "p = {p.value}"))

enter image description here

Vincent
  • 15,809
  • 7
  • 37
  • 39