Skip to content

Instantly share code, notes, and snippets.

@kylebutts
Created May 15, 2024 16:15
Show Gist options
  • Save kylebutts/185446d878787f0028fc4b3268ca61dd to your computer and use it in GitHub Desktop.
Save kylebutts/185446d878787f0028fc4b3268ca61dd to your computer and use it in GitHub Desktop.
"Attach" vcov to fixest object
library(fixest)
library(sandwich)

est <- feols(mpg ~ hp + i(cyl) | am, mtcars, vcov = "hc1")
vcov_bs <- sandwich::vcovBS(est, R = 500)

### attach new vcov to est
est_bs <- summary(est, vcov = vcov_bs)
###

etable(est, est_bs)
#>                                 est             est_bs
#> Dependent Var.:                 mpg                mpg
#>                                                       
#> hp              -0.0442*** (0.0116) -0.0442** (0.0132)
#> cyl = 6            -3.925** (1.215)   -3.925** (1.304)
#> cyl = 8             -3.533. (1.920)     -3.533 (2.101)
#> Fixed-Effects:  ------------------- ------------------
#> am                              Yes                Yes
#> _______________ ___________________ __________________
#> S.E. type       Heteroskedast.-rob.             Custom
#> Observations                     32                 32
#> R2                          0.82488            0.82488
#> Within R2                   0.72645            0.72645
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Created on 2024-05-15 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment