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
#> Warning: package 'randomizr' was built under R version 3.3.2
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.779192 0.1677829 28.48439 3.322561e-49
#> Z 10.264458 0.2212777 46.38723 1.698068e-68
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 | 4.723*** | |
(0.175) | ||
Z_2 | 2.341*** | |
(0.174) | ||
Constant | 10.173 | 9.813 |
(0.111) | (0.112) | |
Observations | 100 | 100 |
R2 | 0.882 | 0.648 |
Adjusted R2 | 0.881 | 0.644 |
Residual Std. Error (df = 98) | 0.873 | 0.871 |
F Statistic (df = 1; 98) | 731.660*** | 180.343*** |
Note: | p<0.1; p<0.05; p<0.01 |