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

**URL:** <https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200>\
**Category:** Statistics\
**Created:** [April 16, 2019, 12:06pm UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200 "2019-04-16T12:06:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![flxho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flxho/32/3922_2.png) [@flxho](https://discourse.julialang.org/u/flxho)\
**Post date:** [April 16, 2019, 12:06pm UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200/1 "2019-04-16T12:06:06Z")

</div>

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

```julia
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)))`?

---

<div class="post-metadata">

**Author:** ![matthieu](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@matthieu](https://discourse.julialang.org/u/matthieu)\
**Post date:** [April 16, 2019, 10:10pm UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200/2 "2019-04-16T22:10:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![flxho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flxho/32/3922_2.png) [@flxho](https://discourse.julialang.org/u/flxho)\
**Post date:** [April 17, 2019, 6:07am UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200/3 "2019-04-17T06:07:54Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![matthieu](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@matthieu](https://discourse.julialang.org/u/matthieu)\
**Post date:** [April 17, 2019, 12:27pm UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200/4 "2019-04-17T12:27:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jo-fleck](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@jo-fleck](https://discourse.julialang.org/u/jo-fleck)\
**Post date:** [September 23, 2021, 9:25pm UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200/5 "2021-09-23T21:25:12Z")

</div>

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)`]

---

<div class="post-metadata">

**Author:** ![matthieu](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@matthieu](https://discourse.julialang.org/u/matthieu)\
**Post date:** [September 23, 2021, 9:37pm UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200/6 "2021-09-23T21:37:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jo-fleck](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@jo-fleck](https://discourse.julialang.org/u/jo-fleck)\
**Post date:** [September 23, 2021, 11:12pm UTC](https://discourse.julialang.org/t/how-can-i-calculate-different-vcov-matrices-after-fixedeffectmodels-jl/23200/7 "2021-09-23T23:12:27Z")

</div>

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.)
