# st: Fixed effects and clustering

 From Alice To statalist@hsphsun2.harvard.edu Subject st: Fixed effects and clustering Date Thu, 19 Mar 2009 10:32:50 +0000 (GMT)

```Dear Statalist,

I want to estimate a regression with several sets of fixed effects, but the regression is far too big to be estimated on my laptop (because there are far too many fixed effects and Stata runs out of memory). So instead I have decided to remove manually the fixed effects.

Assume for simplicity that I want to remove two sets of fixed effects, fe1 and fe2 (in reality I have four sets of fixed effects), so to regress y and x I do the following:

* Fixed effects fe1

sort fe1

by fe1: egen double ya = mean(y)

by fe1: egen double xa = mean(x)

* Fixed effects fe2

sort fe2

by fe2: egen double yb = mean(y)

by fe2: egen double xb = mean(x)

* Overall mean

egen double yy = mean(y)

egen double xx = mean(x)

Then given that I have 2 sets of fixed effects I then generate a new variable for y and one for x as follows:

g double Y = y - ya - yb + yy

g double X = x - xa - xb + xx

Then if I just regress Y on X by OLS, I need to adjust the standard errors for the new degrees of freedom. Assuming that I have df_fe1 and df_fe2 fixed effects for both fe1 and fe2, then:

reg Y X

mat b = e(b)

So then I can adjust standard errors as follows

eret post b V

ereturn display

The results I obtain are then the same as if I estimated

xi: reg y x i.fe1 i.fe2

Now my problem is that I further want to cluster my standard errors in the OLS regression above so the equation I would need to estimate is

xi: reg y x i.fe1 i.fe2, cluster(C)

Does anyone know how I should then adjust my standard errors when removing my means manually? The adjustment above assumes that there is no clustering.

I found in Stata manual the expression for the new var-cov matrix with clustering but I do not know how to adjust it for the new number od degrees of freedom?

Many thanks!

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```