I calculated robust standard errors after running a regression with lm() function.
# robust standard errors
cov2I <- vcovHC(ols2I, type = "HC1")
robust_se2I <- sqrt(diag(cov2I))
print(robust_se2I)
I would like to extract the second value out of the resulting matrix and save it under a new variable. I've tried the following code but it didn't work.
stderrorols2I <- (summary(robust_se2I))[2]
Thanks for your help!
CodePudding user response:
This is how you could add RSE manually to your summary output. Alternativly, you could have a look at coeftest()
library(sandwich)
mod1 <- lm(mpg ~ cyl disp, data = mtcars)
# robust standard errors
cov2I <- vcovHC(mod1, type = "HC1")
robust_se2I <- sqrt(diag(cov2I))
mod1 %>%
broom::tidy() %>%
mutate(rse = robust_se2I)
CodePudding user response:
I found the answer to my question.
To save the specific robust standard error I should have coded the following:
stderrorols2I <- (robust_se2I)[2]
Now it's working perfectly. Thanks anyway for your quick feedback!