How can I calculate different vcov matrices after FixedEffectModels.jl?

Imagine that for some model we calculate standard errors clustered on one dimension, e.g. state:

using DataFrames, RDatasets, FixedEffectModels
df = dataset("plm", "Cigar")
df[:StateCategorical] =  categorical(df[:State])
df[:YearCategorical] =  categorical(df[:Year])
reg(df, @model(Sales ~ NDI, fe = StateCategorical + YearCategorical, weights = Pop, vcov = cluster(StateCategorical)))

Now I would like to calculate a second set of standard errors, e.g. vcov = cluster( StateCategorical + YearCategorical).
How can we calculate these without having to run the costly
reg(df, @model(Sales ~ NDI, fe = StateCategorical + YearCategorical, weights = Pop, vcov = cluster( StateCategorical + YearCategorical)))?

1 Like

You can’t. The reason is that it is not clear what to do if there are observations with a missing cluster variable. You would need to reestimate the model on this new sample anyway.

Out of curiosity, is your estimation really taking a lot of time?

I understand. In my case there are no missing cluster variables. Estimation takes about 5 hours on a cluster for a single regression, but I need to run it for approximately 30 different specifications…

wow… really? Can you open an issue on Github? I did not realize some people were doing such costly computations.

1 Like

In the same example, how can I use robust errors clustered at the state level?

I managed to use either robust or clustered at a time but not jointly.

[In Stata, the syntax is , robust cluster(StateCategorical) ]

Clustered std are always robust. I don’t think adding robust to cluster(StateCategorical) would change anything in Stata.

1 Like

Ah ofc, you’re right. Thanks for the reminder!

(I just checked and it doesn’t make a difference indeed. Wondering why Stata allows both options simultaneously - the FixedEffectModels.jl approach is definitely clearer.)