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