Fixed effects: training in a worker-firm panel¶
examples/worker_firm_panel.py
estimates the effect of a training program on wages in a simulated panel of workers and
firms (34,137 worker-years, from hdfe-stream’s simulate_akm). Every worker and every
firm has a lasting effect on the wage, and better workers tend to work at better firms.
The program is likelier for better workers and at better firms, so who is treated depends
on the fixed effects. The effect depends on tenure and hours, and is 0.2887 on average, so the
estimates can be checked against it.
Ignoring the fixed effects¶
fs.causal_forest("log_wage ~ enrolled | tenure + hours", path).average_treatment_effect()
│ ATE ┆ 0.893751 ┆ 0.006019 ┆ 148.493732 ┆ 0.0 │
The estimate is three times the truth: the treated are the workers and firms with high wages anyway.
With fixed effects¶
fml = "log_wage ~ enrolled | tenure + hours | worker_id + firm_id"
fit = fs.causal_forest(fml, path, seed=1)
print(fit.average_treatment_effect().summary_text())
vcov: iid
obs: 34,137
│ ATE ┆ 0.283307 ┆ 0.004394 ┆ 64.482881 ┆ 0.0 │
The third part of the formula names the fixed effects. The forest centers wages and enrollment on the features and the worker and firm effects together, by backfitting: a forest and the group effects take turns until the effects stop changing. The estimate is within 1.2 standard errors of the truth.
for which, bf in fit.backfit.items():
print(which, bf["iterations"], bf["converged"], bf["stopped"])
y 2 True tolerance
w 2 True tolerance
Both centering steps converged in two rounds. Fixed effects says what the tolerance means and what to do if backfitting does not converge.
Linear centering¶
fast = fs.causal_forest(fml, path, nuisance="linear", seed=1)
│ ATE ┆ 0.283771 ┆ 0.004413 ┆ 64.309956 ┆ 0.0 │
nuisance="linear" removes the fixed effects and a linear function of the features with a
single hdfe-stream regression instead of forests. Here the outcome is close to linear in the
features, so the answer is nearly the same, and the step is much faster. When the outcome
depends on the features in nonlinear ways, the forest centering is better.
Clustering by worker¶
A worker’s years are not independent. cluster="worker_id" samples whole workers into each
tree and clusters the standard error:
clustered = fs.causal_forest(fml, path, cluster="worker_id", seed=1)
vcov: CRV1:worker_id
clusters: worker_id 4,000
│ ATE ┆ 0.283101 ┆ 0.004661 ┆ 60.737659 ┆ 0.0 │
The standard error is 6 percent larger, so the years’ dependence matters a little here.
The estimated effects have a correlation of 0.87 with the true ones (the effect is a small function of tenure and hours against noise in the wage).
fit.plot("heterogeneity", feature="tenure")