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?
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?
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:
t.auto
and p.auto
arguments... –
Astonied 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)
© 2022 - 2024 — McMap. All rights reserved.