Tutorials › Econometrics (Graduate) › Deriving the Fixed-Effects Within Estimator

Fixed and Random Effects · Tutorial 253 of 952

Deriving the Fixed-Effects Within Estimator

Learn how within-unit demeaning removes fixed heterogeneity, produces the fixed-effects slope estimate, and supports consistency under clear panel-data conditions.

Intermediate 10 min read

What You'll Learn

  • Derive time demeaning from the unit-intercept panel model
  • Express the within estimator as a sample-moment formula
  • Work through scalar and multiple-regressor calculations
  • State the conditions that make the within estimator consistent
  • Distinguish fixed unit heterogeneity from time-varying confounding
  • Recognize why between-unit variation alone cannot identify a within slope

Why Remove Unit-Specific Intercepts?

In a panel, the same unit is observed in multiple periods. A unit may have persistent characteristics—such as baseline productivity or long-run health—that affect its outcome but are not recorded as regressors. If those characteristics are related to the observed regressors, pooled OLS can confound their effects with the slope of interest. The fixed-effects within estimator addresses this particular problem by removing each unit’s time-constant component before estimating the slope.

The operation is simple: subtract a unit’s time average from each of its observations. The resulting equation contains changes relative to that unit’s own average, not comparisons of levels across different units. This removes the unit-specific intercept, but it does not remove every source of endogeneity or establish a causal interpretation by itself.

Model: For units \(i=1,\ldots,N\) and periods \(t=1,\ldots,T\), consider the balanced-panel model $$ y_{it}=\alpha_i+x_{it}'\beta+u_{it}. $$ Here \(y_{it}\) is the outcome, \(x_{it}\) is a \(K\)-component regressor vector, \(\beta\) is a common \(K\)-component slope vector, \(\alpha_i\) is an unrestricted time-invariant unit effect, and \(u_{it}\) is the remaining error. The within estimator uses time variation within units to estimate \(\beta\).

The unit effect \(\alpha_i\) may be associated with the entire regressor history for that unit. The within transformation does not require it to be independent of \(x_{it}\). Its key algebraic feature is that \(\alpha_i\) is constant over time for unit \(i\), so subtracting the time average removes it exactly.

Time Demeaning and the Within Equation

For each unit, define its time averages as \(\bar y_i=T^{-1}\sum_{t=1}^T y_{it}\), \(\bar x_i=T^{-1}\sum_{t=1}^T x_{it}\), and \(\bar u_i=T^{-1}\sum_{t=1}^T u_{it}\). Subtract the unit’s average model equation from each period’s equation.

$$ y_{it}-\bar y_i=(x_{it}-\bar x_i)'\beta+(u_{it}-\bar u_i). $$

The intercept disappears because \(\alpha_i-\alpha_i=0\). Write \(\tilde y_{it}=y_{it}-\bar y_i\), \(\tilde x_{it}=x_{it}-\bar x_i\), and \(\tilde u_{it}=u_{it}-\bar u_i\). The transformed model is \(\tilde y_{it}=\tilde x_{it}'\beta+\tilde u_{it}\). In particular, \(\sum_{t=1}^T\tilde x_{it}=0\) and \(\sum_{t=1}^T\tilde y_{it}=0\) for every unit.

Definition: The within estimator is the OLS slope estimate from regressing the time-demeaned outcome \(\tilde y_{it}\) on the time-demeaned regressors \(\tilde x_{it}\), with no separate unit intercept in that transformed regression. It is defined when the aggregate within-regressor cross-product matrix is invertible.

In sample-moment form, the estimator is

$$ \hat\beta_{\mathrm{within}} = \left(\sum_{i=1}^{N}\sum_{t=1}^{T}\tilde x_{it}\tilde x_{it}'\right)^{-1} \left(\sum_{i=1}^{N}\sum_{t=1}^{T}\tilde x_{it}\tilde y_{it}\right). $$

The matrix in parentheses is \(K\times K\); its invertibility requires enough independent within-unit regressor variation to distinguish the \(K\) slope coefficients. With one regressor, this reduces to a ratio: the sum of demeaned regressor–outcome products divided by the sum of squared demeaned regressors.

Worked Example: Removing Two Unit Intercepts

Suppose two units are observed for three periods. The hypothetical data are:

UnitPeriod\(x_{it}\)\(y_{it}\)
A115
A227
A339
B120
B244
B368

For unit A, \(\bar x_A=2\) and \(\bar y_A=7\), so its demeaned values are \(\tilde x_A=(-1,0,1)\) and \(\tilde y_A=(-2,0,2)\). For unit B, \(\bar x_B=4\) and \(\bar y_B=4\), giving \(\tilde x_B=(-2,0,2)\) and \(\tilde y_B=(-4,0,4)\). The within slope is

$$ \hat\beta_{\mathrm{within}} = \frac{(-1)(-2)+(0)(0)+(1)(2)+(-2)(-4)+(0)(0)+(2)(4)} {(-1)^2+0^2+1^2+(-2)^2+0^2+2^2} = \frac{4+16}{2+8} = 2. $$

The estimate is 2 outcome units per regressor unit. The unit-specific average levels do not contribute to this calculation; the estimate is based on how each unit’s outcome and regressor move around that unit’s own average.

Why This Formula Follows From Least Squares

The within estimator can also be derived by first considering least squares with a separate intercept for each unit. For any proposed \(\beta\), choose the intercepts to minimize the residual sum of squares. The part of that sum for unit \(i\) is

$$ \sum_{t=1}^{T}(y_{it}-\alpha_i-x_{it}'\beta)^2. $$

For fixed \(\beta\), differentiate this expression with respect to \(\alpha_i\), set the derivative to zero, and solve:

$$ -2\sum_{t=1}^{T}(y_{it}-\alpha_i-x_{it}'\beta)=0 \quad\Longrightarrow\quad \hat\alpha_i(\beta)=\bar y_i-\bar x_i'\beta. $$

Substituting this intercept into each residual gives

$$ y_{it}-\hat\alpha_i(\beta)-x_{it}'\beta = (y_{it}-\bar y_i)-(x_{it}-\bar x_i)'\beta = \tilde y_{it}-\tilde x_{it}'\beta. $$

Thus, after minimizing over each unit’s intercept, the remaining least-squares objective as a function of \(\beta\) is \(\sum_i\sum_t(\tilde y_{it}-\tilde x_{it}'\beta)^2\). Differentiating this objective with respect to \(\beta\) and setting the resulting \(K\)-vector equal to zero gives

$$ \sum_{i=1}^{N}\sum_{t=1}^{T}\tilde x_{it}\tilde x_{it}'\hat\beta = \sum_{i=1}^{N}\sum_{t=1}^{T}\tilde x_{it}\tilde y_{it}. $$

When the cross-product matrix is invertible, solving these normal equations yields the stated within-estimator formula. This derivation explains why demeaning is not an arbitrary adjustment: it is the least-squares way to remove the unit intercepts while estimating a common slope.

Several Regressors: The Matrix Calculation

With multiple regressors, each component is demeaned separately, but the regressors must be considered jointly. Their within-unit cross-products form a matrix, so the slope estimates account for overlap in the regressors’ within-unit movements.

Worked Example: A Two-Regressor Within Estimate

Consider two hypothetical units observed in three periods. For each unit, suppose the demeaned values of two regressors are \(\tilde x_{1}=(-1,0,1)\) and \(\tilde x_{2}=(1,-2,1)\). Suppose the demeaned outcomes for each unit are \(\tilde y=(-2.5,1,1.5)\). These transformed values are consistent with unit-level means: adding any constant to all three observations for a given unit leaves its demeaned values unchanged.

The within cross-product matrix sums over both units. For one unit, the regressor squares sum to 2 and 6, while the cross-product is \((-1)(1)+(0)(-2)+(1)(1)=0\). The regressor–outcome products for one unit are \(4\) and \(-3\). Therefore,

$$ \sum_{i,t}\tilde x_{it}\tilde x_{it}' = \begin{pmatrix}4&0\\0&12\end{pmatrix}, \qquad \sum_{i,t}\tilde x_{it}\tilde y_{it} = \begin{pmatrix}8\\-6\end{pmatrix}. $$

The estimate is

$$ \hat\beta_{\mathrm{within}} = \begin{pmatrix}4&0\\0&12\end{pmatrix}^{-1} \begin{pmatrix}8\\-6\end{pmatrix} = \begin{pmatrix}1/4&0\\0&1/12\end{pmatrix} \begin{pmatrix}8\\-6\end{pmatrix} = \begin{pmatrix}2\\-0.5\end{pmatrix}. $$

In this constructed example, the estimated slope on the first regressor is 2 outcome units per regressor unit, and the estimated slope on the second is \(-0.5\) outcome units per regressor unit, conditional on the other regressor. The zero off-diagonal entry makes the arithmetic especially simple; generally, the inverse matrix also accounts for correlations among demeaned regressors.

Conditions for Consistency

The transformation removes \(\alpha_i\), but consistency still requires assumptions about the remaining error and the available within variation. A standard setting lets the number of independent units \(N\) grow while the number of periods \(T\) is fixed. The slope vector is common across units, observations are generated from the stated model, and units are independent of one another (or satisfy suitable weak-dependence conditions). Dependence among a unit’s errors over time need not be ruled out for consistency.

Consistency conditions: A standard sufficient set is: (1) strict exogeneity, \(E(u_{it}\mid x_{i1},\ldots,x_{iT},\alpha_i)=0\) for every \(t\); (2) finite moments sufficient for a law of large numbers; (3) independent units, with fixed \(T\); and (4) a nonsingular limiting within-regressor moment matrix, $$ Q=\plim_{N\to\infty}\frac{1}{N}\sum_{i=1}^{N}\sum_{t=1}^{T}\tilde x_{it}\tilde x_{it}', $$ where \(Q\) is positive definite. Under these conditions, \(\hat\beta_{\mathrm{within}}\) converges in probability to \(\beta\).

To see the central argument, substitute the demeaned model into the estimator and subtract \(\beta\). The result is

$$ \hat\beta_{\mathrm{within}}-\beta = \left(\sum_{i,t}\tilde x_{it}\tilde x_{it}'\right)^{-1} \left(\sum_{i,t}\tilde x_{it}\tilde u_{it}\right). $$

Because \(\sum_t\tilde x_{it}=0\), the unit’s demeaned-error contribution satisfies \(\sum_t\tilde x_{it}\tilde u_{it}=\sum_t\tilde x_{it}u_{it}\): the term involving \(\bar u_i\) cancels. Strict exogeneity implies that each \(u_{it}\) has conditional mean zero given the unit’s full regressor history and \(\alpha_i\). Consequently, the average regressor–error cross-product converges to zero under the sampling and moment conditions. Meanwhile, the normalized cross-product matrix converges to the positive-definite matrix \(Q\), whose inverse exists. The estimation error therefore converges to zero.

Strict exogeneity is stronger than requiring only that the current regressor be uncorrelated with the current error. It rules out, for example, an error in one period predicting a regressor in another period. The fixed-effects transformation does not make this requirement unnecessary. Nor does it require \(\alpha_i\) to be independent of the regressors: that persistent unit component is precisely what the transformation eliminates.

Worked Example: Checking What the Transformation Does and Does Not Solve

Suppose a hypothetical panel records a worker’s output and training hours for five years. A worker’s stable ability is unobserved, but is plausibly related to training. If ability is constant over the five years, it is part of \(\alpha_i\), and demeaning removes its additive contribution from the within equation. This permits the within slope to be consistent despite the association between stable ability and training, provided the other conditions hold.

Now suppose a promotion occurs in year four, raises output, and also changes training hours. The promotion varies over time and is not removed by subtracting each worker’s average. If it is omitted from the model, its contribution can remain correlated with demeaned training, violating the required error–regressor condition. The within transformation alone therefore does not establish a causal effect of training. The omitted time-varying factor would need to be addressed by an appropriate model or design.

Common Pitfall: Demeaning Does Not Remove Everything

  • Wrong reasoning: “Fixed effects removes unobserved confounding, so the slope is automatically causal.”
  • Correction: Demeaning removes additive factors that are constant within a unit over time. Time-varying omitted factors, reverse feedback, measurement error, and violations of strict exogeneity can still invalidate the estimate or its causal interpretation.
  • Wrong reasoning: “A regressor that differs across units provides information for the within slope.”
  • Correction: A time-invariant regressor has \(\tilde x_{it}=0\) for every period and contributes no within variation. A slope is identified only when the demeaned regressors have adequate variation and their aggregate cross-product matrix has full rank.
Key takeaway: The within estimator is OLS on deviations from unit-specific time averages. This exactly removes a time-constant unit effect; consistency then depends on strict exogeneity, adequate within-regressor variation, and suitable sampling and moment conditions.

Check Your Understanding

Answer each question using the model and definitions above.

  1. For the model \(y_{it}=\alpha_i+x_{it}'\beta+u_{it}\), show in one line why subtracting the unit mean removes \(\alpha_i\).
  2. What is the within-estimator formula when there is one regressor? State what appears in its numerator and denominator.
  3. Why does strict exogeneity refer to a unit’s full regressor history rather than only its current regressor?
  4. What happens to a time-invariant regressor after within demeaning, and what does this imply for estimating its slope?
  5. Give an example of a time-varying omitted factor that would not be eliminated by demeaning, and explain why it can threaten consistency.
Clinical Biostats