1

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!

TFT
  • 129
  • 10

2 Answers2

2

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)
Julian
  • 6,586
  • 2
  • 9
  • 33
1

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!

Nad Pat
  • 3,129
  • 3
  • 10
  • 20
TFT
  • 129
  • 10