Tutorials › Econometrics (Graduate) › Quasi-Demeaning in Random-Effects GLS

Generalized Least Squares · Tutorial 151 of 952

Quasi-Demeaning in Random-Effects GLS

Learn how quasi-demeaning converts random-intercept GLS into ordinary least squares on transformed panel variables and how to calculate the transformation correctly.

Intermediate 10 min read

What You'll Learn

  • State the random-intercept panel model and the assumptions behind its GLS transformation.
  • Derive the quasi-demeaning parameter from the covariance eigenvalues.
  • Interpret how the parameter depends on the variance components and panel length.
  • Transform outcomes, regressors, and the intercept using consistent arithmetic.
  • Distinguish quasi-demeaning from both pooled regression and full within-group demeaning.

Why Random-Intercept GLS Uses Quasi-Demeaning

In panel data, observations from the same unit can share an unobserved component. A random intercept represents that shared component, so the resulting errors are correlated within units. Ordinary least squares on the untransformed observations does not account for this covariance pattern. Generalized least squares (GLS) does so by changing the scale of the common, between-unit direction relative to the within-unit directions. In this model, that operation has a particularly simple form: subtract a fraction of each unit’s time average from each observation.

The fraction is neither arbitrary nor generally equal to zero or one. It is determined by the variance of the random intercept, the variance of the idiosyncratic error, and the number of observations for that unit. Deriving it makes clear both why the transformation works and what its limiting cases mean.

Model and Assumptions

For unit \(i=1,\ldots,N\) and period \(t=1,\ldots,T_i\), consider the random-intercept model

$$ y_{it}=x_{it}'\beta+a_i+\epsilon_{it}. $$

Here \(y_{it}\) is the outcome, \(x_{it}\) is a vector of observed regressors, and \(\beta\) is the coefficient vector. The unit-specific random intercept \(a_i\) is shared across periods for unit \(i\); \(\epsilon_{it}\) is the period-specific error. The panel may be unbalanced, so the number of observed periods \(T_i\) can vary across units. Define unit averages by \(\bar y_i=T_i^{-1}\sum_{t=1}^{T_i}y_{it}\) and \(\bar x_i=T_i^{-1}\sum_{t=1}^{T_i}x_{it}\).

For the covariance structure and transformation below, assume \(E[a_i]=0\), \(\operatorname{Var}(a_i)=\sigma_a^2\), \(E[\epsilon_{it}]=0\), and \(\operatorname{Var}(\epsilon_{it})=\sigma_\epsilon^2\). Assume idiosyncratic errors are uncorrelated across periods and units, and are uncorrelated with the random intercepts. Random intercepts are uncorrelated across units. Thus, within a unit, the composite error \(u_{it}=a_i+\epsilon_{it}\) has covariance matrix

$$ \operatorname{Var}(u_i)=\sigma_\epsilon^2 I_{T_i}+\sigma_a^2\mathbf{1}_{T_i}\mathbf{1}_{T_i}'. $$

For unit \(i\)'s transformed errors to have zero conditional mean given \(X_i\), also require \(E[a_i\mid X_i]=0\) and \(E[\epsilon_{it}\mid X_i,a_i]=0\), where \(X_i\) collects the regressors for unit \(i\). These exogeneity conditions are distinct from the covariance assumptions: a correct covariance transformation does not by itself guarantee that the regressors are exogenous.

Definition: The quasi-demeaning transformation replaces each observation by \(y_{it}^*=y_{it}-\theta_i\bar y_i\) and \(x_{it}^*=x_{it}-\theta_i\bar x_i\), where \(\theta_i\) is chosen from the covariance parameters and \(T_i\). Applying the same transformation to outcomes, regressors, and any other columns of the design matrix gives the GLS regression in transformed form.

Deriving the Transformation Parameter

Let \(P_i=\mathbf{1}_{T_i}\mathbf{1}_{T_i}'/T_i\), the projection onto the direction that is constant across unit \(i\)’s observed periods. The covariance matrix has eigenvalue \(\sigma_\epsilon^2\) in every direction orthogonal to \(\mathbf{1}_{T_i}\), and eigenvalue \(\sigma_\epsilon^2+T_i\sigma_a^2\) in the constant direction. A transformation that leaves the within-unit directions unchanged and multiplies the constant direction by \(1-\theta_i\) is \(Q_i=I_{T_i}-\theta_iP_i\). Since \(P_i\) is a projection, \(Q_i\) acts as the identity on the within directions and as multiplication by \(1-\theta_i\) on the constant direction.

To make the transformed covariance equal to \(\sigma_\epsilon^2 I_{T_i}\), choose \(1-\theta_i\) so that the variance in the constant direction is reduced to \(\sigma_\epsilon^2\). The resulting equation and solution are

$$ (1-\theta_i)^2(\sigma_\epsilon^2+T_i\sigma_a^2)=\sigma_\epsilon^2, \qquad \theta_i=1-\sqrt{\frac{\sigma_\epsilon^2}{\sigma_\epsilon^2+T_i\sigma_a^2}}. $$

The positive square root is used so that \(1-\theta_i\) is positive. Equivalently, \(Q_i\operatorname{Var}(u_i)Q_i'=\sigma_\epsilon^2I_{T_i}\). Also, \(P_i y_i\) is the vector whose entries are all \(\bar y_i\), so \(Q_i y_i\) has entries \(y_{it}-\theta_i\bar y_i\). The identical operation on each regressor gives the stated quasi-demeaned regression. Because the transformed errors have the same scalar covariance within every unit, least squares on all transformed observations is GLS when the variance components are known.

Interpretation: The parameter \(\theta_i\) measures how much of unit \(i\)’s time average is subtracted. If \(\sigma_a^2=0\), then \(\theta_i=0\), and there is no shared random-intercept variation to remove. As \(\sigma_a^2/\sigma_\epsilon^2\) or \(T_i\) increases, \(\theta_i\) increases toward one. At the limiting value \(\theta_i=1\), the transformation is full within-unit demeaning; at intermediate values it retains some between-unit information.

Worked Transformations

Worked Example: Transforming One Balanced Unit

Suppose a balanced panel has \(T=3\), with \(\sigma_a^2=4\) and \(\sigma_\epsilon^2=6\). For one hypothetical unit, the three outcomes are \(10,14,16\), and a single regressor takes values \(1,2,4\). Calculate the quasi-demeaned observations.

First, the transformation parameter is

$$ \theta=1-\sqrt{\frac{6}{6+3(4)}}=1-\sqrt{\frac{1}{3}} =0.4226497\ldots $$

The unit means are \(\bar y=(10+14+16)/3=13.3333\ldots\) and \(\bar x=(1+2+4)/3=2.3333\ldots\). Use the unrounded expression for \(\theta\) when calculating. The amount subtracted from each outcome is

$$ \left(1-\frac{1}{\sqrt{3}}\right)\frac{40}{3} =5.6353297\ldots, \qquad \left(1-\frac{1}{\sqrt{3}}\right)\frac{7}{3} =0.9861827\ldots $$

The second value is the amount subtracted from each regressor observation. Therefore, to four decimal places, the transformed outcomes are \(4.3647, 8.3647, 10.3647\), and the transformed regressor values are \(0.0138, 1.0138, 3.0138\). For instance, the first transformed outcome is \(10-5.6353297\ldots=4.3646703\ldots\), and the first transformed regressor is \(1-0.9861827\ldots=0.0138173\ldots\). Rounding \(\theta\) before multiplying can create small inconsistencies in these results, so retain precision through the calculation and round the final values.

Worked Example: Different Panel Lengths, Different Transformations

Suppose \(\sigma_\epsilon^2=4\) and \(\sigma_a^2=1\). Unit A has two observed periods, with outcomes \(5,9\) and regressor values \(2,6\). Unit B has four observed periods, with outcomes \(3,4,6,7\) and regressor values \(1,2,3,5\). Calculate each unit’s parameter and transformed values.

For unit A, \(T_A=2\), so

$$ \theta_A=1-\sqrt{\frac{4}{4+2}}=1-\sqrt{\frac{2}{3}} =0.1835034\ldots $$

Its means are \(\bar y_A=7\) and \(\bar x_A=4\). Thus the transformed outcomes are \(5-\theta_A(7)=3.7155\) and \(9-\theta_A(7)=7.7155\); the transformed regressor values are \(2-\theta_A(4)=1.2660\) and \(6-\theta_A(4)=5.2660\).

For unit B, \(T_B=4\), giving

$$ \theta_B=1-\sqrt{\frac{4}{4+4}}=1-\frac{1}{\sqrt{2}} =0.2928932\ldots $$

Here \(\bar y_B=5\) and \(\bar x_B=2.75\). The amount subtracted from each outcome is \(\theta_B(5)=1.4645\), and the amount subtracted from each regressor value is \(\theta_B(2.75)=0.8055\), to four decimal places. The transformed outcomes are therefore \(1.5355, 2.5355, 4.5355, 5.5355\), and the transformed regressor values are \(0.1945, 1.1945, 2.1945, 4.1945\). Unit B has a larger \(\theta_i\) because its longer panel makes the shared intercept contribute more variance to the unit’s common direction.

Worked Example: Transforming the Intercept in an Unbalanced Panel

Suppose a regression includes a constant and the variance components are \(\sigma_\epsilon^2=9\) and \(\sigma_a^2=3\). Unit C has \(T_C=1\), while unit D has \(T_D=4\). What happens to the constant column?

A constant regressor equals one in every period, so its unit mean is also one. For unit C,

$$ \theta_C=1-\sqrt{\frac{9}{9+3}}=1-\frac{\sqrt{3}}{2} =0.1340\ldots,\qquad 1-\theta_C=0.8660\ldots . $$

The transformed constant entry for that unit is \(1-\theta_C=0.8660\ldots\). For unit D,

$$ \theta_D=1-\sqrt{\frac{9}{9+12}}=1-\frac{\sqrt{3}}{\sqrt{7}} =0.3453\ldots,\qquad 1-\theta_D=0.6547\ldots . $$

Every transformed constant entry for unit D is \(0.6547\ldots\). Since the panel is unbalanced, these two transformed values differ. The constant column must therefore be transformed along with the other design columns; it is not generally an unchanged column of ones. In a balanced panel, all units have the same \(T_i\), so the transformed constant is the same nonzero value in every row and remains proportional to an ordinary constant column.

What the Transformation Retains

The decomposition into a unit’s average and its deviations from that average clarifies the transformation’s meaning. Write an observation as \(y_{it}=(y_{it}-\bar y_i)+\bar y_i\). Then

$$ y_{it}-\theta_i\bar y_i=(y_{it}-\bar y_i)+(1-\theta_i)\bar y_i. $$

The within-unit deviation is retained in full, while the unit mean is multiplied by \(1-\theta_i\). When \(\theta_i=0\), both within and between variation remain unchanged, as in pooled least squares. As \(\theta_i\) approaches one, the between-unit component is increasingly attenuated; at \(\theta_i=1\), only deviations from unit means remain. Quasi-demeaning is therefore not simply “subtracting the random intercept”: the intercept is unobserved, and the transformation instead rescales the common direction in the way required by the covariance matrix.

This distinction matters for interpretation and estimation. Intermediate quasi-demeaning uses both within- and between-unit variation, with their relative contribution shaped by the covariance parameters. It does not, by itself, resolve possible correlation between \(a_i\) and the regressors. If the random-intercept exogeneity condition fails, the transformation can still whiten the specified covariance matrix, but the resulting coefficient estimator need not have the desired conditional mean.

Common Mistakes

  • Using a single parameter in an unbalanced panel. Since \(\theta_i\) depends on \(T_i\), units with different numbers of observed periods generally require different transformations.
  • Transforming only the outcome. GLS requires applying the same operation to every regressor and to any constant column. Otherwise the transformed equation is not the original model’s GLS regression.
  • Calling quasi-demeaning full demeaning. Unless \(\theta_i=1\), the transformed observation still contains \((1-\theta_i)\bar y_i\), so between-unit information has not been removed entirely.
  • Rounding too early. A rounded \(\theta_i\) may not reproduce displayed products or transformed values. Keep full precision during multiplication and round the final results consistently.
  • Confusing covariance correction with exogeneity. The transformation handles the stipulated within-unit covariance. It does not make a random intercept uncorrelated with regressors if that assumption is false.
Key takeaway: Under the random-intercept covariance model, quasi-demeaning uses \(\theta_i=1-\sqrt{\sigma_\epsilon^2/(\sigma_\epsilon^2+T_i\sigma_a^2)}\). It leaves within-unit deviations intact and attenuates unit means by \(1-\theta_i\), producing the GLS transformation when applied consistently to every model column.

Check Your Understanding

Try these questions before reviewing the derivation and examples.

  1. For fixed positive variance components, how does increasing \(T_i\) affect \(\theta_i\), and what does that imply about the unit mean?
  2. If \(\sigma_a^2=0\), what is \(\theta_i\), and how does the transformation change the observations?
  3. A unit has \(T_i=2\), \(\sigma_\epsilon^2=5\), and \(\sigma_a^2=1\). Write the formula for its \(\theta_i\) and calculate it to four decimal places.
  4. Why must the constant column be transformed in an unbalanced panel?
  5. Does correct quasi-demeaning guarantee that the random-intercept estimator is unbiased if \(a_i\) is correlated with the regressors? Explain.
Clinical Biostats