lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
362 stars 59 forks source link

Can fixest auto-Inverse-Variance weight the FE estimate? #368

Open giuliogcantone opened 1 year ago

giuliogcantone commented 1 year ago
set.seed(1018)
tibble(X = rnorm(1000),
       Y = X + rnorm(1000),
       G = sample(c("A","B"),1000,replace=T)
) %>% fixest::feols(data = .,
            fml = Y ~ X | G,
            se =  "hetero",
            weights = ???) %>%
  tidy %>%
  mutate(across(where(is.numeric),round,3))

Is there a way to instruct fixest to do this:

or any result of the estimate for X that is coherent with IVW?

giuliogcantone commented 1 year ago

UPDATE:

Someone suggested me this code:

nlme::gls(
model = Y ~ X + G - 1,
weights=varIdent(form = ~ 1 | G),
data = .)

I cannot evaluate gls() because I never worked with GLS before. What I noticed is that nlme::gls() accept a costructor function varIdent() as weights, so my guess is if fixest do the same, and which one should be the function.