Hi! I want to control for heteroscedasticity with robust standard errors.
I have read a lot about the pain of replicate the easy robust option from STATA to R to use robust standard errors. I replicated following approaches: StackExchange and Economic Theory Blog. They work but the problem I face is, if I want to print my results using the stargazer function (this prints the .tex code for Latex files).
You may be interested in the lmtest package which provides some nice functions for generating robust standard errors and returning results in the same format as lm().
library(lmtest)
library(sandwich)
lmtest::coeftest(reg1, vcov. = sandwich::vcovHC(reg1, type = 'HC1'))
Thank you @mattwarkentin , that worked!
Do you now by chance how i can add, that the observations, R2, adj. R2, Residual, Residual St.Error and the F-Statistics will also be printed?
At the moment it just the coefficients are printed:
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.54923 6.85521 -0.3719 0.710611
id 0.39634 0.12376 3.2026 0.001722 **
source 1.48164 4.20183 0.3526 0.724960
country -4.00398 4.00256 -1.0004 0.319041
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
While I'd like to have the following as well (example is from actual lm function):
Residual standard error: 17.43 on 127 degrees of freedom
Multiple R-squared: 0.09676, Adjusted R-squared: 0.07543
F-statistic: 4.535 on 3 and 127 DF, p-value: 0.00469