3

I would like to display the t value and p value from my regression output using the stargazer package. So far, I've found ways to show one or the other. I did find something online that displays both; however, it omits the coefficient names. Is there a function or something else that will enable me to show all three?

library(stargazer)
data("cars")
model <- lm(hp ~ wt, mtcars)
stargazer(model, type='text',report = "csp")

Shows p-values, but no beta coefficient names table output

shows beta coefficient names, but no pvalues. I would like to keep all three: coefficient names, t stat, and p-value

output not including p-value

edit

removed a function used on the website that I did not use

zephryl
  • 14,633
  • 3
  • 11
  • 30
bandcar
  • 649
  • 4
  • 11

1 Answers1

3

You could mention it by using t in the report argument:

a character string containing only elements of "v", "c", "s","t", "p", "" that determines whether, and in which order, variable names ("v"), coefficients ("c"), standard errors/confidence intervals ("s"), test statistics ("t") and p-values ("p") should be reported in regression tables. If one of the aforementioned letters is followed by an asterisk (""), significance stars will be reported next to the corresponding statistic.

Here is a reproducible example:

library(stargazer)
data("cars")
model <- lm(hp ~ wt, mtcars)
stargazer(model, type='text', report = "vcstp")
#> 
#> ===============================================
#>                         Dependent variable:    
#>                     ---------------------------
#>                                 hp             
#> -----------------------------------------------
#> wt                            46.160           
#>                               (9.625)          
#>                              t = 4.796         
#>                             p = 0.00005        
#>                                                
#> Constant                      -1.821           
#>                              (32.325)          
#>                             t = -0.056         
#>                              p = 0.956         
#>                                                
#> -----------------------------------------------
#> Observations                    32             
#> R2                             0.434           
#> Adjusted R2                    0.415           
#> Residual Std. Error      52.437 (df = 30)      
#> F Statistic           22.999*** (df = 1; 30)   
#> ===============================================
#> Note:               *p<0.1; **p<0.05; ***p<0.01

Created on 2022-11-12 with reprex v2.0.2

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • Hi! I would like it to keep the beta estimates for wt and the constant. I'll post a photo of what it should look like but with p-values. EDIT: And the names of the independent variables – bandcar Nov 12 '22 at 18:33
  • @bandcar, Please check updated code! You should include v in the report argument for variable names. – Quinten Nov 12 '22 at 18:42
  • Hi @Quinten! Is it possible to have p-values in the parentheses instead of being denoted as "p = ...." without having to change them manually? I want to show only the coefficient, significance stars and p values in parentheses. Thanks – fsure Aug 02 '23 at 07:06
  • Hi @fsure, Unfortunately, I can’t help you right now. I am able to help you in a couple of days. Otherwise you could ask this as a new question? Thanks – Quinten Aug 02 '23 at 12:15