Tutorials › Econometrics (Graduate) › Deriving Quasi-Demeaning For Random Effects

Fixed and Random Effects · Tutorial 262 of 952

Deriving Quasi-Demeaning For Random Effects

See how generalized least squares leads to quasi-demeaning, and calculate how much of each unit’s mean remains in the transformed data.

Intermediate 12 min read

What You'll Learn

  • State the balanced random-effects model and its error covariance assumptions
  • Derive the quasi-demeaning parameter from the covariance matrix’s within- and between-unit directions
  • Transform outcomes, regressors, and the intercept using the same parameter
  • Interpret quasi-demeaning as partial removal of unit means
  • Verify numerically that the transformation reproduces the GLS quadratic objective

Why Random-Effects GLS Transforms the Data

In a panel model with a random unit effect, observations from the same unit share a component of their error. Consequently, their errors are correlated, and ordinary least squares on the untransformed observations does not use the error covariance structure in the way generalized least squares (GLS) does. In the balanced random-effects model, GLS can be implemented by a particularly simple transformation: subtract a fraction of each unit’s time average from each observation. This is called quasi-demeaning.

The fraction is neither arbitrary nor generally equal to one. It is determined by the relative sizes of the unit-effect and idiosyncratic error variances and by the number of observations per unit. Deriving it from the covariance matrix explains both why the transformation is GLS and why it only partially removes unit means.

Model and Covariance Structure

Consider a balanced panel with \(N\) units and \(T\) observations for each unit. For unit \(i\) at time \(t\), let

$$ y_{it}=x_{it}'\beta+a_i+u_{it}, \qquad i=1,\ldots,N,\quad t=1,\ldots,T. $$

Here \(y_{it}\) is the outcome, \(x_{it}\) is a vector of regressors, \(\beta\) is the slope vector, \(a_i\) is a time-constant random unit effect, and \(u_{it}\) is the idiosyncratic error. Write \(X_i\) for the \(T\)-row regressor matrix and \(y_i\) for the \(T\)-element outcome vector of unit \(i\).

Assumptions for the derivation: Conditional on the regressors, the random unit effects have mean zero and variance \(\sigma_a^2\), are independent across units, and are uncorrelated with the regressors. The idiosyncratic errors have conditional mean zero, variance \(\sigma_u^2\), and are uncorrelated across times and units. They are uncorrelated with the unit effects. Thus the composite error for unit \(i\), \(a_i\mathbf{1}+u_i\), has covariance \(\Omega_i=\sigma_u^2 I_T+\sigma_a^2\mathbf{1}\mathbf{1}'\), where \(\mathbf{1}\) is a \(T\)-element vector of ones. The variance components are positive and treated as known for the transformation derived here.

The covariance matrix has \(\sigma_u^2+\sigma_a^2\) on its diagonal and \(\sigma_a^2\) off the diagonal. For distinct times \(t\) and \(s\), the shared \(a_i\) gives \(\operatorname{Cov}(a_i+u_{it},a_i+u_{is}\mid X_i)=\sigma_a^2\). Thus the within-unit observations are not independent, even though the idiosyncratic errors are uncorrelated.

Deriving the Quasi-Demeaning Parameter

Define the projection onto the unit-mean direction by \(P=\mathbf{1}\mathbf{1}'/T\). It maps a vector to a vector whose entries are all that vector’s time average. The complementary projection \(I_T-P\) removes the unit mean. These two directions separate the covariance structure:

$$ \Omega_i=\sigma_u^2(I_T-P)+(\sigma_u^2+T\sigma_a^2)P. $$

To check this decomposition, note that \(P^2=P\), \((I_T-P)^2=I_T-P\), and \(P(I_T-P)=0\). Also, \(\mathbf{1}\mathbf{1}'=TP\). Along directions with zero time mean, the covariance has eigenvalue \(\sigma_u^2\); along the unit-mean direction, it has eigenvalue \(\sigma_u^2+T\sigma_a^2\). GLS whitens these directions by dividing by the square roots of their respective eigenvalues.

$$ \Omega_i^{-1/2} =\frac{1}{\sigma_u}(I_T-P) +\frac{1}{\sqrt{\sigma_u^2+T\sigma_a^2}}P. $$

Factor out \(1/\sigma_u\), and define \(\theta\) so the remaining matrix has the form \(I_T-\theta P\). Matching its coefficient on \(P\) gives

$$ 1-\theta=\frac{\sigma_u}{\sqrt{\sigma_u^2+T\sigma_a^2}}, \qquad \theta=1-\frac{\sigma_u}{\sqrt{\sigma_u^2+T\sigma_a^2}}. $$
Definition: The balanced-panel random-effects quasi-demeaning parameter is \(\displaystyle \theta=1-\frac{\sigma_u}{\sqrt{\sigma_u^2+T\sigma_a^2}}\). For any unit-level vector \(z_i\), its quasi-demeaned version is \(\displaystyle z_i^*=z_i-\theta\bar z_i\mathbf{1}\), where \(\bar z_i=T^{-1}\sum_{t=1}^{T}z_{it}\). Apply the same transformation to the outcome and every regressor.

This parameter lies between zero and one under the stated positive-variance assumptions. More importantly for interpreting the operation, the time average of the transformed vector is

$$ \bar z_i^*=\bar z_i-\theta\bar z_i=(1-\theta)\bar z_i. $$

Thus quasi-demeaning removes the fraction \(\theta\) of the unit mean and retains the fraction \(1-\theta\). It does not generally remove the mean completely. The common scalar \(1/\sigma_u\) in the whitening matrix can be omitted when estimating by least squares: multiplying every transformed observation by the same nonzero scalar multiplies the least-squares objective by a constant and leaves its minimizer unchanged.

From the Transformation to GLS

Let \(y_i^*=y_i-\theta\bar y_i\mathbf{1}\) and transform each column of \(X_i\) in the same way to obtain \(X_i^* = X_i-\theta\mathbf{1}\bar x_i'\), where \(\bar x_i=T^{-1}X_i'\mathbf{1}\). Since the whitening matrix is proportional to \(I_T-\theta P\), GLS on the original panel has the same coefficient estimate as least squares using the transformed outcomes and regressors. In particular, the unit effect is transformed along with the observations:

$$ y_{it}^*=x_{it}^{*'}\beta+(1-\theta)a_i+u_{it}^*. $$

The transformed error is not obtained by simply discarding \(a_i\). Rather, the mean-direction part of the composite error has been rescaled to have the appropriate GLS weight. If the model includes a common intercept, its regressor is a column of ones. That column transforms to \((1-\theta)\mathbf{1}\), not to zero except in the limiting case of complete demeaning.

Worked Example: Calculating the Transformation Parameter

Suppose a hypothetical balanced panel has \(T=4\), with \(\sigma_u^2=9\) and \(\sigma_a^2=7\), measured in squared outcome units. Calculate \(\theta\), then state how much of each unit mean remains.

First take the square root of each variance component as needed: \(\sigma_u=3\). Substitution gives

$$ \theta =1-\frac{3}{\sqrt{9+4(7)}} =1-\frac{3}{\sqrt{37}} \approx 1-\frac{3}{6.083} \approx 0.5068. $$

Each observation is therefore transformed by subtracting about \(0.5068\) times its unit’s time average. The retained fraction of the mean is \(1-\theta\approx0.4932\). For example, if a unit’s average outcome is 20 outcome units, the transformed unit average is \(0.4932(20)\approx9.864\) outcome units. The mean is partially removed, not set to zero.

The calculation uses the number of observations per unit, \(T=4\), and the two error variances. No sample outcome values are needed to determine \(\theta\) when the variance components are known.

Applying Quasi-Demeaning to Panel Data

Worked Example: Transforming Outcomes and Regressors

Consider a hypothetical unit observed for three periods. Its outcomes are \(10,14,16\), and its single regressor values are \(1,2,4\). Suppose \(\sigma_u^2=4\) and \(\sigma_a^2=4\). Find the transformed observations when the model includes a common intercept.

Here \(\sigma_u=2\), so

$$ \theta =1-\frac{2}{\sqrt{4+3(4)}} =1-\frac{2}{4} =0.5. $$

The unit means are \(\bar y_i=(10+14+16)/3=13.333\) and \(\bar x_i=(1+2+4)/3=2.333\). For each period, subtract half the corresponding unit mean:

$$ y_i^*=(10,14,16)-0.5(13.333,13.333,13.333) \approx(3.333,7.333,9.333), $$
$$ x_i^*=(1,2,4)-0.5(2.333,2.333,2.333) \approx(-0.1667,0.8333,2.833). $$

The transformed outcome average is \((3.333+7.333+9.333)/3\approx6.667\), which equals \((1-\theta)\bar y_i=0.5(13.333)\). The transformed regressor average is approximately \(1.167\), also equal to \(0.5(2.333)\). The common-intercept column becomes \((0.5,0.5,0.5)\). These values show explicitly that the same operation applies to the outcome, regressor, and intercept.

Checking the GLS Objective

A direct numerical check makes the GLS connection concrete. For a residual vector \(r_i=y_i-X_i\beta\), GLS weights its squared deviations by \(\Omega_i^{-1}\), giving \(r_i'\Omega_i^{-1}r_i\). The quasi-demeaning matrix must reproduce this same quadratic objective, up to the common scale factor \(1/\sigma_u^2\).

Worked Example: Comparing the GLS and Transformed Objectives

For a hypothetical two-period unit, let \(\sigma_u^2=4\), \(\sigma_a^2=1\), and consider the residual vector \(r_i=(2,0)'\). Calculate its GLS quadratic contribution and check it using quasi-demeaning.

The covariance matrix and its inverse are

$$ \Omega_i= \begin{pmatrix}5&1\\1&5\end{pmatrix}, \qquad \Omega_i^{-1} =\frac{1}{24} \begin{pmatrix}5&-1\\-1&5\end{pmatrix}. $$

Therefore,

$$ r_i'\Omega_i^{-1}r_i =(2,0)\frac{1}{24} \begin{pmatrix}5&-1\\-1&5\end{pmatrix} \begin{pmatrix}2\\0\end{pmatrix} =\frac{20}{24} \approx0.8333. $$

The quasi-demeaning parameter is \(\theta=1-2/\sqrt{6}\approx0.1835\), and the residual mean is \(\bar r_i=1\). Thus \(r_i^*=r_i-\theta\bar r_i\mathbf{1}\approx(1.8165,-0.1835)'\). Its transformed sum of squares, with the common GLS scale restored, is

$$ \frac{1}{\sigma_u^2}r_i^{*'}r_i^* \approx\frac{(1.8165)^2+(-0.1835)^2}{4} \approx0.8333. $$

The two calculations agree, apart from rounding. This is why least squares on quasi-demeaned data implements GLS for this covariance structure.

What the Transformation Does to Unit Means

Quasi-demeaning lies between two familiar treatments of unit means. When \(\theta=0\), no part of a unit mean is removed. As \(\theta\) increases, a larger fraction is subtracted. Complete demeaning would subtract the entire mean; quasi-demeaning instead retains the fraction \(1-\theta\) dictated by the covariance weighting. This distinction matters when a regressor is constant over time: its transformed values are all \((1-\theta)x_i\), so it is not automatically eliminated by the transformation.

The covariance derivation also explains the role of panel length. The variance in the mean direction is \(\sigma_u^2+T\sigma_a^2\), whereas the variance in a zero-mean direction is \(\sigma_u^2\). GLS weights these two directions differently. The formula for \(\theta\) is precisely the adjustment that makes the transformed mean direction receive that relative weight. The transformation does not itself establish whether the random-effects assumptions are appropriate; it follows from the specified covariance structure.

Common Pitfall

Common mistake: “Random-effects estimation subtracts each unit’s full mean, so it is the same transformation as the fixed-effects within estimator.” This is incorrect unless \(\theta=1\). In the random-effects GLS transformation, each observation is \(z_{it}-\theta\bar z_i\), and the transformed mean is \((1-\theta)\bar z_i\). The correction is to calculate \(\theta\) from the variance components and \(T\), and then apply that same partial subtraction to every outcome and regressor.
Key takeaway: For a balanced random-effects panel, GLS whitening separates the unit-mean direction from the within-unit directions. Its equivalent quasi-demeaning subtracts the fraction \(\theta=1-\sigma_u/\sqrt{\sigma_u^2+T\sigma_a^2}\) of each unit mean, leaving the remaining fraction in the transformed data.

Check Your Understanding

Use the model, covariance assumptions, and transformation derived above.

  1. In the balanced random-effects model, which component of the composite error creates correlation between two observations from the same unit?
  2. If \(\theta=0.4\) and a unit’s regressor mean is 12 units, what is the mean of its quasi-demeaned regressor?
  3. Why does GLS assign a different weight to the unit-mean direction than to directions with zero unit mean?
  4. For \(T=3\), \(\sigma_u^2=4\), and \(\sigma_a^2=4\), calculate \(\theta\) and the fraction of the unit mean retained.
  5. What happens to a time-invariant regressor when it is quasi-demeaned, and why is the result generally different from complete demeaning?
Clinical Biostats