The commarobust
pacakge does two things:
-
With the
commarobust()
function, you can easily estimate robust standard errors on your model objects. Almost as easy as Stata! -
You can easily prepare your standard errors for inclusion in a stargazer table with
makerobustseslist()
. I'm open to better names for this function.
Install from Github!
install.packages("devtools")
devtools::install_github("acoppock/commarobust")
Check it out:
library(commarobust)
library(randomizr) # For easy random assignments
Z <- complete_ra(100)
Y <- 5 + 10*Z + rnorm(100)
fit <- lm(Y ~ Z)
commarobust(fit)
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 4.797376 0.1349279 35.55510 8.201968e-58
#> Z 10.290971 0.2028367 50.73526 3.696001e-72
And now in Stargazer. See how the intercept doesn't have stars even though the control group mean is statistically significantly larger than zero? Nice!
library(stargazer)
Z_1 <- complete_ra(100)
Y_1 <- 10 + 5*Z_1 + rnorm(100)
Z_2 <- complete_ra(100)
Y_2 <- 10 + 2*Z_2 + rnorm(100)
fit_1 <- lm(Y_1 ~ Z_1)
fit_2 <- lm(Y_2 ~ Z_2)
stargazer(fit_1, fit_2,
se = makerobustseslist(fit_1, fit_2),
p = makerobustpslist(fit_1, fit_2), type = "html")
Dependent variable: | ||
Y\_1 | Y\_2 | |
(1) | (2) | |
Z\_1 | 5.407\*\*\* | |
(0.206) | ||
Z\_2 | 1.899\*\*\* | |
(0.207) | ||
Constant | 9.767 | 10.039 |
(0.150) | (0.151) | |
Observations | 100 | 100 |
R2 | 0.875 | 0.463 |
Adjusted R2 | 0.874 | 0.458 |
Residual Std. Error (df = 98) | 1.030 | 1.033 |
F Statistic (df = 1; 98) | 688.468\*\*\* | 84.532\*\*\* |
Note: | *p<0.1; **p<0.05; ***p<0.01 |