I would like to ask for your help concerning the following issue. In a nutshell, I would like to know, how demeaning works in a panel regression with two (separate) fixed effects.

Let us assume I have the textbook balanced panel with $N=100$ individuals $i$ and $T=20$ time periods $t$ (say, 100 firms observed over 20 years, neither does a firm enter the sample, nor does a firm leave it). I observe regressand $Y$ and the two regressors $X$ and $Z$.

To estimate a two-way-fixed effects model with both individual- and time-fixed effects, I could estimate (being only interested in coefficients $\mathbf{\beta}$)

$Y_{i,t} = \lambda^i + \lambda^t + \beta_{1} \cdot X_{i,t}+ \beta_{2}\cdot Z_{i,t}+\varepsilon_{i,t},$

where $\lambda^{m}$ is meant as a short-hand notation for $\sum_{m=1}^M \lambda_m \cdot \mathbf{I}(m \in group~ m)$, with $\mathbf{I}(.)$ being the indicator function, which takes upon the value of 1, if the expression in brackets is true and 0 else. I.e., I include a dummy-variable for every individual $i$ and time period $t$.

But for computational convenience, I would like to get rid off the dummies and estimate the model by demeaning.

However, I am stuck which means to subtract and which terms to add.

Thus, let us visit the easier example of exclusively individual fixed effects. Instead of estimating

$Y_{i,t} = \lambda^i + \alpha_{1} \cdot X_{i,t}+ \alpha_{2}\cdot Z_{i,t}+\eta_{i,t}$

I estimate

$Y_{i,t}-\bar{Y}_i = \alpha_{1} \cdot (X_{i,t}-\bar{X}_i)+ \alpha_{2} \cdot (Z_{i,t}-\bar{Z}_i) + (\eta_{i,t}-\bar{\eta}_{i}),$

where "upper-bar with index i" denotes means taken over i. E.g., for $i=1$, for each of the $T=20$ observations I have for $i=1$, I subtract the mean of $i=1$ computed over that $T=20$ observations.

My question is:

With two separate fixed effects: Which means do I subtract? What do I add back? E.g., simply additionally subtracting an $\bar{Y}_t$ for $Y$ would presumably not do the trick. Is there a formula for demeaning wich generalized to the case of integer $f>0$ fixed effects?

Yours sincerely, Sinistrum


If you use demean approach (which is theoretically right), then you have to do demean your data both cross sectionally and time series (irrespective of the order). See how it is works.

Assume following regression model:

$$y_{it} = u_i + \nu_t + \beta X_{it} + e_{it} \,\,\,\,\, i = 1, 2, \dots, n \,\,\,\,\, T = 1, 2, \dots, t \tag{1}$$

First demean cross sectionally. Mean equation is

$$\bar{y_i} = u_i + \bar{v} + \beta \bar{X_i} + \bar{e_i}\,\,\,\,\, i = 1, \dots, n \tag{2}$$ (notice, the $\bar{v}$ will be same for each cross sectional)

Subtracting (1) - (2) $$y_{it} - \bar{y_i} = \nu_t - \bar{v} + \beta (X_{it} - \bar{X_i}) + (e_{it} - \bar{e_i}) \tag{3}$$ (see there is no fixed effect in equation 3)

Now, take mean of equation 1 for each $t$, and the mean equation is, $$\bar{y}_t = \bar{u} + \nu_t + \beta \bar{X_t} + \bar{e_t} \,\,\,\,\, T = 1, 2, \dots, t\tag{4}$$

Now, subtract equation 4 from equation 3, we get: $$y_{it} - \bar{y_i} - \bar{y_t} = \beta (X_{it} - \bar{X}_i - \bar{X}_t) -(\bar{v} + \bar{u}) + (e_{it} - \bar{e_i} - \bar{e_t}) \tag{5}$$

In this way, there is no fixed effects and time effects in equation 5.

  • $\begingroup$ Thank you very much indeed If I understood correctly, after all it is just the consecutive subtraction I mentioned I thought of being too simple. I.e., demean over all $i$, demean over all $t$, subtract means from starting equation $(1)$. Thus, it would also generalize to $f$ fixed effects by repeating the procedure for all $f$ groups. $\endgroup$ – Sinistrum May 23 at 12:28
  • $\begingroup$ Yes, you are right. $\endgroup$ – Neeraj May 24 at 17:15
  • $\begingroup$ Keep in mind, the unbalanced case is trickier. $\endgroup$ – Helix123 May 24 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.