From the Model to a Hand Calculation
A fixed-effects estimate uses changes within a unit to separate the effect of a regressor from stable differences between units. With two periods, that calculation is especially transparent: subtracting each unit’s mean removes its unit effect, while differencing its two observations removes the same effect. The resulting within and first-difference slopes are identical when computed on the same balanced sample with the same regressor.
Consider a static panel with units \(i=1,\ldots,n\) observed in periods \(t=1,2\). There is one time-varying regressor, \(x_{it}\), and one outcome, \(y_{it}\). The unit fixed-effects model is
Here \(\alpha_i\) is a unit-specific effect that does not change between the two periods, \(\beta\) is a common slope, and \(u_{it}\) is the time-varying error. The fixed-effects calculation allows \(\alpha_i\) to be associated with the regressor. It does not, by itself, ensure that changes in \(x_{it}\) are uncorrelated with changes in \(u_{it}\). A standard condition for interpreting the slope as consistently estimating \(\beta\) is strict exogeneity conditional on the unit effect: \(E(u_{it}\mid x_{i1},x_{i2},\alpha_i)=0\) for each \(t\). The arithmetic below defines and computes the estimator; this exogeneity condition is about its statistical interpretation, not about whether the arithmetic can be performed.
This is a one-regressor calculation. To identify its slope, the regressor must vary within at least some units; if \(x_{i2}=x_{i1}\) for every unit, the within regressor is zero everywhere and the slope is undefined. The balanced-panel condition here means the same units have observations in both periods.
Worked Calculation: Within and First Differences
The following values are hypothetical. Suppose four units are observed in both periods:
| Unit | \(x_{i1}\) | \(x_{i2}\) | \(y_{i1}\) | \(y_{i2}\) |
|---|---|---|---|---|
| A | 2 | 5 | 10 | 16 |
| B | 4 | 2 | 13 | 10 |
| C | 1 | 3 | 8 | 11 |
| D | 3 | 4 | 12 | 13 |
Worked Example: Demeaning Each Unit’s Observations
First calculate the means within each unit, then subtract those means from each observation. All values in this hypothetical example are in the units of their respective variables.
| Unit | \(\bar{x}_i\) | \(\bar{y}_i\) | \((\tilde{x}_{i1},\tilde{x}_{i2})\) | \((\tilde{y}_{i1},\tilde{y}_{i2})\) |
|---|---|---|---|---|
| A | \((2+5)/2=3.5\) | \((10+16)/2=13\) | \((-1.5,1.5)\) | \((-3,3)\) |
| B | \((4+2)/2=3\) | \((13+10)/2=11.5\) | \((1,-1)\) | \((1.5,-1.5)\) |
| C | \((1+3)/2=2\) | \((8+11)/2=9.5\) | \((-1,1)\) | \((-1.5,1.5)\) |
| D | \((3+4)/2=3.5\) | \((12+13)/2=12.5\) | \((-0.5,0.5)\) | \((-0.5,0.5)\) |
For example, unit A’s first demeaned regressor value is \(2-3.5=-1.5\), and its second is \(5-3.5=1.5\). In both periods the unit-specific effect cancels: \(\tilde{y}_{it}=\beta\tilde{x}_{it}+\tilde{u}_{it}\). The within OLS slope is the sum of demeaned cross-products divided by the sum of demeaned regressor squares:
The numerator contribution from A is \((-1.5)(-3)+(1.5)(3)=9\); its denominator contribution is \((-1.5)^2+(1.5)^2=4.5\). The other units’ contributions are calculated in the same way. The estimated slope is about 1.722 outcome units per one regressor unit.
The First-Difference Calculation
Define the first difference as the period-2 value minus the period-1 value: \(\Delta x_i=x_{i2}-x_{i1}\) and \(\Delta y_i=y_{i2}-y_{i1}\). Differencing the model gives
because \(\alpha_i-\alpha_i=0\). There is no intercept in this differenced equation: a common intercept in a regression of changes would not be part of this fixed-effects transformation. The one-regressor first-difference estimate is therefore the OLS slope through the origin.
Worked Example: Regressing Changes Through the Origin
Using the same hypothetical data, the unit changes and the products needed for the first-difference slope are:
| Unit | \(\Delta x_i\) | \(\Delta y_i\) | \(\Delta x_i\Delta y_i\) | \((\Delta x_i)^2\) |
|---|---|---|---|---|
| A | \(5-2=3\) | \(16-10=6\) | 18 | 9 |
| B | \(2-4=-2\) | \(10-13=-3\) | 6 | 4 |
| C | \(3-1=2\) | \(11-8=3\) | 6 | 4 |
| D | \(4-3=1\) | \(13-12=1\) | 1 | 1 |
The through-origin OLS formula is \(\hat{\beta}_{\mathrm{FD}}=\sum_i\Delta x_i\Delta y_i/\sum_i(\Delta x_i)^2\). Substituting all four units gives
The estimate matches the within result: both equal \(31/18\), or approximately 1.722 outcome units per regressor unit. Under the model and exogeneity condition stated above, this is the fixed-effects slope estimate; it is not, solely from this computation, proof of a causal effect.
Why the Two Calculations Coincide
The equality can be checked directly. For any unit in a balanced two-period panel,
Thus that unit contributes \(\Delta x_i\Delta y_i/2\) to the within numerator and \((\Delta x_i)^2/2\) to the within denominator. Summing over units puts the same factor \(1/2\) in both parts of the within ratio. It cancels, leaving the first-difference ratio.
For the worked data, the within numerator is \(15.5\), exactly half the first-difference numerator \(31\), and the within denominator is \(9\), exactly half the first-difference denominator \(18\). This cancellation is why the two reported slopes agree. The result does not say that the transformed data are identical: within estimation uses two demeaned observations per unit, whereas first differences use one change per unit.
What Identifies the Slope?
Only within-unit changes in \(x\) supply information about the fixed-effects slope. A unit with no change in \(x\) does not increase the denominator of the first-difference ratio. Its change in \(y\) cannot, by itself, identify the slope because there is no corresponding change in the regressor.
Worked Example: A Unit With No Regressor Change
Suppose a different hypothetical two-period panel has three units with changes \((\Delta x_i,\Delta y_i)=(1,2),(2,2),(0,100)\). The third unit has a large outcome change but no regressor change. The first-difference slope is
The third unit contributes zero to both sums. Its \(100\)-unit outcome change does not create identifying variation in \(x\). If every unit had \(\Delta x_i=0\), the denominator would be zero and the fixed-effects slope could not be calculated.
The estimate is also not generally the unweighted average of the ratios \(\Delta y_i/\Delta x_i\). In the four-unit example, those ratios are \(2\), \(1.5\), \(1.5\), and \(1\), whose unweighted mean is \(1.5\), not \(1.7222\). The OLS calculation weights the contributions according to the amount of regressor change, as shown by the squared changes in its denominator.
Common Mistakes
- Keeping a unit effect after transforming. Subtracting the unit mean or differencing cancels a fixed \(\alpha_i\); it is not an extra term to estimate in the transformed regression.
- Adding an intercept to the first-difference regression. The fixed-effects first-difference equation has no intercept when the original model contains only unit effects and a common slope. An intercept in a regression of changes is a different specification.
- Using pooled levels to calculate this slope. Pooled OLS in levels can mix between-unit differences with within-unit changes. The calculation here uses demeaned values or first differences.
- Averaging unit-specific change ratios. The fixed-effects slope is the ratio of summed cross-products to summed squared changes, not generally the simple average of \(\Delta y_i/\Delta x_i\).
- Overstating the interpretation. Removing time-invariant unit effects does not remove time-varying confounding or guarantee exogeneity. A computed slope alone does not establish causation.
Check Your Understanding
Use the definitions and formulas above to answer these questions.
- For a unit with \(x_{i1}=6\) and \(x_{i2}=10\), what are its two demeaned regressor values and its first difference?
- Why does the first-difference regression have no intercept in the stated fixed-effects model?
- A unit has \(\Delta x_i=0\) and \(\Delta y_i=4\). What does it contribute to the first-difference numerator and denominator, and why?
- For the four-unit worked example, why do the within numerator and denominator equal one-half of their first-difference counterparts?
- What condition on regressor changes is needed to calculate the one-regressor fixed-effects slope?
- Does equality of the within and first-difference estimates, by itself, establish a causal effect? Explain briefly.