10

When using the stargazer package, I want to change the value that appears in parentheses under the coefficients. By default, the package will output the standard errors.

How can I include the actual p-values in parentheses?

1
  • There are some choices that require that you define the data columns being used and the number of models in your table. It's not going to be very helpful to have no example to work with.
    – IRTFM
    Jul 3, 2014 at 5:04

2 Answers 2

11

As mentioned in Stargazer Omit test statistics, since version 5.0 stargazer has included the report argument that allows users to choose which statistics to report. So to display p-values instead of SEs you would do this:

require(stargazer)
linear.1 <- lm(rating ~ complaints + privileges + learning 
                        + raises + critical, data=attitude)
## put in the p-values rather than the se's
stargazer(linear.1, type="text", report=('vc*p'))

Which will output:

> stargazer(linear.1,  type="text", report=('vc*p'))

========================================
                 Dependent variable:    
             ---------------------------
                       rating           
----------------------------------------
complaints            0.692***          
                     p = 0.0002         

privileges             -0.104           
                      p = 0.450         

learning                0.249           
                      p = 0.132         

raises                 -0.033           
                      p = 0.870         

critical                0.015           
                      p = 0.918         

Constant               11.010           
                      p = 0.357         

----------------------------------------
Observations             30             
R2                      0.715           
Adjusted R2             0.656           
F Statistic           12.060***         
========================================
Note:        *p<0.1; **p<0.05; ***p<0.01

This approach is safer than using the se argument, and doesn't mess the significance stars.

See also:

2
  • 3
    This question is not answered: can I display these p-values in parantheses? "p = " is unusual for journals.
    – Jakob
    Dec 17, 2016 at 14:44
  • 2
    This is likely a feature request for @Marek. You can manually replace SEs with p-values as shown in Unprecise p-values in Stargazer, but you have to be very careful with t.auto and p.auto arguments...
    – landroni
    Feb 9, 2017 at 11:02
0

There is no easy way (unless one of the style options addresses) this. But you can replace the standard errors with p-values and hard-code the p-values so that the correct number of stars appears as below.

library(stargazer)
#> 
#> Please cite as:
#>  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
#>  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer

models <- list()
models[[1]] <- lm(mpg ~ cyl + disp, data = mtcars)
models[[2]] <- lm(mpg ~ cyl + disp + wt, data = mtcars)

get_ts <- function(fm) {
  summary(fm)$coefficients[,3]
}

get_pvals <- function(fm) {
  summary(fm)$coefficients[,4]
}

ts <- lapply(models, get_ts)
pvals <- lapply(models, get_pvals)

stargazer(models, type = "text", report=('vc*s'), se = pvals, p = pvals)
#> 
#> =================================================================
#>                                  Dependent variable:             
#>                     ---------------------------------------------
#>                                          mpg                     
#>                              (1)                    (2)          
#> -----------------------------------------------------------------
#> cyl                        -1.587**              -1.785***       
#>                            (0.034)                (0.007)        
#>                                                                  
#> disp                       -0.021*                 0.007         
#>                            (0.054)                (0.533)        
#>                                                                  
#> wt                                               -3.636***       
#>                                                   (0.002)        
#>                                                                  
#> Constant                  34.661***              41.108***       
#>                            (0.000)                (0.000)        
#>                                                                  
#> -----------------------------------------------------------------
#> Observations                  32                     32          
#> R2                          0.760                  0.833         
#> Adjusted R2                 0.743                  0.815         
#> Residual Std. Error    3.055 (df = 29)        2.595 (df = 28)    
#> F Statistic         45.808*** (df = 2; 29) 46.424*** (df = 3; 28)
#> =================================================================
#> Note:                                 *p<0.1; **p<0.05; ***p<0.01

Created on 2021-05-11 by the reprex package (v2.0.0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.