Solutions Tutorial 4

Retrieval practice

  1. Between-unit variation, which compares persistent differences across units, and within-unit variation, which compares a unit with itself over time; unit FE use only the within-unit deviations from each unit’s own mean.
  2. Demeaning subtracts each unit’s own mean, and a regressor that never changes is equal to its mean, so it becomes identically zero and is collinear with the unit effects.
  3. \(E(u_{it}\mid x_{i1},\ldots,x_{iT},\alpha_i)=0\) for every \(t\); feedback from today’s outcome shock to next period’s regressor violates it and is not removed by fixed effects.
  4. They are identical.
  5. Normally at the unit level, where the regressor varies and errors may be correlated; clustering changes the estimated uncertainty, not the coefficient.

Solutions

1. Between and within variation

a) Demeaning

The firm means are

\[ (\bar x_A,\bar y_A)=(2,12), \qquad (\bar x_B,\bar y_B)=(7.5,34). \]

Therefore:

Firm Period \(\ddot x_{it}\) \(\ddot y_{it}\)
A 1 \(-1\) \(-2\)
A 2 \(1\) \(2\)
B 1 \(-1.5\) \(-3\)
B 2 \(1.5\) \(3\)

b) The FE slope

\[ \hat\beta_{\mathrm{FE}} =\frac{(-1)(-2)+(1)(2)+(-1.5)(-3)+(1.5)(3)} {(-1)^2+1^2+(-1.5)^2+(1.5)^2} =\frac{13}{6.5}=2. \]

The coefficient is identified by changes in innovation and profit within the same firm. FE discards the large level difference between Firms A and B: Firm B has both much higher average innovation and much higher average profit. That between-firm comparison has no direct role in the FE slope.

c) The time-invariant regressor

Family ownership is constant within each firm, so

\[ z_i-\bar z_i=0 \]

for every observation. Its coefficient cannot be separately estimated with firm FE because it is perfectly collinear with the firm effects. This does not mean that ownership is unimportant; it means this panel contains no within-firm ownership variation with which to identify its coefficient.

d) First differences

The two differences are

Firm \(\Delta x_i\) \(\Delta y_i\)
A 2 4
B 3 6

The line through \((2,4)\) and \((3,6)\) has intercept zero and slope 2, equal to the FE slope. The common-change intercept happens to be zero in these data. More generally, with \(T=2\), demeaning produces rescaled first differences, so matching FE and FD specifications provide the same slope information. With three or more periods, FE and FD combine changes differently and their slopes need not be equal.

2. Estimating a fixed-effects model

a) Firm FE with firm-clustered standard errors

url <- "https://empirical-economics.netlify.app/tutorials/datafiles/jtrain.csv"
jtrain <- read_csv2(url, show_col_types = FALSE)

fe_firm <- feols(
  scrap ~ grant | fcode,
  data = jtrain,
  vcov = ~fcode
)

etable(fe_firm)
                           fe_firm
Dependent Var.:              scrap
                                  
grant           -0.7534** (0.2604)
Fixed-Effects:  ------------------
fcode                          Yes
_______________ __________________
S.E.: Clustered          by: fcode
Observations                   162
R2                         0.91719
Within R2                  0.02230
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
import pandas as pd
import pyfixest as pf

url = "https://empirical-economics.netlify.app/tutorials/datafiles/jtrain.csv"
jtrain_py = pd.read_csv(url, sep=";", decimal=",")

fe_firm_py = pf.feols(
    "scrap ~ grant | fcode",
    data=jtrain_py,
    vcov={"CRV1": "fcode"},
)

fe_firm_py.summary()
###

Estimation:  OLS
Dep. var.: scrap, Fixed effects: fcode
Inference:  CRV1
Observations:  162

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5% |   97.5% |
|:--------------|-----------:|-------------:|----------:|-----------:|-------:|--------:|
| grant         |     -0.753 |        0.260 |    -2.893 |      0.006 | -1.276 |  -0.231 |
---
RMSE: 1.723 R2: 0.917 R2 Within: 0.022 

The estimate is

\[ \hat\beta_{\mathrm{FE}}=-0.753, \qquad SE_{\text{cluster(firm)}}=0.260. \]

The regression uses 162 observations on 54 firms. The full file contains 157 firms, but scrap is observed for only these 54 firms.

b) Interpretation

For the same firm, a year with a training grant is associated with a scrap rate about 0.75 points lower than a year without a grant. This comparison holds all stable observed and unobserved firm characteristics fixed.

The estimate is not automatically causal. For example, a time-varying demand shock could affect both training-grant receipt and scrap, or past scrap shocks could influence subsequent grant allocation. Firm FE remove neither threat.

c) IID versus clustered inference

fe_iid <- feols(scrap ~ grant | fcode, data = jtrain, vcov = "iid")
NOTE: 309 observations removed because of NA values (LHS: 309).
etable(
  "IID SE" = fe_iid,
  "Firm-clustered SE" = fe_firm,
  fitstat = ~n
)
                          IID SE  Firm-clustered SE
Dependent Var.:            scrap              scrap
                                                   
grant           -0.7534 (0.4823) -0.7534** (0.2604)
Fixed-Effects:  ---------------- ------------------
fcode                        Yes                Yes
_______________ ________________ __________________
S.E. type                    IID          by: fcode
Observations                 162                162
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_iid_py = pf.feols(
    "scrap ~ grant | fcode",
    data=jtrain_py,
    vcov="iid",
)

pf.etable(
    [fe_iid_py, fe_firm_py],
    model_heads=["IID SE", "Firm-clustered SE"],
)
  scrap
IID SE Firm-clustered SE
(1) (2)
coef
grant -0.753
(0.482)
-0.753**
(0.260)
fe
fcode x x
stats
Observations 162 162
S.E. type iid by: fcode
R2 0.917 0.917
R2 Within 0.022 0.022
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell: Coefficient (Std. Error)

Both specifications return the same coefficient, \(-0.753\). The IID standard error is \(0.482\), whereas the firm-clustered standard error is \(0.260\).

There are repeated observations per firm, grant status varies within firms, and unobserved productivity shocks may be related across a firm’s years. Firm is therefore the natural clustering level. Clustered standard errors are not a mechanical penalty and need not exceed IID standard errors; their direction depends on the covariance pattern. The choice should be made from the sampling and assignment structure, not from which standard error gives a preferred result.

d) Adding year effects

fe_two_way <- feols(
  scrap ~ grant | fcode + year,
  data = jtrain,
  vcov = ~fcode
)
NOTE: 309 observations removed because of NA values (LHS: 309).
etable(
  "Firm FE" = fe_firm,
  "Firm + year FE" = fe_two_way,
  fitstat = ~n
)
                           Firm FE   Firm + year FE
Dependent Var.:              scrap            scrap
                                                   
grant           -0.7534** (0.2604) -0.3993 (0.3043)
Fixed-Effects:  ------------------ ----------------
fcode                          Yes              Yes
year                            No              Yes
_______________ __________________ ________________
S.E.: Clustered          by: fcode        by: fcode
Observations                   162              162
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_two_way_py = pf.feols(
    "scrap ~ grant | fcode + year",
    data=jtrain_py,
    vcov={"CRV1": "fcode"},
)

pf.etable(
    [fe_firm_py, fe_two_way_py],
    model_heads=["Firm FE", "Firm + year FE"],
)
  scrap
Firm FE Firm + year FE
(1) (2)
coef
grant -0.753**
(0.260)
-0.399
(0.304)
fe
year - x
fcode x x
stats
Observations 162 162
S.E. type by: fcode by: fcode
R2 0.917 0.926
R2 Within 0.022 0.006
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell: Coefficient (Std. Error)

With firm and year effects, the grant coefficient is \(-0.399\) with a firm-clustered standard error of \(0.304\).

  • Firm effects absorb stable management quality, location, or persistent production technology.
  • Year effects absorb a statewide recession or a common change in manufacturing regulation in a given year.
  • Neither absorbs a firm-specific, time-varying machinery breakdown that affects both scrap and the decision to seek a grant.

3. Identification: a feedback problem

a) Which assumption fails?

The proposed mechanism is

\[ u_{i,t-1} \longrightarrow \text{scrap}_{i,t-1} \longrightarrow \text{grant}_{it}. \]

It implies

\[ \operatorname{Cov}(u_{i,t-1},\text{grant}_{it}\mid\alpha_i)\neq0. \]

Strict exogeneity requires the error in every period to be mean-independent of grant status in all periods, conditional on the firm effect. Here a future regressor is related to a past error, so that requirement fails.

b) Why fixed effects do not solve it

Firm FE remove only time-invariant firm characteristics. The previous year’s unexpected scrap shock is time-varying, so demeaning does not remove the feedback link. Year effects absorb shocks common to all firms in a year, but they do not absorb a firm-specific past shock that changes that firm’s grant probability. Thus adding year effects does not generally solve the problem.

c) Identification versus inference

Clustering by firm allows the estimated errors to have an arbitrary covariance pattern within firms and adjusts the estimated sampling uncertainty. It does not break the relationship between the regressor and the error and therefore cannot remove feedback bias.

Strict exogeneity is an identification condition. Clustering is an inference choice. A precisely estimated biased coefficient remains biased.

4. Estimating and comparing first differences

a) FD estimation

jtrain_diff <- jtrain |>
  arrange(fcode, year) |>
  group_by(fcode) |>
  mutate(
    d_scrap = scrap - lag(scrap),
    d_grant = grant - lag(grant)
  ) |>
  ungroup() |>
  filter(!is.na(d_scrap), !is.na(d_grant))

fd_model <- feols(
  d_scrap ~ d_grant,
  data = jtrain_diff,
  vcov = ~fcode
)

etable(fd_model)
                          fd_model
Dependent Var.:            d_scrap
                                  
Constant        -0.6983** (0.2613)
d_grant          -0.4516. (0.2397)
_______________ __________________
S.E.: Clustered          by: fcode
Observations                   108
R2                         0.01859
Adj. R2                    0.00933
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
jtrain_diff_py = jtrain_py.sort_values(["fcode", "year"]).copy()
jtrain_diff_py["d_scrap"] = (
    jtrain_diff_py.groupby("fcode")["scrap"].diff()
)
jtrain_diff_py["d_grant"] = (
    jtrain_diff_py.groupby("fcode")["grant"].diff()
)
jtrain_diff_py = jtrain_diff_py.dropna(
    subset=["d_scrap", "d_grant"]
)

fd_model_py = pf.feols(
    "d_scrap ~ d_grant",
    data=jtrain_diff_py,
    vcov={"CRV1": "fcode"},
)

fd_model_py.summary()
###

Estimation:  OLS
Dep. var.: d_scrap, Fixed effects: 0
Inference:  CRV1
Observations:  108

| Coefficient   |   Estimate |   Std. Error |   t value |   Pr(>|t|) |   2.5% |   97.5% |
|:--------------|-----------:|-------------:|----------:|-----------:|-------:|--------:|
| Intercept     |     -0.698 |        0.261 |    -2.673 |      0.010 | -1.222 |  -0.174 |
| d_grant       |     -0.452 |        0.240 |    -1.884 |      0.065 | -0.932 |   0.029 |
---
RMSE: 2.166 R2: 0.019 

The FD slope is

\[ \hat\beta_{\mathrm{FD}}=-0.452, \qquad SE_{\text{cluster(firm)}}=0.240. \]

The regression has 108 observations: two changes for each of the 54 firms. The intercept, \(-0.698\), is retained and can represent a common linear trend in the level of scrap.

b) Interpretation

A change from no grant last year to grant receipt this year has \(\Delta\text{grant}=1\). The estimate associates that transition with a 0.452-point larger decline in the scrap rate than when grant status is unchanged. A change from grant to no grant has \(\Delta\text{grant}=-1\); the fitted contribution of that transition reverses sign.

This is still an association unless the identifying assumptions hold. The coefficient is not necessarily the immediate causal effect of switching grant status.

c) What the comparison can and cannot show

The one-way FE estimate is \(-0.753\) and the FD estimate is \(-0.452\). Both use within-firm changes, but this numerical comparison is not a test of strict exogeneity. Strict exogeneity is sufficient for consistency of both estimators in the static model; it does not require their finite-sample estimates to be equal when \(T>2\). Conversely, feedback could bias both estimates in the same direction and leave them looking similar.

FE and FD can differ because:

  • they combine the two available changes per firm differently;
  • differencing can magnify measurement error;
  • the level errors may be serially correlated;
  • the available within variation is limited, so sampling variation can be substantial.

Model misspecification is another possibility, but the coefficient comparison alone cannot identify which explanation is responsible.

d) Relative efficiency

FE is generally relatively attractive when the level errors have weak serial correlation. If level errors are serially independent, adjacent differenced errors mechanically have correlation \(-0.5\), which can make FD inefficient.

FD can be relatively attractive when level errors are highly persistent, such as near a random walk, because differencing removes much of that persistence. However, differencing may also magnify measurement error and discard useful longer-run variation.

Efficiency concerns the variance of an estimator under a maintained model. It does not establish identification, and the estimate with the preferred sign or smallest reported \(p\)-value is not thereby the right estimator. The economic setting, identifying variation, error persistence, measurement quality, and precision all matter.

5. Audit the claims

  1. Incorrect. Firm FE control for characteristics that are constant within a firm. They do not automatically control for time-varying confounders, feedback, reverse causality, measurement error, or differential trends. Causal interpretation still requires an identification argument.

  2. Incorrect. A time-invariant management score is perfectly collinear with the firm effects. Its coefficient cannot be separately estimated in a standard firm-FE model.

  3. Incorrect. Similarity is a useful descriptive robustness comparison, but it does not validate strict exogeneity. The same feedback process can bias both estimators, and strict exogeneity does not require identical finite-sample estimates when \(T>2\).

  4. Incorrect. Clustering changes estimated uncertainty under within-firm dependence. It does not eliminate correlation between the regressor and the error and cannot repair feedback bias.

  5. Correct, for matching specifications and an identified slope. With two periods, demeaned observations are rescaled first differences. With more than two periods, FE and FD weight and combine changes differently, so their slopes need not coincide.

Self-study

6. What survives demeaning?

(a) Years of schooling. Pooled OLS can estimate it. Worker FE cannot: the variable equals its own worker mean in every year, so demeaning turns it into a column of zeros. Adding year effects changes nothing.

(b) The national unemployment rate. Pooled OLS and worker FE can both estimate it, because it varies over time and the within-worker deviations are non-zero. Adding year effects removes it, since the variable takes a single value per year and is perfectly collinear with the year dummies.

(c) Union membership. All three specifications can estimate it, provided some workers actually change status during the sample. With worker FE the coefficient is identified only by those switchers.

(d) Tenure. Pooled OLS and worker FE can estimate it. Under worker and year effects it is identified only if tenure varies across workers within the same year, which requires job changes or different start dates. If tenure rose by exactly one for every worker in every year, its within-worker deviation would be a pure function of \(t\) and therefore collinear with the year effects.

(e) Because a regressor that takes one value per year lies in the space spanned by the year dummies. The year effects absorb every common time shock, so no independent variation is left to attribute to that variable.

(f) It is true that worker fixed effects remove the influence of schooling, and of every other permanent worker characteristic, from the estimation of the remaining coefficients: those coefficients are no longer contaminated by time-invariant confounding. It is not true that the return to schooling has been estimated. Schooling has no within-worker variation here, so its own effect is absorbed into \(\alpha_i\) and cannot be separated from it.

7. Why keep the intercept in a first-difference regression?

(a) Writing the model at \(t\) and \(t-1\) and subtracting,

\[ y_{it}-y_{i,t-1} =(\alpha_i-\alpha_i)+g\bigl(t-(t-1)\bigr) +\beta(x_{it}-x_{i,t-1})+(u_{it}-u_{i,t-1}), \]

so

\[ \Delta y_{it}=g+\beta\Delta x_{it}+\Delta u_{it}. \]

The unit effect disappears, and the common trend survives as the constant.

(b) Regressing \(\Delta y\) on \(\Delta x\) through the origin imposes \(g=0\): it assumes there is no common linear trend in the levels. If \(g\neq0\) and \(E(\Delta x)\neq0\), the omitted constant is an omitted regressor that is correlated with \(\Delta x\) in the sample, and the usual omitted-variable-bias reasoning applies: \(\hat\beta\) is pulled in the direction of \(\operatorname{sign}(g)\times\operatorname{sign}(E(\Delta x))\). A general rise in the outcome is then misattributed to a regressor that also happens to be rising.

(c) With \(y_{it}=\alpha_i+g_it+\beta x_{it}+u_{it}\), first differencing gives

\[ \Delta y_{it}=g_i+\beta\Delta x_{it}+\Delta u_{it}. \]

A unit-specific constant remains, so first differencing removes the level effect \(\alpha_i\) but not the trend \(g_i\). Differencing a second time removes it, as does including unit-specific linear trends in the levels or FE specification. Either way, the identifying variation becomes changes in the growth of \(x\), which is demanding of the data.

(d) A remaining \(g_i\) that is correlated with \(\Delta x_{it}\) makes the transformed regressor correlated with the transformed error, which biases \(\hat\beta\). Clustering changes only the estimated variance of \(\hat\beta\) around whatever it converges to. This is the identification-versus-inference distinction: a standard-error choice cannot repair a misspecified conditional mean.

Takeaways

What should you be able to do now?

  1. Separate between-unit and within-unit variation in a panel, and say which comparison a given estimator uses.
  2. Demean and first-difference a small panel by hand, and compute the resulting FE and FD slopes.
  3. Estimate FE and FD models in R or Python, absorbing unit effects and clustering standard errors at the level at which the regressor varies.
  4. State strict exogeneity and explain concretely why feedback from past outcomes violates it and why fixed effects do not repair it.
  5. Distinguish an identification problem from an inference problem, and say what fixed effects, differencing, and clustering each do and do not fix.