Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to show t stat and p value with coefficient with stargazer

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

output not including p-value

edit

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading