Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User provided vcov for multiple models #532

Open
sousaru opened this issue Dec 16, 2024 · 1 comment
Open

User provided vcov for multiple models #532

sousaru opened this issue Dec 16, 2024 · 1 comment

Comments

@sousaru
Copy link

sousaru commented Dec 16, 2024

From the vignette I cannot find a way to provide user estimated vcov matrices for multiple models - included as a list. I would assume that providing a list of matrices should work but it throws an error. Is there an alternative to use user provided vcovs for multiple models or is this feature not implemented?

Thanks a lot!

@kylebutts
Copy link
Contributor

Here is how you can do this in user-space. Though, passing a list of vcovs does seem like a reasonable thing to be able to do.

library(fixest)
est <- feols(c(hp, mpg) ~ i(cyl), mtcars)
est
#> Standard-errors: IID 
#> Dep. var.: hp
#>             Estimate Std. Error t value   Pr(>|t|)    
#> (Intercept)  82.6364    11.4328 7.22799 5.8642e-08 ***
#> cyl::6       39.6494    18.3333 2.16269 3.8949e-02 *  
#> cyl::8      126.5779    15.2778 8.28511 3.9151e-09 ***
#> ---
#> Dep. var.: mpg
#>              Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept)  26.66364   0.971801 27.43735  < 2.2e-16 ***
#> cyl::6       -6.92078   1.558348 -4.44110 1.1947e-04 ***
#> cyl::8      -11.56364   1.298623 -8.90453 8.5682e-10 ***
custom_vcovs <- list(
  2 * vcov(est[[1]], "HC1"),
  2 * vcov(est[[2]], "HC1")
)

for (i in 1:length(est)) { 
  est[[i]] <- summary(est[[i]], .vcov = custom_vcovs[[i]])
}

est
#> Standard-errors: Custom 
#> Dep. var.: hp
#>             Estimate Std. Error t value   Pr(>|t|)    
#> (Intercept)  82.6364    8.94049 9.24293 3.8165e-10 ***
#> cyl::6       39.6494   15.45909 2.56479 1.5764e-02 *  
#> cyl::8      126.5779   21.45486 5.89973 2.0979e-06 ***
#> ---
#> Dep. var.: mpg
#>              Estimate Std. Error  t value   Pr(>|t|)    
#> (Intercept)  26.66364    1.92601 13.84399 2.6085e-14 ***
#> cyl::6       -6.92078    2.06893 -3.34510 2.2843e-03 ** 
#> cyl::8      -11.56364    2.16075 -5.35168 9.5467e-06 ***

Created on 2025-02-19 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants