Panel.Estimand­Characterization.Flexible­DIDMundlak

Wooldridge's extended TWFE: the equivalence of pooled OLS with saturated interactions and imputation-style estimands.

DID 26 core · 6 supporting This file provides finite-cell primitives for Wooldridge-style flexible imputation, pooled least squares, and extended two-way fixed effects difference-in-differences estimands. ★ recovers_target_Y0★ thetaPOLS_eq_imputationTheta★ thetaETWFE_eq_imputationTheta★ flexible_did_cell_characterization★ flexible_did_aggregate_characterization★ flexible_did_scaffold_characterization

Wooldridge Flexible DID Cells

This file provides finite-cell primitives for Wooldridge-style flexible imputation, pooled least squares, and extended two-way fixed effects difference-in-differences estimands. It defines staggered-adoption cell means, support conditions, untreated-outcome regressions, normal-equation-based POLS/ETWFE coefficients, and aggregate ATT quantities. The main public theorem is flexible_did_scaffold_characterization, the finite-cell characterization, with cell and aggregate components available as flexible_did_cell_characterization and flexible_did_aggregate_characterization.

structure StaggeredATTCells reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Finite staggered-adoption cell system: cohort shares and within-cohort covariate weights over treated and untreated cohort-time cells, with cell-level means of the untreated and cohort-specific treated potential outcomes. It requires that every treated cell's cohort has positive share, that the covariate weights are nonnegative and sum to one within each cohort, and that the observed cell mean coincides with the treated mean on treated cells and with the untreated mean on untreated cells.

Definition (Lean source)
Cohort Time Covar :
Type*
Fintype Cohort
Fintype Time
Fintype Covar
cohortShare :
Cohort → ℝ
covarWeight :
Cohort → Covar → ℝ
treatedCell :
Cohort → Time → Prop
untreatedCell :
Cohort → Time → Prop
Y0Mean :
Cohort → Time → Covar → ℝ
YgMean :
Cohort → Time → Covar → ℝ
observedMean :
Cohort → Time → Covar → ℝ
cohortShare_pos_on_treated :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
treatedCell g t
then
0 < cohortShare g
covarWeight_nonneg :
∀ g c, 0 ≤ covarWeight g c
covarWeight_sum_one :
∀ g, ∑ c, covarWeight g c = 1
consistency_treated :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
treatedCell g t
then
∀ c, observedMean g t c = YgMean g t c
consistency_untreated :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
untreatedCell g t
then
∀ c, observedMean g t c = Y0Mean g t c
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:37
def treatedCells reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

Treated cohort-time support set C_tr.

Definition (Lean source)
noncomputable def treatedCells (P : StaggeredATTCells Cohort Time Covar) : Finset (Cohort × Time) := (Finset.univ : Finset (Cohort × Time)).filter (fun gt => P.treatedCell gt.1 gt.2)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells.treatedCells · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:73 · uses StaggeredATTCells
def untreatedCells reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

Untreated cohort-time design set used to fit the untreated-outcome regression (the support of the weighted projection that produces m0).

Definition (Lean source)
noncomputable def untreatedCells (P : StaggeredATTCells Cohort Time Covar) : Finset (Cohort × Time) := (Finset.univ : Finset (Cohort × Time)).filter (fun gt => P.untreatedCell gt.1 gt.2)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells.untreatedCells · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:79 · uses StaggeredATTCells
def tauCell reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

ATT cell τ_gt, averaged over baseline covariate cells within cohort.

Definition (Lean source)
noncomputable def tauCell (P : StaggeredATTCells Cohort Time Covar) (g : Cohort) (t : Time) : ℝ := ∑ c, P.covarWeight g c * (P.YgMean g t c - P.Y0Mean g t c)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells.tauCell · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:85 · uses StaggeredATTCells
def tauAgg reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

Aggregate ATT for requested finite treated-cell weights.

Definition (Lean source)
noncomputable def tauAgg (P : StaggeredATTCells Cohort Time Covar) (a : Cohort → Time → ℝ) : ℝ := ∑ gt ∈ P.treatedCells, a gt.1 gt.2 * P.tauCell gt.1 gt.2
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells.tauAgg · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:90 · uses StaggeredATTCells
structure AggregateWeights reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Nonnegative aggregate weights summing to one on the target treated cells.

Definition (Lean source)
P :
StaggeredATTCells Cohort Time Covar
weight :
Cohort → Time → ℝ
nonneg_on_treated :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
P.treatedCell g t
then
0 ≤ weight g t
sum_treated :
gt ∈ P.treatedCells, weight gt.1 gt.2 = 1
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.AggregateWeights · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:97 · uses StaggeredATTCells
def NoAnticipation reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

No anticipation: before adoption, the cohort-g potential outcome equals the untreated potential outcome. Here untreatedCell marks the relevant pre-treatment / not-yet-treated observations.

Definition (Lean source)
def NoAnticipation (P : StaggeredATTCells Cohort Time Covar) : Prop := ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, P.untreatedCell g t → ∀ c, P.YgMean g t c = P.Y0Mean g t c
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.NoAnticipation · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:104 · uses StaggeredATTCells
def ConditionalParallelTrendsAdditive reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Conditional parallel trends, represented by the equivalent additive untreated mean form m0(g,t,c) = α(g,c) + λ(t,c).

Definition (Lean source)
def ConditionalParallelTrendsAdditive (P : StaggeredATTCells Cohort Time Covar) : Prop := ∃ α : Cohort → Covar → ℝ, ∃ lam : Time → Covar → ℝ, ∀ g t c, P.Y0Mean g t c = α g c + lam t c
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ConditionalParallelTrendsAdditive · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:111 · uses StaggeredATTCells
def IsCellAdditive reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

An additive function d(g,t,c) = γ(g,c) + δ(t,c) of the cohort/time/covariate cell, the difference class used to compare two additive untreated-mean representations.

Definition (Lean source)
def IsCellAdditive (d : Cohort → Time → Covar → ℝ) : Prop := ∃ γ : Cohort → Covar → ℝ, ∃ δ : Time → Covar → ℝ, ∀ g t c, d g t c = γ g c + δ t c
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.IsCellAdditive · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:118
def UntreatedDesignIdentifies reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Connected untreated design and full-rank identification condition.

Definition (Lean source)
def UntreatedDesignIdentifies (P : StaggeredATTCells Cohort Time Covar) : Prop := ∀ d : Cohort → Time → Covar → ℝ, IsCellAdditive (Cohort := Cohort) d → (∀ ⦃g : Cohort⦄ ⦃t : Time⦄, P.untreatedCell g t → ∀ c, d g t c = 0) → ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, P.treatedCell g t → ∀ c, d g t c = 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.UntreatedDesignIdentifies · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:125 · uses StaggeredATTCells
structure SaturatedUntreatedRegression reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

A finite-cell weighted least-squares fit of the untreated-outcome mean for a staggered cell design P, restricted to the untreated observations. It bundles a fitted untreated-outcome mean that is additive in cohort and time given the covariate cell, projection weights that are strictly positive on the untreated design, the requirement that the fit solves the covariate/cell-weighted normal equations against every additive test function, summed over the untreated design, full-rank identification of the additive class from vanishing on the untreated design alone, and a positive cohort share on every treated cell.

Definition (Lean source)
P :
StaggeredATTCells Cohort Time Covar
m0 :
Cohort → Time → Covar → ℝ
additive :
∃ α : Cohort → Covar → ℝ, ∃ lam : Time → Covar → ℝ, ∀ g t c, m0 g t c = α g c + lam t c
Nonnegative covariate/cell weights of the untreated-only projection.
untreatedWeight :
Cohort → Time → Covar → ℝ
The projection weights are strictly positive on the untreated design (positive probability of each untreated observation cell).
untreatedWeight_pos :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
P.untreatedCell g t
then
∀ c, 0 < untreatedWeight g t c
Finite-cell projection origin of `m0`: `m0` solves the weighted least-squares normal equations for the observed outcome on the additive class `H0`, using only untreated observations: against every additive test function the covariate/cell-weighted residual `observedMean − m0` over the untreated design vanishes.
untreatedNormalEq :
∀ d : Cohort → Time → Covar → ℝ
if
IsCellAdditive (Cohort := Cohort) d
then
gt ∈ P.untreatedCells, ∑ c, untreatedWeight gt.1 gt.2 c * (P.observedMean gt.1 gt.2 c - m0 gt.1 gt.2 c) * d gt.1 gt.2 c
= 0
design_identifies :
target_cell_support :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
P.treatedCell g t
then
0 < P.cohortShare g
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:137 · uses StaggeredATTCells
structure UntreatedFitWitness reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

The part of an untreated-regression witness needed to prove exact fit on the untreated design.

Definition (Lean source)
P :
StaggeredATTCells Cohort Time Covar
m0 :
Cohort → Time → Covar → ℝ
additive :
IsCellAdditive (Cohort := Cohort) m0
untreatedWeight :
Cohort → Time → Covar → ℝ
untreatedWeight_pos :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
P.untreatedCell g t
then
∀ c, 0 < untreatedWeight g t c
untreatedNormalEq :
∀ d : Cohort → Time → Covar → ℝ
if
IsCellAdditive (Cohort := Cohort) d
then
gt ∈ P.untreatedCells, ∑ c, untreatedWeight gt.1 gt.2 c * (P.observedMean gt.1 gt.2 c - m0 gt.1 gt.2 c) * d gt.1 gt.2 c
= 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.UntreatedFitWitness · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:187 · uses StaggeredATTCells
def toUntreatedFitWitness reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression

Forget the target-support and design-identification fields that are not needed for exact fit on untreated cells.

Definition (Lean source)
def SaturatedUntreatedRegression.toUntreatedFitWitness {P : StaggeredATTCells Cohort Time Covar} (S : SaturatedUntreatedRegression P) : UntreatedFitWitness P where m0 := S.m0 additive := S.additive untreatedWeight := S.untreatedWeight untreatedWeight_pos := S.untreatedWeight_pos untreatedNormalEq := S.untreatedNormalEq
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression.toUntreatedFitWitness · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:203 · uses SaturatedUntreatedRegression , StaggeredATTCells , UntreatedFitWitness
theorem recovers_target_Y0 reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression

Saturated untreated regression recovers the untreated potential outcome on treated cells. If no anticipation holds: the treated and untreated potential-outcome means agree on every cell in the untreated-outcome regression's design and conditional parallel trends holds — the mean untreated potential outcome admits an additive cohort/time fixed-effects representation given covariates, then on any treated cohort-time cell (g,t) covered by the saturated untreated regression S, the fitted value S.m0 g t c equals the mean untreated potential outcome Y0Mean g t c, for every covariate cell c.

Formal statement
P :
StaggeredATTCells Cohort Time Covar
hNA :
NoAnticipation P
g :
Cohort
t :
Time
hgt :
P.treatedCell g t
c :
Covar
S.m0 g t c = P.Y0Mean g t c
Proof (Lean source)
theorem recovers_target_Y0 {P : StaggeredATTCells Cohort Time Covar} (S : SaturatedUntreatedRegression P) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) ⦃g : Cohort⦄ ⦃t : Time⦄ (hgt : P.treatedCell g t) (c : Covar) : S.m0 g t c = P.Y0Mean g t c := by classical obtain ⟨αm, lamm, hm⟩ := S.additive obtain ⟨αy, lamy, hy⟩ := id hCPT -- The difference of the two additive representations. set d : Cohort → Time → Covar → ℝ := fun g t c => S.m0 g t c - P.Y0Mean g t c with hd have hd_add : IsCellAdditive (Cohort := Cohort) d := by refine ⟨fun g c => αm g c - αy g c, fun t c => lamm t c - lamy t c, ?_⟩ intro g t c simp only [hd, hm, hy]; ring have hd_untreated : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, P.untreatedCell g t → ∀ c, d g t c = 0 := by intro g t hut c have h1 : S.m0 g t c = P.Y0Mean g t c := by have hfit := SaturatedUntreatedRegression.untreatedFit S.toUntreatedFitWitness hNA hCPT hut c rw [show S.m0 g t c = P.YgMean g t c by simpa [SaturatedUntreatedRegression.toUntreatedFitWitness] using hfit, hNA hut c] simp [hd, h1] have hzero : d g t c = 0 := S.design_identifies d hd_add hd_untreated hgt c have := sub_eq_zero.mp (by simpa [hd] using hzero) exact this
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression.recovers_target_Y0 · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:294 · uses ConditionalParallelTrendsAdditive , NoAnticipation , SaturatedUntreatedRegression , StaggeredATTCells
def imputationTheta reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Imputation residual mean for a treated cohort-time cell.

Definition (Lean source)
noncomputable def imputationTheta (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (g : Cohort) (t : Time) : ℝ := ∑ c, P.covarWeight g c * (P.observedMean g t c - S.m0 g t c)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.imputationTheta · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:341 · uses SaturatedUntreatedRegression , StaggeredATTCells
def cellResidualNormalEq reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Finite-cell residual normal equation for a cell coefficient. With baseline-covariate weights summing to one inside cohort g, this pins down the unique coefficient as the imputation residual mean.

Definition (Lean source)
def cellResidualNormalEq (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (theta : ℝ) (g : Cohort) (t : Time) : Prop := ∑ c, P.covarWeight g c * (P.observedMean g t c - S.m0 g t c - theta) = 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.cellResidualNormalEq · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:351 · uses SaturatedUntreatedRegression , StaggeredATTCells
def cellIndicator reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Saturated treated-cell indicator 1{(g',t') = (g,t)} (the POLS/ETWFE treated regressor for cell (g,t)).

Definition (Lean source)
noncomputable def cellIndicator [DecidableEq Cohort] [DecidableEq Time] (g : Cohort) (t : Time) : Cohort → Time → ℝ := fun g' t' => if g' = g ∧ t' = t then 1 else 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.cellIndicator · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:390
structure FlexibleDIDEstimands reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

On top of a staggered-cell design P and its saturated untreated-outcome regression S, this structure packages three families of treated-cell coefficients — an imputation coefficient, a pooled-least-squares (POLS) coefficient, and an extended two-way-fixed-effects (ETWFE) coefficient — together with the conditions pinning them down: on every treated cell the imputation coefficient equals the covariate-weighted imputation residual mean, and the POLS and ETWFE coefficients each solve the finite-cell covariate-weighted residual normal equation.

Definition (Lean source)
P :
StaggeredATTCells Cohort Time Covar
thetaImp :
Cohort → Time → ℝ
thetaPOLS :
Cohort → Time → ℝ
thetaETWFE :
Cohort → Time → ℝ
thetaImp_eq_imputation :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
P.treatedCell g t
then
thetaImp g t = imputationTheta P S g t
pols_cell_normalEq :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
P.treatedCell g t
then
cellResidualNormalEq P S (thetaPOLS g t) g t
etwfe_cell_normalEq :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
P.treatedCell g t
then
cellResidualNormalEq P S (thetaETWFE g t) g t
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.FlexibleDIDEstimands · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:443 · uses SaturatedUntreatedRegression , StaggeredATTCells
theorem thetaPOLS_eq_imputationTheta reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.FlexibleDIDEstimands

POLS cell coefficients equal imputation. On any treated cohort-time cell (g,t), the flexible POLS cell coefficient equals the imputation residual mean at that cell.

Formal statement
P :
StaggeredATTCells Cohort Time Covar
g :
Cohort
t :
Time
hgt :
P.treatedCell g t
E.thetaPOLS g t = imputationTheta P S g t
Proof (Lean source)
theorem thetaPOLS_eq_imputationTheta (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) : E.thetaPOLS g t = imputationTheta P S g t := cellResidualNormalEq_eq_imputationTheta P.observedMean S.m0 P.covarWeight P.covarWeight_sum_one (E.pols_cell_normalEq hgt)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.FlexibleDIDEstimands.thetaPOLS_eq_imputationTheta · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:477 · uses FlexibleDIDEstimands , SaturatedUntreatedRegression , StaggeredATTCells , imputationTheta
theorem thetaETWFE_eq_imputationTheta reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.FlexibleDIDEstimands

ETWFE cell coefficients equal imputation. On any treated cohort-time cell (g,t), the extended two-way-fixed-effects (ETWFE) cell coefficient equals the imputation residual mean at that cell.

Formal statement
P :
StaggeredATTCells Cohort Time Covar
g :
Cohort
t :
Time
hgt :
P.treatedCell g t
E.thetaETWFE g t = imputationTheta P S g t
Proof (Lean source)
theorem thetaETWFE_eq_imputationTheta (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) : E.thetaETWFE g t = imputationTheta P S g t := cellResidualNormalEq_eq_imputationTheta P.observedMean S.m0 P.covarWeight P.covarWeight_sum_one (E.etwfe_cell_normalEq hgt)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.FlexibleDIDEstimands.thetaETWFE_eq_imputationTheta · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:492 · uses FlexibleDIDEstimands , SaturatedUntreatedRegression , StaggeredATTCells , imputationTheta
def psiImp reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Aggregate estimand for the imputation coefficients.

Definition (Lean source)
noncomputable def psiImp (P : StaggeredATTCells Cohort Time Covar) {S : SaturatedUntreatedRegression P} (E : FlexibleDIDEstimands P S) (a : Cohort → Time → ℝ) : ℝ := ∑ gt ∈ P.treatedCells, a gt.1 gt.2 * E.thetaImp gt.1 gt.2
def psiPOLS reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Aggregate estimand for the flexible POLS coefficients.

Definition (Lean source)
noncomputable def psiPOLS (P : StaggeredATTCells Cohort Time Covar) {S : SaturatedUntreatedRegression P} (E : FlexibleDIDEstimands P S) (a : Cohort → Time → ℝ) : ℝ := ∑ gt ∈ P.treatedCells, a gt.1 gt.2 * E.thetaPOLS gt.1 gt.2
def psiETWFE reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Aggregate estimand for the flexible ETWFE coefficients.

Definition (Lean source)
noncomputable def psiETWFE (P : StaggeredATTCells Cohort Time Covar) {S : SaturatedUntreatedRegression P} (E : FlexibleDIDEstimands P S) (a : Cohort → Time → ℝ) : ℝ := ∑ gt ∈ P.treatedCells, a gt.1 gt.2 * E.thetaETWFE gt.1 gt.2
theorem flexible_did_cell_characterization reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Cell-level characterization: imputation, POLS, and ETWFE agree with the ATT cell. If no anticipation holds, conditional parallel trends holds — the mean untreated potential outcome admits an additive cohort/time fixed-effects representation given covariates, and (g,t) is a treated cohort-time cell covered by the untreated-regression witness S and the imputation/POLS/ETWFE estimands E, then the imputation, POLS, and ETWFE cell coefficients at (g,t) all equal the ATT cell τ_gt.

Formal statement
P :
StaggeredATTCells Cohort Time Covar
hNA :
NoAnticipation P
g :
Cohort
t :
Time
hgt :
P.treatedCell g t
E.thetaImp g t = P.tauCell g t ∧
E.thetaPOLS g t = P.tauCell g t ∧
E.thetaETWFE g t = P.tauCell g t
Proof (Lean source)
theorem flexible_did_cell_characterization (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) : E.thetaImp g t = P.tauCell g t ∧ E.thetaPOLS g t = P.tauCell g t ∧ E.thetaETWFE g t = P.tauCell g t := by have himp : E.thetaImp g t = P.tauCell g t := imputationTheta_eq_tauCell P S E hNA hCPT hgt have hpols : E.thetaPOLS g t = P.tauCell g t := by rw [E.pols_cell_eq_imputation P S hgt, himp] have hetwfe : E.thetaETWFE g t = P.tauCell g t := by rw [E.etwfe_cell_eq_pols P S hgt, hpols] exact ⟨himp, hpols, hetwfe⟩
theorem flexible_did_aggregate_characterization reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Aggregate characterization: every weighting of imputation, POLS, and ETWFE equals the weighted ATT aggregate. If no anticipation holds and conditional parallel trends holds — the mean untreated potential outcome admits an additive cohort/time fixed-effects representation given covariates, then for any treated-cell weighting function a, the a-weighted aggregates of the imputation, POLS, and ETWFE cell estimands all equal the a-weighted ATT aggregate.

Formal statement
P :
StaggeredATTCells Cohort Time Covar
hNA :
NoAnticipation P
a :
Cohort → Time → ℝ
psiImp P E a = P.tauAgg a ∧ psiPOLS P E a = P.tauAgg a ∧ psiETWFE P E a = P.tauAgg a
Proof (Lean source)
theorem flexible_did_aggregate_characterization (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) (a : Cohort → Time → ℝ) : psiImp P E a = P.tauAgg a ∧ psiPOLS P E a = P.tauAgg a ∧ psiETWFE P E a = P.tauAgg a := by classical have hcell : ∀ gt ∈ P.treatedCells, E.thetaImp gt.1 gt.2 = P.tauCell gt.1 gt.2 ∧ E.thetaPOLS gt.1 gt.2 = P.tauCell gt.1 gt.2 ∧ E.thetaETWFE gt.1 gt.2 = P.tauCell gt.1 gt.2 := by intro gt hgt_mem have hgt : P.treatedCell gt.1 gt.2 := by simpa [StaggeredATTCells.treatedCells] using hgt_mem exact flexible_did_cell_characterization P S E hNA hCPT hgt constructor · unfold psiImp StaggeredATTCells.tauAgg refine Finset.sum_congr rfl ?_ intro gt hgt rw [(hcell gt hgt).1] constructor · unfold psiPOLS StaggeredATTCells.tauAgg refine Finset.sum_congr rfl ?_ intro gt hgt rw [(hcell gt hgt).2.1] · unfold psiETWFE StaggeredATTCells.tauAgg refine Finset.sum_congr rfl ?_ intro gt hgt rw [(hcell gt hgt).2.2]
theorem flexible_did_scaffold_characterization reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Headline finite-cell characterization (Wooldridge, Theorem B). If no anticipation holds: the treated and untreated potential-outcome means agree on every cell in the untreated-outcome regression's design and conditional parallel trends holds — the mean untreated potential outcome admits an additive cohort/time fixed-effects representation given covariates, then, given the saturated untreated regression S and the POLS/ETWFE finite-cell residual normal equations carried by E, on every treated cohort-time cell the flexible imputation, POLS, and ETWFE estimands all equal the ATT cell, and consequently every treated-cell weighted aggregate of the three estimands equals the correspondingly weighted ATT aggregate.

Formal statement
P :
StaggeredATTCells Cohort Time Covar
hNA :
NoAnticipation P
(∀ ⦃g : Cohort⦄ ⦃t : Time⦄, P.treatedCell g t → E.thetaImp g t = P.tauCell g t ∧ E.thetaPOLS g t = P.tauCell g t ∧ E.thetaETWFE g t = P.tauCell g t) ∧
(∀ a : Cohort → Time → ℝ, psiImp P E a = P.tauAgg a ∧ psiPOLS P E a = P.tauAgg a ∧ psiETWFE P E a = P.tauAgg a)
Proof (Lean source)
theorem flexible_did_scaffold_characterization (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) : (∀ ⦃g : Cohort⦄ ⦃t : Time⦄, P.treatedCell g t → E.thetaImp g t = P.tauCell g t ∧ E.thetaPOLS g t = P.tauCell g t ∧ E.thetaETWFE g t = P.tauCell g t) ∧ (∀ a : Cohort → Time → ℝ, psiImp P E a = P.tauAgg a ∧ psiPOLS P E a = P.tauAgg a ∧ psiETWFE P E a = P.tauAgg a) := by constructor · intro g t hgt exact flexible_did_cell_characterization P S E hNA hCPT hgt · intro a exact flexible_did_aggregate_characterization P S E hNA hCPT a
6 supporting declarations (lemmas, instances)
  • untreatedFit theorem — The weighted projection m0 reproduces the factual cohort-g outcome mean on every untreated cell.
    P :
    StaggeredATTCells Cohort Time Covar
    hNA :
    NoAnticipation P
    g :
    Cohort
    t :
    Time
    hgt :
    P.untreatedCell g t
    c :
    Covar
    S.m0 g t c = P.YgMean g t c
    Proof (Lean source)
    theorem untreatedFit {P : StaggeredATTCells Cohort Time Covar} (S : UntreatedFitWitness P) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) ⦃g : Cohort⦄ ⦃t : Time⦄ (hgt : P.untreatedCell g t) (c : Covar) : S.m0 g t c = P.YgMean g t c := by classical obtain ⟨αy, lamy, hy⟩ := hCPT obtain ⟨αm, lamm, hm⟩ := S.additive set d : Cohort → Time → Covar → ℝ := fun g t c => S.m0 g t c - P.Y0Mean g t c with hd have hd_add : IsCellAdditive (Cohort := Cohort) d := by refine ⟨fun g c => αm g c - αy g c, fun t c => lamm t c - lamy t c, ?_⟩ intro g t c simp only [hd, hm, hy]; ring have hne := S.untreatedNormalEq d hd_add -- The positively-weighted squared residual over the untreated design vanishes. have hsq : (∑ gt ∈ P.untreatedCells, ∑ c, S.untreatedWeight gt.1 gt.2 c * (d gt.1 gt.2 c) ^ 2) = 0 := by have hQR : (∑ gt ∈ P.untreatedCells, ∑ c, S.untreatedWeight gt.1 gt.2 c * (d gt.1 gt.2 c) ^ 2) + (∑ gt ∈ P.untreatedCells, ∑ c, S.untreatedWeight gt.1 gt.2 c * (P.observedMean gt.1 gt.2 c - S.m0 gt.1 gt.2 c) * d gt.1 gt.2 c) = 0 := by rw [← Finset.sum_add_distrib] refine Finset.sum_eq_zero ?_ intro gt hgt_mem have hut : P.untreatedCell gt.1 gt.2 := by simpa [StaggeredATTCells.untreatedCells] using hgt_mem rw [← Finset.sum_add_distrib] refine Finset.sum_eq_zero ?_ intro c _ have hobs : P.observedMean gt.1 gt.2 c = P.Y0Mean gt.1 gt.2 c := P.consistency_untreated hut c simp only [hd] rw [hobs]; ring linarith [hQR, hne] -- Extract the single untreated cell `(g,t)` and covariate `c`. have hmem : (g, t) ∈ P.untreatedCells := by simp only [StaggeredATTCells.untreatedCells, mem_filter, Finset.mem_univ, true_and] exact hgt have hrow_nonneg : ∀ gt ∈ P.untreatedCells, 0 ≤ ∑ c, S.untreatedWeight gt.1 gt.2 c * (d gt.1 gt.2 c) ^ 2 := by intro gt hgt_mem have hut : P.untreatedCell gt.1 gt.2 := by simpa [StaggeredATTCells.untreatedCells] using hgt_mem exact sum_nonneg fun c _ => mul_nonneg (le_of_lt (S.untreatedWeight_pos hut c)) (sq_nonneg _) have hrow := (Finset.sum_eq_zero_iff_of_nonneg hrow_nonneg).mp hsq (g, t) hmem have hcell_nonneg : ∀ c' ∈ (Finset.univ : Finset Covar), 0 ≤ S.untreatedWeight g t c' * (d g t c') ^ 2 := fun c' _ => mul_nonneg (le_of_lt (S.untreatedWeight_pos hgt c')) (sq_nonneg _) have hcell := (Finset.sum_eq_zero_iff_of_nonneg hcell_nonneg).mp hrow c (Finset.mem_univ c) have hw := S.untreatedWeight_pos hgt c have hd0 : d g t c = 0 := by have hsq0 : (d g t c) ^ 2 = 0 := (mul_eq_zero.mp hcell).resolve_left (ne_of_gt hw) exact pow_eq_zero_iff (by norm_num) |>.mp hsq0 have hm0 : S.m0 g t c = P.Y0Mean g t c := by have hh := hd0; simp only [hd] at hh; linarith rw [hm0]; exact (hNA hgt c).symm
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression.untreatedFit · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:216
  • cellResidualNormalEq_eq_imputationTheta theorem — A finite-cell residual normal equation identifies the coefficient with the imputation residual mean.
    outcome fitted :
    Cohort → Time → Covar → ℝ
    covarWeight :
    Cohort → Covar → ℝ
    covarWeight_sum_one :
    ∀ g, ∑ c, covarWeight g c = 1
    theta :
    g :
    Cohort
    t :
    Time
    :
    ∑ c, covarWeight g c * (outcome g t c - fitted g t c - theta) = 0
    theta = ∑ c, covarWeight g c * (outcome g t c - fitted g t c)
    Proof (Lean source)
    theorem cellResidualNormalEq_eq_imputationTheta (outcome fitted : Cohort → Time → Covar → ℝ) (covarWeight : Cohort → Covar → ℝ) (covarWeight_sum_one : ∀ g, ∑ c, covarWeight g c = 1) {theta : ℝ} {g : Cohort} {t : Time} (hθ : ∑ c, covarWeight g c * (outcome g t c - fitted g t c - theta) = 0) : theta = ∑ c, covarWeight g c * (outcome g t c - fitted g t c) := by have hsum : (∑ c, covarWeight g c * (outcome g t c - fitted g t c - theta)) = (∑ c, covarWeight g c * (outcome g t c - fitted g t c)) - (∑ c, covarWeight g c) * theta := by simp only [mul_sub, Finset.sum_sub_distrib, Finset.sum_mul] have hnormal : (∑ c, covarWeight g c * (outcome g t c - fitted g t c)) - theta = 0 := by calc (∑ c, covarWeight g c * (outcome g t c - fitted g t c)) - theta = (∑ c, covarWeight g c * (outcome g t c - fitted g t c)) - (∑ c, covarWeight g c) * theta := by rw [covarWeight_sum_one g] ring _ = ∑ c, covarWeight g c * (outcome g t c - fitted g t c - theta) := by rw [hsum] _ = 0 := hθ exact (sub_eq_zero.mp hnormal).symm
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.cellResidualNormalEq_eq_imputationTheta · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:360
  • cellIndicator_normalEq_eq_cellResidual theorem — Saturated block-diagonalization for treated-cell indicators.
    outcome fitted :
    Cohort → Time → Covar → ℝ
    covarWeight :
    Cohort → Covar → ℝ
    theta :
    g :
    Cohort
    t :
    Time
    (∑ g', ∑ t', ∑ c, cellIndicator g t g' t' * covarWeight g' c * (outcome g' t' c - fitted g' t' c - cellIndicator g t g' t' * theta) = 0)
    ↔ ∑ c, covarWeight g c * (outcome g t c - fitted g t c - theta) = 0
    Proof (Lean source)
    theorem cellIndicator_normalEq_eq_cellResidual [DecidableEq Cohort] [DecidableEq Time] (outcome fitted : Cohort → Time → Covar → ℝ) (covarWeight : Cohort → Covar → ℝ) (theta : ℝ) (g : Cohort) (t : Time) : (∑ g', ∑ t', ∑ c, cellIndicator g t g' t' * covarWeight g' c * (outcome g' t' c - fitted g' t' c - cellIndicator g t g' t' * theta) = 0) ↔ ∑ c, covarWeight g c * (outcome g t c - fitted g t c - theta) = 0 := by classical unfold cellIndicator -- The full saturated sum collapses to the single-cell residual sum, because -- the saturated indicator vanishes off cell `(g,t)`. have hcollapse : (∑ g', ∑ t', ∑ c, (if g' = g ∧ t' = t then (1 : ℝ) else 0) * covarWeight g' c * (outcome g' t' c - fitted g' t' c - (if g' = g ∧ t' = t then (1 : ℝ) else 0) * theta)) = ∑ c, covarWeight g c * (outcome g t c - fitted g t c - theta) := by rw [Finset.sum_eq_single g, Finset.sum_eq_single t] · refine Finset.sum_congr rfl ?_ intro c _ simp · intro t' _ ht' refine Finset.sum_eq_zero ?_ intro c _ simp [ht'] · intro hg; simp at hg · intro g' _ hg' refine Finset.sum_eq_zero ?_ intro t' _ refine Finset.sum_eq_zero ?_ intro c _ simp [hg'] · intro hg; simp at hg rw [hcollapse]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.cellIndicator_normalEq_eq_cellResidual · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:396
  • pols_cell_eq_imputation theorem — Compatibility alias: the POLS/imputation equality is now derived from the POLS normal equation, rather than stored as a field.
    P :
    StaggeredATTCells Cohort Time Covar
    g :
    Cohort
    t :
    Time
    hgt :
    P.treatedCell g t
    E.thetaPOLS g t = E.thetaImp g t
    Proof (Lean source)
    theorem pols_cell_eq_imputation (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) : E.thetaPOLS g t = E.thetaImp g t := by rw [E.thetaPOLS_eq_imputationTheta P S hgt, E.thetaImp_eq_imputation hgt]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.FlexibleDIDEstimands.pols_cell_eq_imputation · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:508
  • etwfe_cell_eq_pols theorem — Compatibility alias: ETWFE/POLS equality is now derived by solving both finite-cell normal equations, rather than stored as a field.
    P :
    StaggeredATTCells Cohort Time Covar
    g :
    Cohort
    t :
    Time
    hgt :
    P.treatedCell g t
    E.thetaETWFE g t = E.thetaPOLS g t
    Proof (Lean source)
    theorem etwfe_cell_eq_pols (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) : E.thetaETWFE g t = E.thetaPOLS g t := by rw [E.thetaETWFE_eq_imputationTheta P S hgt, E.thetaPOLS_eq_imputationTheta P S hgt]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.FlexibleDIDEstimands.etwfe_cell_eq_pols · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:518
  • imputationTheta_eq_tauCell theorem — Imputation recovers the ATT cell once the saturated untreated prediction equals the untreated potential-outcome mean in target cells.
    P :
    StaggeredATTCells Cohort Time Covar
    hNA :
    NoAnticipation P
    g :
    Cohort
    t :
    Time
    hgt :
    P.treatedCell g t
    E.thetaImp g t = P.tauCell g t
    Proof (Lean source)
    theorem imputationTheta_eq_tauCell (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) : E.thetaImp g t = P.tauCell g t := by rw [E.thetaImp_eq_imputation hgt] unfold imputationTheta StaggeredATTCells.tauCell refine Finset.sum_congr rfl ?_ intro c _hc rw [P.consistency_treated hgt c, S.recovers_target_Y0 hNA hCPT hgt c]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.imputationTheta_eq_tauCell · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:549
TWFE 8 core · 5 supporting This file formalizes the scalar-regressor finite balanced-panel version of Wooldridge's two-way fixed effects and two-way Mundlak equivalence. ★ twfe_twm_equivalence

Wooldridge Scalar TWFE and Mundlak

This file formalizes the scalar-regressor finite balanced-panel version of Wooldridge's two-way fixed effects and two-way Mundlak equivalence. It defines the scalar TWFE problem, coefficient, and normal equation, proves ScalarTWFEProblem.betaTWFE_normalEq and ScalarTWFEProblem.betaTWFE_unique, and then proves twfe_twm_equivalence and twfe_twm_optional_controls_invariant for coding-free two-way Mundlak fits.

structure ScalarTWFEProblem reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

A scalar two-way-fixed-effects regression problem on a finite balanced panel of units and time periods, given a scalar outcome and a scalar regressor, where the sum of squared double-demeaned regressor values is strictly positive — the scalar full-rank condition ensuring the two-way within estimator is well defined.

Definition (Lean source)
Unit Time :
Type*
Fintype Unit
Fintype Time
panel :
BalancedPanel Unit Time
Y :
Unit → Time → ℝ
X :
Unit → Time → ℝ
ddotX_ss_pos :
0 < ∑ i, ∑ t, (ddot X i t)^2
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:33
def twfeDenominator reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

Residualized-design denominator for scalar TWFE.

Definition (Lean source)
noncomputable def twfeDenominator (P : ScalarTWFEProblem Unit Time) : ℝ := ∑ i, ∑ t, (ddot P.X i t)^2
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.twfeDenominator · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:45 · uses ScalarTWFEProblem
def twfeNumerator reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

Residualized numerator using double-demeaned outcome and regressor.

Definition (Lean source)
noncomputable def twfeNumerator (P : ScalarTWFEProblem Unit Time) : ℝ := ∑ i, ∑ t, ddot P.X i t * ddot P.Y i t
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.twfeNumerator · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:49 · uses ScalarTWFEProblem
def betaTWFE reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

Population scalar TWFE coefficient from the double-demeaned normal equation.

Definition (Lean source)
noncomputable def betaTWFE (P : ScalarTWFEProblem Unit Time) : ℝ := P.twfeNumerator / P.twfeDenominator
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.betaTWFE · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:53 · uses ScalarTWFEProblem
def twfeNormalEq reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

Scalar TWFE normal equation after double demeaning.

Definition (Lean source)
def twfeNormalEq (P : ScalarTWFEProblem Unit Time) (β : ℝ) : Prop := ∑ i, ∑ t, ddot P.X i t * (ddot P.Y i t - ddot P.X i t * β) = 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.twfeNormalEq · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:58 · uses ScalarTWFEProblem
def IsTwoWayMundlakNuisance reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Two-way Mundlak nuisance span for a scalar regressor: constants, unit means of X, time means of X, optional time-constant controls Z_i, and optional time-only controls M_t.

Definition (Lean source)
def IsTwoWayMundlakNuisance (X : Unit → Time → ℝ) (Zvar : Z → Unit → ℝ) (Mvar : M → Time → ℝ) (h : Unit → Time → ℝ) : Prop := ∃ c γu γt : ℝ, ∃ ζ : Z → ℝ, ∃ μ : M → ℝ, ∀ i t, h i t = c + γu * unitMean X i + γt * timeMean X t + (∑ z, ζ z * Zvar z i) + (∑ m, μ m * Mvar m t)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.IsTwoWayMundlakNuisance · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:137
structure ScalarTWMFit reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

A scalar two-way Mundlak fit of the TWFE problem P against optional time-constant controls Zvar and time-only controls Mvar, stated by normal equations rather than by a particular coding of the nuisance regressors. It bundles a scalar coefficient on the regressor and a nuisance function lying in the two-way Mundlak span, subject to the pooled normal equation against the regressor and the pooled normal equation against every nuisance function in that span.

Definition (Lean source)
Zvar :
Z → Unit → ℝ
Mvar :
M → Time → ℝ
beta :
nuisance :
Unit → Time → ℝ
nuisance_mem :
IsTwoWayMundlakNuisance P.X Zvar Mvar nuisance
normal_X :
∑ i, ∑ t, P.X i t * (P.Y i t - P.X i t * beta - nuisance i t) = 0
normal_H :
∀ h : Unit → Time → ℝ
if
IsTwoWayMundlakNuisance P.X Zvar Mvar h
then
∑ i, ∑ t, h i t * (P.Y i t - P.X i t * beta - nuisance i t) = 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWMFit · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:163 · uses ScalarTWFEProblem
theorem twfe_twm_equivalence reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Wooldridge finite-panel scalar TWFE-two-way-Mundlak equivalence. For a scalar two-way-fixed-effects panel regression problem P with optional time-constant controls Zvar and time-only controls Mvar, given any pooled two-way Mundlak regression fit stated by its normal equations, that fit's coefficient on the regressor equals the two-way-fixed-effects coefficient.

Formal statement
Zvar :
Z → Unit → ℝ
Mvar :
M → Time → ℝ
fit :
ScalarTWMFit P Zvar Mvar
fit.beta = P.betaTWFE
Proof (Lean source)
theorem twfe_twm_equivalence (P : ScalarTWFEProblem Unit Time) (Zvar : Z → Unit → ℝ) (Mvar : M → Time → ℝ) (fit : ScalarTWMFit P Zvar Mvar) : fit.beta = P.betaTWFE := by let hres : Unit → Time → ℝ := fun i t => P.X i t - ddot P.X i t have hres_mem : IsTwoWayMundlakNuisance P.X Zvar Mvar hres := by refine ⟨-grandMean P.X, 1, 1, fun _ => 0, fun _ => 0, ?_⟩ intro i t dsimp [hres] rw [sub_ddot_eq_unitTimeProjection P.X i t] unfold unitTimeProjection simp ring have hYadd : IsUnitTimeAdditive (fun i t => P.Y i t - ddot P.Y i t) := by rw [show (fun i t => P.Y i t - ddot P.Y i t) = unitTimeProjection P.Y by funext i t exact sub_ddot_eq_unitTimeProjection P.Y i t] exact unitTimeProjection_additive P.Y have hYorth : ∑ i, ∑ t, ddot P.X i t * (P.Y i t - ddot P.Y i t) = 0 := by simpa [inner] using ddot_orthogonal_unit_time (lt_of_lt_of_le (by decide) P.panel.unit_card_ge_two) (lt_of_lt_of_le (by decide) P.panel.time_card_ge_two) P.X (fun i t => P.Y i t - ddot P.Y i t) hYadd have hfw := finite_residualized_coefficient_eq_of_normalEqs (fun h : Unit → Time → ℝ => IsTwoWayMundlakNuisance P.X Zvar Mvar h) (Y := P.Y) (D := P.X) (Yproj := fun i t => P.Y i t - ddot P.Y i t) (Ytilde := ddot P.Y) (Dproj := hres) (Dtilde := ddot P.X) (Hβ := fit.nuisance) (β := fit.beta) (by intro i t ring) (by intro i t dsimp [hres] ring) hres_mem fit.nuisance_mem (twfe_twm_residual_common P Zvar Mvar).2 (by simpa [inner] using hYorth) (by simpa [inner, pow_two] using P.ddotX_ss_pos) (by simpa [inner] using fit.normal_X) (by simpa [inner] using fit.normal_H hres hres_mem) simpa [ScalarTWFEProblem.betaTWFE, ScalarTWFEProblem.twfeNumerator, ScalarTWFEProblem.twfeDenominator, finiteResidualizedCoefficient, inner, pow_two] using hfw
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.twfe_twm_equivalence · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:198 · uses ScalarTWFEProblem , betaTWFE , ScalarTWMFit
5 supporting declarations (lemmas, instances)
  • betaTWFE_normalEq theorem — The closed-form coefficient satisfies the scalar TWFE normal equation by dividing through the positive residualized sum of squares.
    P.twfeNormalEq P.betaTWFE
    Proof (Lean source)
    theorem betaTWFE_normalEq (P : ScalarTWFEProblem Unit Time) : P.twfeNormalEq P.betaTWFE := by let A : ℝ := ∑ i, ∑ t, ddot P.X i t * ddot P.Y i t let B : ℝ := ∑ i, ∑ t, (ddot P.X i t)^2 have hden : B ≠ 0 := by dsimp [B] exact ne_of_gt P.ddotX_ss_pos have hfactor : ∀ c : ℝ, (∑ i, ∑ t, ddot P.X i t * (ddot P.X i t * c)) = B * c := by intro c dsimp [B] simp only [← mul_assoc, pow_two, Finset.sum_mul] unfold twfeNormalEq betaTWFE twfeNumerator twfeDenominator change ∑ i, ∑ t, ddot P.X i t * (ddot P.Y i t - ddot P.X i t * (A / B)) = 0 calc ∑ i, ∑ t, ddot P.X i t * (ddot P.Y i t - ddot P.X i t * (A / B)) = A - B * (A / B) := by dsimp [A] simp only [mul_sub, Finset.sum_sub_distrib] rw [hfactor] _ = 0 := by rw [div_eq_mul_inv] rw [show B * (A * B⁻¹) = A * (B * B⁻¹) by ring] rw [mul_inv_cancel₀ hden] ring
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.betaTWFE_normalEq · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:62
  • betaTWFE_unique theorem — Scalar full-rank uniqueness of the TWFE normal-equation solution.
    β :
    :
    P.twfeNormalEq β
    β = P.betaTWFE
    Proof (Lean source)
    theorem betaTWFE_unique (P : ScalarTWFEProblem Unit Time) {β : ℝ} (hβ : P.twfeNormalEq β) : β = P.betaTWFE := by unfold twfeNormalEq at hβ change β = (∑ i, ∑ t, ddot P.X i t * ddot P.Y i t) / (∑ i, ∑ t, (ddot P.X i t)^2) have hden : (∑ i, ∑ t, (ddot P.X i t)^2) ≠ 0 := ne_of_gt P.ddotX_ss_pos have hnormal : (∑ i, ∑ t, ddot P.X i t * ddot P.Y i t) - (∑ i, ∑ t, (ddot P.X i t)^2) * β = 0 := by calc (∑ i, ∑ t, ddot P.X i t * ddot P.Y i t) - (∑ i, ∑ t, (ddot P.X i t)^2) * β = ∑ i, ∑ t, ddot P.X i t * (ddot P.Y i t - ddot P.X i t * β) := by simp only [mul_sub, Finset.sum_sub_distrib] ring_nf simp only [pow_two, Finset.sum_mul] simp [mul_comm] _ = 0 := hβ have hnum : (∑ i, ∑ t, ddot P.X i t * ddot P.Y i t) = (∑ i, ∑ t, (ddot P.X i t)^2) * β := sub_eq_zero.mp hnormal calc β = ((∑ i, ∑ t, (ddot P.X i t)^2) * β) / (∑ i, ∑ t, (ddot P.X i t)^2) := by rw [div_eq_mul_inv] rw [show ((∑ i, ∑ t, (ddot P.X i t)^2) * β) * (∑ i, ∑ t, (ddot P.X i t)^2)⁻¹ = β * ((∑ i, ∑ t, (ddot P.X i t)^2) * (∑ i, ∑ t, (ddot P.X i t)^2)⁻¹) by ring] rw [mul_inv_cancel₀ hden, mul_one] _ = (∑ i, ∑ t, ddot P.X i t * ddot P.Y i t) / (∑ i, ∑ t, (ddot P.X i t)^2) := by rw [← hnum]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.betaTWFE_unique · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:94
  • mundlak_nuisance_unit_time theorem — Mundlak nuisance functions are unit/time additive, so optional time-constant and time-only controls lie inside the same orthogonality class.
    X :
    Unit → Time → ℝ
    Zvar :
    Z → Unit → ℝ
    Mvar :
    M → Time → ℝ
    h :
    Unit → Time → ℝ
    hh :
    IsUnitTimeAdditive h
    Proof (Lean source)
    theorem mundlak_nuisance_unit_time (X : Unit → Time → ℝ) (Zvar : Z → Unit → ℝ) (Mvar : M → Time → ℝ) {h : Unit → Time → ℝ} (hh : IsTwoWayMundlakNuisance X Zvar Mvar h) : IsUnitTimeAdditive h := by rcases hh with ⟨c, γu, γt, ζ, μ, hrep⟩ refine ⟨fun i => c + γu * unitMean X i + ∑ z, ζ z * Zvar z i, fun t => γt * timeMean X t + ∑ m, μ m * Mvar m t, ?_⟩ intro i t rw [hrep i t] ring
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.mundlak_nuisance_unit_time · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:149
  • twfe_twm_residual_common theorem — Residualizing the scalar regressor against the two-way Mundlak nuisance span leaves the same residual as double demeaning.
    Zvar :
    Z → Unit → ℝ
    Mvar :
    M → Time → ℝ
    IsUnitTimeAdditive (fun i t => P.X i t - ddot P.X i t) ∧
    (∀ h : Unit → Time → ℝ, IsTwoWayMundlakNuisance P.X Zvar Mvar h → inner (ddot P.X) h = 0)
    Proof (Lean source)
    theorem twfe_twm_residual_common (P : ScalarTWFEProblem Unit Time) (Zvar : Z → Unit → ℝ) (Mvar : M → Time → ℝ) : IsUnitTimeAdditive (fun i t => P.X i t - ddot P.X i t) ∧ (∀ h : Unit → Time → ℝ, IsTwoWayMundlakNuisance P.X Zvar Mvar h → inner (ddot P.X) h = 0) := by constructor · rw [show (fun i t => P.X i t - ddot P.X i t) = unitTimeProjection P.X by funext i t exact sub_ddot_eq_unitTimeProjection P.X i t] exact unitTimeProjection_additive P.X · intro h hh exact ddot_orthogonal_unit_time (lt_of_lt_of_le (by decide) P.panel.unit_card_ge_two) (lt_of_lt_of_le (by decide) P.panel.time_card_ge_two) P.X h (mundlak_nuisance_unit_time P.X Zvar Mvar hh)
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.twfe_twm_residual_common · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:180
  • twfe_twm_optional_controls_invariant theorem — Adding or removing optional time-constant or time-only controls does not change the scalar coefficient, because both fits equal the TWFE coefficient.
    Z₁ M₁ Z₂ M₂ :
    Type*
    Fintype Z₁
    Fintype M₁
    Fintype Z₂
    Fintype M₂
    Zvar₁ :
    Z₁ → Unit → ℝ
    Mvar₁ :
    M₁ → Time → ℝ
    Zvar₂ :
    Z₂ → Unit → ℝ
    Mvar₂ :
    M₂ → Time → ℝ
    fit₁ :
    ScalarTWMFit P Zvar₁ Mvar₁
    fit₂ :
    ScalarTWMFit P Zvar₂ Mvar₂
    fit₁.beta = fit₂.beta
    Proof (Lean source)
    theorem twfe_twm_optional_controls_invariant {Z₁ M₁ Z₂ M₂ : Type*} [Fintype Z₁] [Fintype M₁] [Fintype Z₂] [Fintype M₂] (P : ScalarTWFEProblem Unit Time) (Zvar₁ : Z₁ → Unit → ℝ) (Mvar₁ : M₁ → Time → ℝ) (Zvar₂ : Z₂ → Unit → ℝ) (Mvar₂ : M₂ → Time → ℝ) (fit₁ : ScalarTWMFit P Zvar₁ Mvar₁) (fit₂ : ScalarTWMFit P Zvar₂ Mvar₂) : fit₁.beta = fit₂.beta := by rw [twfe_twm_equivalence P Zvar₁ Mvar₁ fit₁, twfe_twm_equivalence P Zvar₂ Mvar₂ fit₂]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.twfe_twm_optional_controls_invariant · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:255
Vector­TWFE 9 core · 2 supporting This file defines the finite-dimensional vector-regressor version of Wooldridge's two-way fixed effects normal equation on a balanced panel. ★ betaTWFE_normalEq★ betaTWFE_unique

Wooldridge Vector TWFE

This file defines the finite-dimensional vector-regressor version of Wooldridge's two-way fixed effects normal equation on a balanced panel. It constructs the componentwise residual ddotVec, residualized Gram matrix gram, numerator numer, and VectorTWFEProblem.betaTWFE. It proves vecNormalEq_iff_mulVec, VectorTWFEProblem.betaTWFE_normalEq, and VectorTWFEProblem.betaTWFE_unique, then relates the scalar problem to the one-coordinate case with ScalarTWFEProblem.toVector and ScalarTWFEProblem.toVector_betaTWFE.

def ddotVec reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Component-wise double-demeaned vector regressor: the k-th coordinate is the scalar double demean of the k-th component field.

Definition (Lean source)
noncomputable def ddotVec (X : Unit → Time → K → ℝ) (i : Unit) (t : Time) (k : K) : ℝ := ddot (fun i t => X i t k) i t
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ddotVec · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:43
def gram reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Residualized Gram matrix Q_{\ddot X} = Σ_it ddot(X_it) ddot(X_it)ᵀ.

Definition (Lean source)
noncomputable def gram (X : Unit → Time → K → ℝ) : Matrix K K ℝ := fun j k => ∑ i, ∑ t, ddotVec X i t j * ddotVec X i t k
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.gram · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:48
def numer reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Residualized numerator vector Σ_it ddot(X_it) ddot(Y_it).

Definition (Lean source)
noncomputable def numer (X : Unit → Time → K → ℝ) (Y : Unit → Time → ℝ) : K → ℝ := fun k => ∑ i, ∑ t, ddotVec X i t k * ddot Y i t
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.numer · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:52
structure VectorTWFEProblem reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

A K-vector two-way-fixed-effects regression problem on a finite balanced panel of units and time periods, given a scalar outcome and a K-vector of regressors, where the residualized Gram matrix of the double-demeaned regressors is nonsingular — the vector full-rank condition ensuring the two-way within estimator is well defined.

Definition (Lean source)
Unit Time :
Type*
Fintype Unit
Fintype Time
K :
panel :
BalancedPanel Unit Time
Y :
Unit → Time → ℝ
X :
Unit → Time → K → ℝ
gram_unit :
IsUnit (gram X).det
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:56
def betaTWFE reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem

Closed-form vector TWFE coefficient Q_{\ddot X}⁻¹ (Σ_it ddot X ddot Y).

Definition (Lean source)
noncomputable def betaTWFE (P : VectorTWFEProblem Unit Time K) : K → ℝ := (gram P.X)⁻¹.mulVec (numer P.X P.Y)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem.betaTWFE · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:70 · uses VectorTWFEProblem
def vecTwfeNormalEq reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem

Vector TWFE normal equation after double demeaning: in every coordinate the residualized regressor is orthogonal to the residual.

Definition (Lean source)
def vecTwfeNormalEq (P : VectorTWFEProblem Unit Time K) (β : K → ℝ) : Prop := ∀ k, ∑ i, ∑ t, ddotVec P.X i t k * (ddot P.Y i t - ∑ j, ddotVec P.X i t j * β j) = 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem.vecTwfeNormalEq · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:74 · uses VectorTWFEProblem
theorem betaTWFE_normalEq reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem

Existence of a TWFE solution. For a vector two-way-fixed-effects problem, whose residualized Gram matrix is nonsingular by assumption, the closed-form coefficient P.betaTWFE solves the matrix normal equation defining the TWFE coefficient.

Formal statement
P :
P.vecTwfeNormalEq P.betaTWFE
Proof (Lean source)
theorem betaTWFE_normalEq (P : VectorTWFEProblem Unit Time K) : P.vecTwfeNormalEq P.betaTWFE := by rw [vecTwfeNormalEq, vecNormalEq_iff_mulVec] change (gram P.X).mulVec ((gram P.X)⁻¹.mulVec (numer P.X P.Y)) = numer P.X P.Y rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ P.gram_unit, Matrix.one_mulVec]
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem.betaTWFE_normalEq · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:140 · uses VectorTWFEProblem , betaTWFE , vecTwfeNormalEq
theorem betaTWFE_unique reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem

Full-rank uniqueness of the vector TWFE coefficient. For a vector TWFE problem P with nonsingular residualized Gram matrix, if a coefficient vector β satisfies the coordinate-wise TWFE normal equation — in every coordinate the double-demeaned regressor is orthogonal to the double-demeaned residual, then β equals the closed-form vector TWFE coefficient P.betaTWFE.

Formal statement
P :
β :
K → ℝ
:
P.vecTwfeNormalEq β
β = P.betaTWFE
Proof (Lean source)
theorem betaTWFE_unique (P : VectorTWFEProblem Unit Time K) {β : K → ℝ} (hβ : P.vecTwfeNormalEq β) : β = P.betaTWFE := by have h : (gram P.X).mulVec β = numer P.X P.Y := (vecNormalEq_iff_mulVec P.X P.Y β).mp hβ change β = (gram P.X)⁻¹.mulVec (numer P.X P.Y) rw [← h, Matrix.mulVec_mulVec, Matrix.nonsing_inv_mul _ P.gram_unit, Matrix.one_mulVec]
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem.betaTWFE_unique · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:149 · uses VectorTWFEProblem , betaTWFE , vecTwfeNormalEq
def toVector reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

The scalar TWFE problem embeds as the singleton-K = Fin 1 vector problem: the regressor is the same scalar in the single coordinate and the matrix full-rank condition reduces to the scalar ddotX_ss_pos.

Definition (Lean source)
noncomputable def ScalarTWFEProblem.toVector (P : ScalarTWFEProblem Unit Time) : VectorTWFEProblem Unit Time (Fin 1) where panel := P.panel Y := P.Y X := fun i t _ => P.X i t gram_unit := by have hval : (gram (fun i t (_ : Fin 1) => P.X i t)).det = ∑ i, ∑ t, (ddot P.X i t) ^ 2 := by rw [Matrix.det_fin_one] simp only [gram, ddotVec] refine Finset.sum_congr rfl (fun i _ => Finset.sum_congr rfl (fun t _ => ?_)) rw [pow_two] rw [hval] exact (isUnit_iff_ne_zero).mpr (ne_of_gt P.ddotX_ss_pos)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.toVector · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:165 · uses ScalarTWFEProblem , VectorTWFEProblem
2 supporting declarations (lemmas, instances)
  • vecNormalEq_iff_mulVec theorem — The coordinate-wise normal equation is equivalent to the matrix normal equation Q_{\ddot X} β = Σ_it ddot X ddot Y.
    X :
    Unit → Time → K → ℝ
    Y :
    Unit → Time → ℝ
    β :
    K → ℝ
    (∀ k, ∑ i, ∑ t, ddotVec X i t k * (ddot Y i t - ∑ j, ddotVec X i t j * β j) = 0)
    ↔ (gram X).mulVec β = numer X Y
    Proof (Lean source)
    theorem vecNormalEq_iff_mulVec (X : Unit → Time → K → ℝ) (Y : Unit → Time → ℝ) (β : K → ℝ) : (∀ k, ∑ i, ∑ t, ddotVec X i t k * (ddot Y i t - ∑ j, ddotVec X i t j * β j) = 0) ↔ (gram X).mulVec β = numer X Y := by have key : ∀ k, ∑ i, ∑ t, ddotVec X i t k * (ddot Y i t - ∑ j, ddotVec X i t j * β j) = numer X Y k - (gram X).mulVec β k := by intro k have hmv : (gram X).mulVec β k = ∑ j, (∑ i, ∑ t, ddotVec X i t k * ddotVec X i t j) * β j := by simp only [mulVec, dotProduct, gram] rw [hmv] change ∑ i, ∑ t, ddotVec X i t k * (ddot Y i t - ∑ j, ddotVec X i t j * β j) = (∑ i, ∑ t, ddotVec X i t k * ddot Y i t) - ∑ j, (∑ i, ∑ t, ddotVec X i t k * ddotVec X i t j) * β j -- split off the regressor term and swap the `j` sum outward have hsplit : ∑ i, ∑ t, ddotVec X i t k * (ddot Y i t - ∑ j, ddotVec X i t j * β j) = (∑ i, ∑ t, ddotVec X i t k * ddot Y i t) - ∑ i, ∑ t, ∑ j, ddotVec X i t k * ddotVec X i t j * β j := by rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl (fun i _ => ?_) rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl (fun t _ => ?_) rw [mul_sub, Finset.mul_sum] congr 1 refine Finset.sum_congr rfl (fun j _ => ?_) ring rw [hsplit] congr 1 -- reorder ∑ i ∑ t ∑ j → ∑ j ∑ i ∑ t and pull `β j` out of the i,t sums calc ∑ i, ∑ t, ∑ j, ddotVec X i t k * ddotVec X i t j * β j = ∑ i, ∑ j, ∑ t, ddotVec X i t k * ddotVec X i t j * β j := by refine Finset.sum_congr rfl (fun i _ => ?_) rw [Finset.sum_comm] _ = ∑ j, ∑ i, ∑ t, ddotVec X i t k * ddotVec X i t j * β j := by rw [Finset.sum_comm] _ = ∑ j, (∑ i, ∑ t, ddotVec X i t k * ddotVec X i t j) * β j := by refine Finset.sum_congr rfl (fun j _ => ?_) rw [Finset.sum_mul] refine Finset.sum_congr rfl (fun i _ => ?_) rw [Finset.sum_mul] constructor · intro h funext k have := key k rw [h k] at this -- 0 = numer k - mulVec k ⇒ mulVec k = numer k linarith [this] · intro h k rw [key k, h] ring
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.vecNormalEq_iff_mulVec · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:83
  • toVector_betaTWFE theorem — The singleton-coordinate vector TWFE coefficient recovers the scalar TWFE coefficient, so the scalar theorem is the K = Fin 1 case of the vector one.
    P.toVector.betaTWFE 0 = P.betaTWFE
    Proof (Lean source)
    theorem ScalarTWFEProblem.toVector_betaTWFE (P : ScalarTWFEProblem Unit Time) : P.toVector.betaTWFE 0 = P.betaTWFE := by have hsol : P.toVector.vecTwfeNormalEq (fun _ => P.betaTWFE) := by intro k have h := P.betaTWFE_normalEq rw [ScalarTWFEProblem.twfeNormalEq] at h simpa [VectorTWFEProblem.vecTwfeNormalEq, ScalarTWFEProblem.toVector, ddotVec, Fin.sum_univ_one] using h have heq := P.toVector.betaTWFE_unique hsol rw [← heq]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.toVector_betaTWFE · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:183
Population­Bridge 1 core · 3 supporting This file connects Wooldridge's finite imputation estimands to population conditional expectations. ★ thetaImp_eq_eventCondExp

Wooldridge Population Bridge

This file connects Wooldridge's finite imputation estimands to population conditional expectations. The main bridges are imputationTheta_eq_eventCondExp and thetaImp_eq_eventCondExp, which apply the finite-partition law of iterated expectations to identify covariate-weighted finite residual means with event-level conditional expectations. The companion lemmas m0_eq_eventCondExp_treated and m0_eq_eventCondExp_untreated state the population conditional-expectation origin of the saturated untreated fit on treated and untreated cells.

theorem thetaImp_eq_eventCondExp reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

The imputation estimand equals a population conditional expectation. On a treated cohort-time cell (g,t), suppose the cohort event is measurable, each covariate cell is measurable, the covariate cells are pairwise disjoint, the covariate cells cover the whole sample space, the treatment-effect integrand Δ is integrable, each finite covariate weight equals the conditional probability of that covariate cell given the cohort event, and each finite cell residual — the observed mean minus the fitted untreated mean — equals the within-cell conditional mean of Δ given the cohort event and that covariate cell. Then the imputation cell estimand thetaImp g t equals the population conditional expectation E[Δ | cohortEvent].

Formal statement
Ω :
P :
StaggeredATTCells Cohort Time Covar
g :
Cohort
t :
Time
hgt :
P.treatedCell g t
cohortEvent :
Set Ω
covarCell :
Covar → Set Ω
Δ :
Ω → ℝ
hG :
MeasurableSet cohortEvent
hC :
∀ c, MeasurableSet (covarCell c)
hdisj :
Pairwise (onFun Disjoint covarCell)
hcov :
(⋃ c, covarCell c) = univ
:
hweight :
∀ c, P.covarWeight g c = (μ (cohortEvent ∩ covarCell c)).toReal / (μ cohortEvent).toReal
hcell :
∀ c, P.observedMean g t c - S.m0 g t c = eventCondExp μ (cohortEvent ∩ covarCell c) Δ
E.thetaImp g t = eventCondExp μ cohortEvent Δ
Proof (Lean source)
theorem thetaImp_eq_eventCondExp {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] (P : StaggeredATTCells Cohort Time Covar) (S : SaturatedUntreatedRegression P) (E : FlexibleDIDEstimands P S) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) (cohortEvent : Set Ω) (covarCell : Covar → Set Ω) (Δ : Ω → ℝ) (hG : MeasurableSet cohortEvent) (hC : ∀ c, MeasurableSet (covarCell c)) (hdisj : Pairwise (onFun Disjoint covarCell)) (hcov : (⋃ c, covarCell c) = univ) (hΔ : Integrable Δ μ) (hweight : ∀ c, P.covarWeight g c = (μ (cohortEvent ∩ covarCell c)).toReal / (μ cohortEvent).toReal) (hcell : ∀ c, P.observedMean g t c - S.m0 g t c = eventCondExp μ (cohortEvent ∩ covarCell c) Δ) : E.thetaImp g t = eventCondExp μ cohortEvent Δ := by rw [E.thetaImp_eq_imputation hgt] exact imputationTheta_eq_eventCondExp μ P S g t cohortEvent covarCell Δ hG hC hdisj hcov hΔ hweight hcell
3 supporting declarations (lemmas, instances)
Population­Origin 4 core · 0 supporting This file constructs the finite staggered-DID cell system from an underlying probability model. ★ ofPopulation★ m0_eq_eventCondExp_treated_ofPopulation★ m0_eq_eventCondExp_untreated_ofPopulation

Wooldridge Population Origin

This file constructs the finite staggered-DID cell system from an underlying probability model. StaggeredATTCells.ofPopulation defines the cell means as raw event-level quotients of population outcomes and derives the consistency fields from pointwise potential-outcome consistency on the corresponding cells. The corollaries m0_eq_eventCondExp_treated_ofPopulation and m0_eq_eventCondExp_untreated_ofPopulation specialize the population bridge for systems built by this constructor, so the untreated-fit identification hypothesis is definitional.

def ofMeasure reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

Builds a finite staggered-DID cell system from a population model.

Definition (Lean source)
noncomputable def StaggeredATTCells.ofMeasure {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) (cellEvent : Cohort → Time → Covar → Set Ω) (Y0pop Ygpop Yobspop : Ω → ℝ) (treatedCell untreatedCell : Cohort → Time → Prop) (cohortShare : Cohort → ℝ) (covarWeight : Cohort → Covar → ℝ) (hmeas : ∀ g t c, MeasurableSet (cellEvent g t c)) (hcell_pos : ∀ g t c, 0 < (μ (cellEvent g t c)).toReal) (hY0_int : ∀ g t c, IntegrableOn Y0pop (cellEvent g t c) μ) (hYg_int : ∀ g t c, IntegrableOn Ygpop (cellEvent g t c) μ) (hYobs_int : ∀ g t c, IntegrableOn Yobspop (cellEvent g t c) μ) (cohortShare_pos_on_treated : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → 0 < cohortShare g) (covarWeight_nonneg : ∀ g c, 0 ≤ covarWeight g c) (covarWeight_sum_one : ∀ g, ∑ c, covarWeight g c = 1) (hcons_tr : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Ygpop ω) (hcons_ut : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, untreatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Y0pop ω) : StaggeredATTCells Cohort Time Covar where cohortShare := cohortShare covarWeight := covarWeight treatedCell := treatedCell untreatedCell := untreatedCell Y0Mean g t c := eventCondExp μ (cellEvent g t c) Y0pop YgMean g t c := eventCondExp μ (cellEvent g t c) Ygpop observedMean g t c := eventCondExp μ (cellEvent g t c) Yobspop cohortShare_pos_on_treated := cohortShare_pos_on_treated covarWeight_nonneg := covarWeight_nonneg covarWeight_sum_one := covarWeight_sum_one consistency_treated g t hgt c := have _ := hcell_pos g t c have _ := hYg_int g t c have _ := hYobs_int g t c eventCondExp_congr_on μ (hmeas g t c) (hcons_tr hgt c) consistency_untreated g t hut c := have _ := hcell_pos g t c have _ := hY0_int g t c have _ := hYobs_int g t c eventCondExp_congr_on μ (hmeas g t c) (hcons_ut hut c)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells.ofMeasure · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/PopulationOrigin.lean:58 · uses StaggeredATTCells
def ofPopulation reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

Probability-measure specialization of StaggeredATTCells.ofMeasure.

Definition (Lean source)
noncomputable def StaggeredATTCells.ofPopulation {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (cellEvent : Cohort → Time → Covar → Set Ω) (Y0pop Ygpop Yobspop : Ω → ℝ) (treatedCell untreatedCell : Cohort → Time → Prop) (cohortShare : Cohort → ℝ) (covarWeight : Cohort → Covar → ℝ) (hmeas : ∀ g t c, MeasurableSet (cellEvent g t c)) (hcell_pos : ∀ g t c, 0 < (μ (cellEvent g t c)).toReal) (hY0_int : ∀ g t c, IntegrableOn Y0pop (cellEvent g t c) μ) (hYg_int : ∀ g t c, IntegrableOn Ygpop (cellEvent g t c) μ) (hYobs_int : ∀ g t c, IntegrableOn Yobspop (cellEvent g t c) μ) (cohortShare_pos_on_treated : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → 0 < cohortShare g) (covarWeight_nonneg : ∀ g c, 0 ≤ covarWeight g c) (covarWeight_sum_one : ∀ g, ∑ c, covarWeight g c = 1) (hcons_tr : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Ygpop ω) (hcons_ut : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, untreatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Y0pop ω) : StaggeredATTCells Cohort Time Covar := StaggeredATTCells.ofMeasure μ cellEvent Y0pop Ygpop Yobspop treatedCell untreatedCell cohortShare covarWeight hmeas hcell_pos hY0_int hYg_int hYobs_int cohortShare_pos_on_treated covarWeight_nonneg covarWeight_sum_one hcons_tr hcons_ut
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells.ofPopulation · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/PopulationOrigin.lean:119 · uses StaggeredATTCells
theorem m0_eq_eventCondExp_treated_ofPopulation reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

On a treated cell in a population-built system, the fitted untreated mean equals the population conditional mean of the untreated potential outcome. Fix a population model on a sample space Ω, with population outcomes Y0pop, Ygpop, Yobspop; suppose every cell event cellEvent g t c is measurable, every cell has strictly positive probability mass, and the three population outcomes are each integrable on every cell. Suppose also the cohort share is strictly positive on every treated cell, the covariate weights are nonnegative and sum to one within each cohort, and the observed outcome agrees pointwise with the cohort-g outcome on treated cells and with the untreated outcome on untreated cells (pointwise consistency). If the finite cell system P is exactly the one built from this population data by StaggeredATTCells.ofPopulation and, for a saturated untreated regression S on P, no anticipation holds and conditional parallel trends holds, then on any treated cell (g,t), the saturated regression's fitted value S.m0 g t c equals the population conditional mean E[Y0pop | cellEvent g t c], for every covariate cell c.

Formal statement
Ω :
cellEvent :
Cohort → Time → Covar → Set Ω
Y0pop Ygpop Yobspop :
Ω → ℝ
treatedCell untreatedCell :
Cohort → Time → Prop
cohortShare :
Cohort → ℝ
covarWeight :
Cohort → Covar → ℝ
hmeas :
∀ g t c, MeasurableSet (cellEvent g t c)
hcell_pos :
∀ g t c, 0 < (μ (cellEvent g t c)).toReal
hY0_int :
∀ g t c, IntegrableOn Y0pop (cellEvent g t c) μ
hYg_int :
∀ g t c, IntegrableOn Ygpop (cellEvent g t c) μ
hYobs_int :
∀ g t c, IntegrableOn Yobspop (cellEvent g t c) μ
cohortShare_pos_on_treated :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
treatedCell g t
then
0 < cohortShare g
covarWeight_nonneg :
∀ g c, 0 ≤ covarWeight g c
covarWeight_sum_one :
∀ g, ∑ c, covarWeight g c = 1
hcons_tr :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
treatedCell g t
then
∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Ygpop ω
hcons_ut :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
untreatedCell g t
then
∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Y0pop ω
P :
StaggeredATTCells Cohort Time Covar
hP :
P
= StaggeredATTCells.ofPopulation μ cellEvent Y0pop Ygpop Yobspop treatedCell untreatedCell cohortShare covarWeight hmeas hcell_pos hY0_int hYg_int hYobs_int cohortShare_pos_on_treated covarWeight_nonneg covarWeight_sum_one hcons_tr hcons_ut
hNA :
NoAnticipation P
g :
Cohort
t :
Time
hgt :
P.treatedCell g t
c :
Covar
S.m0 g t c = eventCondExp μ (cellEvent g t c) Y0pop
Proof (Lean source)
theorem m0_eq_eventCondExp_treated_ofPopulation {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (cellEvent : Cohort → Time → Covar → Set Ω) (Y0pop Ygpop Yobspop : Ω → ℝ) (treatedCell untreatedCell : Cohort → Time → Prop) (cohortShare : Cohort → ℝ) (covarWeight : Cohort → Covar → ℝ) (hmeas : ∀ g t c, MeasurableSet (cellEvent g t c)) (hcell_pos : ∀ g t c, 0 < (μ (cellEvent g t c)).toReal) (hY0_int : ∀ g t c, IntegrableOn Y0pop (cellEvent g t c) μ) (hYg_int : ∀ g t c, IntegrableOn Ygpop (cellEvent g t c) μ) (hYobs_int : ∀ g t c, IntegrableOn Yobspop (cellEvent g t c) μ) (cohortShare_pos_on_treated : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → 0 < cohortShare g) (covarWeight_nonneg : ∀ g c, 0 ≤ covarWeight g c) (covarWeight_sum_one : ∀ g, ∑ c, covarWeight g c = 1) (hcons_tr : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Ygpop ω) (hcons_ut : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, untreatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Y0pop ω) {P : StaggeredATTCells Cohort Time Covar} (hP : P = StaggeredATTCells.ofPopulation μ cellEvent Y0pop Ygpop Yobspop treatedCell untreatedCell cohortShare covarWeight hmeas hcell_pos hY0_int hYg_int hYobs_int cohortShare_pos_on_treated covarWeight_nonneg covarWeight_sum_one hcons_tr hcons_ut) (S : SaturatedUntreatedRegression P) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) {g : Cohort} {t : Time} (hgt : P.treatedCell g t) (c : Covar) : S.m0 g t c = eventCondExp μ (cellEvent g t c) Y0pop := have _ := hcell_pos g t c have _ := hY0_int g t c have _ := hYg_int g t c have _ := hYobs_int g t c m0_eq_eventCondExp_treated μ S hNA hCPT hgt c cellEvent Y0pop (by subst hP; rfl)
theorem m0_eq_eventCondExp_untreated_ofPopulation reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

On an untreated cell in a population-built system, the fitted untreated mean equals the population conditional mean of the untreated potential outcome. Fix a population model on a sample space Ω, with population outcomes Y0pop, Ygpop, Yobspop; suppose every cell event cellEvent g t c is measurable, every cell has strictly positive probability mass, and the three population outcomes are each integrable on every cell. Suppose also the cohort share is strictly positive on every treated cell, the covariate weights are nonnegative and sum to one within each cohort, and the observed outcome agrees pointwise with the cohort-g outcome on treated cells and with the untreated outcome on untreated cells (pointwise consistency). If the finite cell system P is exactly the one built from this population data by StaggeredATTCells.ofPopulation and, for a saturated untreated regression S on P, no anticipation holds and conditional parallel trends holds, then on any untreated cell (g,t), the saturated regression's fitted value S.m0 g t c equals the population conditional mean E[Y0pop | cellEvent g t c], for every covariate cell c.

Formal statement
Ω :
cellEvent :
Cohort → Time → Covar → Set Ω
Y0pop Ygpop Yobspop :
Ω → ℝ
treatedCell untreatedCell :
Cohort → Time → Prop
cohortShare :
Cohort → ℝ
covarWeight :
Cohort → Covar → ℝ
hmeas :
∀ g t c, MeasurableSet (cellEvent g t c)
hcell_pos :
∀ g t c, 0 < (μ (cellEvent g t c)).toReal
hY0_int :
∀ g t c, IntegrableOn Y0pop (cellEvent g t c) μ
hYg_int :
∀ g t c, IntegrableOn Ygpop (cellEvent g t c) μ
hYobs_int :
∀ g t c, IntegrableOn Yobspop (cellEvent g t c) μ
cohortShare_pos_on_treated :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
treatedCell g t
then
0 < cohortShare g
covarWeight_nonneg :
∀ g c, 0 ≤ covarWeight g c
covarWeight_sum_one :
∀ g, ∑ c, covarWeight g c = 1
hcons_tr :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
treatedCell g t
then
∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Ygpop ω
hcons_ut :
∀ ⦃g : Cohort⦄ ⦃t : Time⦄
if
untreatedCell g t
then
∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Y0pop ω
P :
StaggeredATTCells Cohort Time Covar
hP :
P
= StaggeredATTCells.ofPopulation μ cellEvent Y0pop Ygpop Yobspop treatedCell untreatedCell cohortShare covarWeight hmeas hcell_pos hY0_int hYg_int hYobs_int cohortShare_pos_on_treated covarWeight_nonneg covarWeight_sum_one hcons_tr hcons_ut
hNA :
NoAnticipation P
g :
Cohort
t :
Time
hut :
P.untreatedCell g t
c :
Covar
S.m0 g t c = eventCondExp μ (cellEvent g t c) Y0pop
Proof (Lean source)
theorem m0_eq_eventCondExp_untreated_ofPopulation {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (cellEvent : Cohort → Time → Covar → Set Ω) (Y0pop Ygpop Yobspop : Ω → ℝ) (treatedCell untreatedCell : Cohort → Time → Prop) (cohortShare : Cohort → ℝ) (covarWeight : Cohort → Covar → ℝ) (hmeas : ∀ g t c, MeasurableSet (cellEvent g t c)) (hcell_pos : ∀ g t c, 0 < (μ (cellEvent g t c)).toReal) (hY0_int : ∀ g t c, IntegrableOn Y0pop (cellEvent g t c) μ) (hYg_int : ∀ g t c, IntegrableOn Ygpop (cellEvent g t c) μ) (hYobs_int : ∀ g t c, IntegrableOn Yobspop (cellEvent g t c) μ) (cohortShare_pos_on_treated : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → 0 < cohortShare g) (covarWeight_nonneg : ∀ g c, 0 ≤ covarWeight g c) (covarWeight_sum_one : ∀ g, ∑ c, covarWeight g c = 1) (hcons_tr : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, treatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Ygpop ω) (hcons_ut : ∀ ⦃g : Cohort⦄ ⦃t : Time⦄, untreatedCell g t → ∀ c, ∀ ω ∈ cellEvent g t c, Yobspop ω = Y0pop ω) {P : StaggeredATTCells Cohort Time Covar} (hP : P = StaggeredATTCells.ofPopulation μ cellEvent Y0pop Ygpop Yobspop treatedCell untreatedCell cohortShare covarWeight hmeas hcell_pos hY0_int hYg_int hYobs_int cohortShare_pos_on_treated covarWeight_nonneg covarWeight_sum_one hcons_tr hcons_ut) (S : SaturatedUntreatedRegression P) (hNA : NoAnticipation P) (hCPT : ConditionalParallelTrendsAdditive P) {g : Cohort} {t : Time} (hut : P.untreatedCell g t) (c : Covar) : S.m0 g t c = eventCondExp μ (cellEvent g t c) Y0pop := have _ := hcell_pos g t c have _ := hY0_int g t c have _ := hYg_int g t c have _ := hYobs_int g t c m0_eq_eventCondExp_untreated μ S hNA hCPT hut c cellEvent Y0pop (by subst hP; rfl)
Vector­Mundlak 5 core · 7 supporting This file extends the finite balanced-panel Mundlak equivalence from one regressor to a finite vector of regressors. ★ vec_twfe_twm_equivalence

Wooldridge Vector Mundlak Equivalence

This file extends the finite balanced-panel Mundlak equivalence from one regressor to a finite vector of regressors. It defines the generic residualized gramOf and numerOf, proves the matrix Frisch-Waugh-Lovell handoff matrix_fwl_eq_of_normalEqs, introduces the vector two-way Mundlak nuisance span and fit, and proves vec_twfe_twm_equivalence together with the optional-control invariance theorem vec_twfe_twm_optional_controls_invariant.

def gramOf reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Generic residualized Gram matrix of a supplied residualized regressor.

Definition (Lean source)
noncomputable def gramOf (Dt : Unit → Time → K → ℝ) : Matrix K K ℝ := fun j k => ∑ i, ∑ t, Dt i t j * Dt i t k
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.gramOf · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:37
def numerOf reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Generic residualized numerator vector.

Definition (Lean source)
noncomputable def numerOf (Dt : Unit → Time → K → ℝ) (Yt : Unit → Time → ℝ) : K → ℝ := fun k => ∑ i, ∑ t, Dt i t k * Yt i t
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.numerOf · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:41
def IsVectorTwoWayMundlakNuisance reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Two-way Mundlak nuisance span for a K-vector regressor: constants, the unit means and time means of every coordinate of X, optional time-constant controls Z_i, and optional time-only controls M_t.

Definition (Lean source)
def IsVectorTwoWayMundlakNuisance (X : Unit → Time → K → ℝ) (Zvar : Z → Unit → ℝ) (Mvar : M → Time → ℝ) (h : Unit → Time → ℝ) : Prop := ∃ c : ℝ, ∃ γu γt : K → ℝ, ∃ ζ : Z → ℝ, ∃ μ : M → ℝ, ∀ i t, h i t = c + (∑ k, γu k * unitMean (fun i t => X i t k) i) + (∑ k, γt k * timeMean (fun i t => X i t k) t) + (∑ z, ζ z * Zvar z i) + (∑ m, μ m * Mvar m t)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.IsVectorTwoWayMundlakNuisance · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:176
structure VectorTWMFit reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

A coding-free K-vector two-way Mundlak fit of the vector TWFE problem P against optional time-constant controls Zvar and time-only controls Mvar, stated by normal equations rather than by a particular coding of the nuisance regressors. It bundles a coefficient vector and a nuisance function lying in the vector two-way Mundlak span, subject to the pooled normal equation against every regressor coordinate and the pooled normal equation against every nuisance function in that span.

Definition (Lean source)
P :
Zvar :
Z → Unit → ℝ
Mvar :
M → Time → ℝ
beta :
K → ℝ
nuisance :
Unit → Time → ℝ
nuisance_mem :
IsVectorTwoWayMundlakNuisance P.X Zvar Mvar nuisance
normal_X :
∀ k, (∑ i, ∑ t, P.X i t k * (P.Y i t - (∑ j, P.X i t j * beta j) - nuisance i t)) = 0
normal_H :
∀ h : Unit → Time → ℝ
then
(∑ i, ∑ t, h i t * (P.Y i t - (∑ j, P.X i t j * beta j) - nuisance i t)) = 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWMFit · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:212 · uses VectorTWFEProblem
theorem vec_twfe_twm_equivalence reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

Wooldridge finite-panel K-vector TWFE-two-way-Mundlak equivalence (Theorem A). For a K-vector two-way-fixed-effects panel regression problem P with optional time-constant controls Zvar and time-only controls Mvar, given any pooled two-way Mundlak regression fit stated by its normal equations, that fit's coefficient vector on the regressors equals the K-vector two-way-fixed-effects coefficient vector.

Formal statement
P :
Zvar :
Z → Unit → ℝ
Mvar :
M → Time → ℝ
fit :
VectorTWMFit P Zvar Mvar
fit.beta = P.betaTWFE
Proof (Lean source)
theorem vec_twfe_twm_equivalence (P : VectorTWFEProblem Unit Time K) (Zvar : Z → Unit → ℝ) (Mvar : M → Time → ℝ) (fit : VectorTWMFit P Zvar Mvar) : fit.beta = P.betaTWFE := by -- decompositions have hY : ∀ i t, P.Y i t = (P.Y i t - ddot P.Y i t) + ddot P.Y i t := by intro i t; ring have hD : ∀ i t k, P.X i t k = unitTimeProjection (fun i t => P.X i t k) i t + ddotVec P.X i t k := by intro i t k have h := sub_ddot_eq_unitTimeProjection (fun i t => P.X i t k) i t simp only [ddotVec] linarith [h] -- the unit/time projection of each coordinate lies in the Mundlak span have hDproj_mem : ∀ k, IsVectorTwoWayMundlakNuisance P.X Zvar Mvar (fun i t => unitTimeProjection (fun i t => P.X i t k) i t) := by intro k refine ⟨-grandMean (fun i t => P.X i t k), fun k' => if k' = k then 1 else 0, fun k' => if k' = k then 1 else 0, fun _ => 0, fun _ => 0, ?_⟩ intro i t unfold unitTimeProjection rw [sum_ite_one_mul k (fun k' => unitMean (fun i t => P.X i t k') i), sum_ite_one_mul k (fun k' => timeMean (fun i t => P.X i t k') t)] simp only [zero_mul, Finset.sum_const_zero] ring -- residualized coordinates are orthogonal to the (additive) Mundlak span have hDtilde_orth : ∀ k, ∀ h : Unit → Time → ℝ, IsVectorTwoWayMundlakNuisance P.X Zvar Mvar h → (∑ i, ∑ t, ddotVec P.X i t k * h i t) = 0 := by intro k h hh have hadd : IsUnitTimeAdditive h := vector_mundlak_nuisance_unit_time P.X Zvar Mvar hh have hortho := ddot_orthogonal_unit_time (lt_of_lt_of_le (by decide) P.panel.unit_card_ge_two) (lt_of_lt_of_le (by decide) P.panel.time_card_ge_two) (fun i t => P.X i t k) h hadd simpa [inner, ddotVec] using hortho have hYproj_orth : ∀ k, (∑ i, ∑ t, ddotVec P.X i t k * (P.Y i t - ddot P.Y i t)) = 0 := by intro k have hadd : IsUnitTimeAdditive (fun i t => P.Y i t - ddot P.Y i t) := by rw [show (fun i t => P.Y i t - ddot P.Y i t) = unitTimeProjection P.Y from funext fun i => funext fun t => sub_ddot_eq_unitTimeProjection P.Y i t] exact unitTimeProjection_additive P.Y have hortho := ddot_orthogonal_unit_time (lt_of_lt_of_le (by decide) P.panel.unit_card_ge_two) (lt_of_lt_of_le (by decide) P.panel.time_card_ge_two) (fun i t => P.X i t k) (fun i t => P.Y i t - ddot P.Y i t) hadd simpa [inner, ddotVec] using hortho -- apply the matrix FWL handoff have hfwl := matrix_fwl_eq_of_normalEqs (H := IsVectorTwoWayMundlakNuisance P.X Zvar Mvar) (Y := P.Y) (Yproj := fun i t => P.Y i t - ddot P.Y i t) (Ytilde := ddot P.Y) (D := P.X) (Dproj := fun i t k => unitTimeProjection (fun i t => P.X i t k) i t) (Dtilde := ddotVec P.X) (Hβ := fit.nuisance) (β := fit.beta) hY hD hDproj_mem fit.nuisance_mem hDtilde_orth hYproj_orth (by rw [← gram_eq_gramOf]; exact P.gram_unit) fit.normal_X fit.normal_H rw [hfwl] rfl
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.vec_twfe_twm_equivalence · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:232 · uses VectorTWFEProblem , betaTWFE , VectorTWMFit
7 supporting declarations (lemmas, instances)
  • gram_eq_gramOf theorem — gram is the residualized instance of the generic version.
    X :
    Unit → Time → K → ℝ
    gram X = gramOf (ddotVec X)
    Proof (Lean source)
    theorem gram_eq_gramOf (X : Unit → Time → K → ℝ) : gram X = gramOf (ddotVec X) := rfl
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.gram_eq_gramOf · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:46
  • numer_eq_numerOf theorem — numer is the residualized instance of the generic version.
    X :
    Unit → Time → K → ℝ
    Y :
    Unit → Time → ℝ
    numer X Y = numerOf (ddotVec X) (ddot Y)
    Proof (Lean source)
    theorem numer_eq_numerOf (X : Unit → Time → K → ℝ) (Y : Unit → Time → ℝ) : numer X Y = numerOf (ddotVec X) (ddot Y) := rfl
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.numer_eq_numerOf · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:50
  • sum_dotRegressor theorem — Reshuffle: a residualized regressor against a β-combination of regressors factors through the cross-Gram.
    Dt D :
    Unit → Time → K → ℝ
    β :
    K → ℝ
    k :
    K
    (∑ i, ∑ t, Dt i t k * (∑ j, D i t j * β j)) = ∑ j, (∑ i, ∑ t, Dt i t k * D i t j) * β j
    Proof (Lean source)
    theorem sum_dotRegressor (Dt D : Unit → Time → K → ℝ) (β : K → ℝ) (k : K) : (∑ i, ∑ t, Dt i t k * (∑ j, D i t j * β j)) = ∑ j, (∑ i, ∑ t, Dt i t k * D i t j) * β j := by calc ∑ i, ∑ t, Dt i t k * (∑ j, D i t j * β j) = ∑ i, ∑ t, ∑ j, Dt i t k * D i t j * β j := by refine Finset.sum_congr rfl (fun i _ => Finset.sum_congr rfl (fun t _ => ?_)) rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun j _ => ?_) ring _ = ∑ i, ∑ j, ∑ t, Dt i t k * D i t j * β j := by refine Finset.sum_congr rfl (fun i _ => ?_) rw [Finset.sum_comm] _ = ∑ j, ∑ i, ∑ t, Dt i t k * D i t j * β j := by rw [Finset.sum_comm] _ = ∑ j, (∑ i, ∑ t, Dt i t k * D i t j) * β j := by refine Finset.sum_congr rfl (fun j _ => ?_) rw [Finset.sum_mul] refine Finset.sum_congr rfl (fun i _ => ?_) rw [Finset.sum_mul]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.sum_dotRegressor · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:55
  • matrix_fwl_eq_of_normalEqs theorem — Matrix Frisch-Waugh-Lovell handoff. If a coefficient vector β and nuisance term Hβ satisfy the finite normal equations against the raw vector regressor D and a nuisance class H, while each coordinate of the residualized regressor Dtilde is orthogonal to H and the residualized Gram matrix is nonsingular, then β is the residualized matrix coefficient.
    H :
    (Unit → Time → ℝ) → Prop
    Y Yproj Ytilde :
    Unit → Time → ℝ
    D Dproj Dtilde :
    Unit → Time → K → ℝ
    :
    Unit → Time → ℝ
    β :
    K → ℝ
    hY :
    ∀ i t, Y i t = Yproj i t + Ytilde i t
    hD :
    ∀ i t k, D i t k = Dproj i t k + Dtilde i t k
    hDproj_mem :
    ∀ k, H (fun i t => Dproj i t k)
    hHβ_mem :
    H Hβ
    hDtilde_orth :
    ∀ k, ∀ h : Unit → Time → ℝ, H h → (∑ i, ∑ t, Dtilde i t k * h i t) = 0
    hYproj_orth :
    ∀ k, (∑ i, ∑ t, Dtilde i t k * Yproj i t) = 0
    hgram_unit :
    IsUnit (gramOf Dtilde).det
    h_normal_D :
    ∀ k, (∑ i, ∑ t, D i t k * (Y i t - (∑ j, D i t j * β j) - Hβ i t)) = 0
    h_normal_H :
    ∀ h : Unit → Time → ℝ
    if
    H h
    then
    (∑ i, ∑ t, h i t * (Y i t - (∑ j, D i t j * β j) - Hβ i t)) = 0
    β = (gramOf Dtilde)⁻¹.mulVec (numerOf Dtilde Ytilde)
    Proof (Lean source)
    theorem matrix_fwl_eq_of_normalEqs (H : (Unit → Time → ℝ) → Prop) {Y Yproj Ytilde : Unit → Time → ℝ} {D Dproj Dtilde : Unit → Time → K → ℝ} {Hβ : Unit → Time → ℝ} {β : K → ℝ} (hY : ∀ i t, Y i t = Yproj i t + Ytilde i t) (hD : ∀ i t k, D i t k = Dproj i t k + Dtilde i t k) (hDproj_mem : ∀ k, H (fun i t => Dproj i t k)) (hHβ_mem : H Hβ) (hDtilde_orth : ∀ k, ∀ h : Unit → Time → ℝ, H h → (∑ i, ∑ t, Dtilde i t k * h i t) = 0) (hYproj_orth : ∀ k, (∑ i, ∑ t, Dtilde i t k * Yproj i t) = 0) (hgram_unit : IsUnit (gramOf Dtilde).det) (h_normal_D : ∀ k, (∑ i, ∑ t, D i t k * (Y i t - (∑ j, D i t j * β j) - Hβ i t)) = 0) (h_normal_H : ∀ h : Unit → Time → ℝ, H h → (∑ i, ∑ t, h i t * (Y i t - (∑ j, D i t j * β j) - Hβ i t)) = 0) : β = (gramOf Dtilde)⁻¹.mulVec (numerOf Dtilde Ytilde) := by -- residual `e` set e : Unit → Time → ℝ := fun i t => Y i t - (∑ j, D i t j * β j) - Hβ i t with he -- step 1: each residualized coordinate is orthogonal to the residual have hDt_e : ∀ k, (∑ i, ∑ t, Dtilde i t k * e i t) = 0 := by intro k have h1 : (∑ i, ∑ t, D i t k * e i t) = 0 := h_normal_D k have h2 : (∑ i, ∑ t, Dproj i t k * e i t) = 0 := h_normal_H _ (hDproj_mem k) have hsplit : (∑ i, ∑ t, D i t k * e i t) = (∑ i, ∑ t, Dproj i t k * e i t) + (∑ i, ∑ t, Dtilde i t k * e i t) := by rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun i _ => ?_) rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun t _ => ?_) rw [hD i t k]; ring linarith [h1, h2, hsplit] -- step 2: expand the orthogonality into the matrix normal equation have hexp : ∀ k, (∑ i, ∑ t, Dtilde i t k * e i t) = numerOf Dtilde Ytilde k - (gramOf Dtilde).mulVec β k := by intro k have hmv : (gramOf Dtilde).mulVec β k = ∑ j, (∑ i, ∑ t, Dtilde i t k * Dtilde i t j) * β j := by simp only [mulVec, dotProduct, gramOf] -- cellwise split of `Dtilde·k * e` have hcell : ∀ i t, Dtilde i t k * e i t = Dtilde i t k * Yproj i t + Dtilde i t k * Ytilde i t - Dtilde i t k * (∑ j, D i t j * β j) - Dtilde i t k * Hβ i t := by intro i t simp only [he] rw [hY i t]; ring have hsum4 : (∑ i, ∑ t, Dtilde i t k * e i t) = (∑ i, ∑ t, Dtilde i t k * Yproj i t) + (∑ i, ∑ t, Dtilde i t k * Ytilde i t) - (∑ i, ∑ t, Dtilde i t k * (∑ j, D i t j * β j)) - (∑ i, ∑ t, Dtilde i t k * Hβ i t) := by have hcong : (∑ i, ∑ t, Dtilde i t k * e i t) = ∑ i, ∑ t, (Dtilde i t k * Yproj i t + Dtilde i t k * Ytilde i t - Dtilde i t k * (∑ j, D i t j * β j) - Dtilde i t k * Hβ i t) := Finset.sum_congr rfl (fun i _ => Finset.sum_congr rfl (fun t _ => hcell i t)) rw [hcong] simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib] -- the `D·β` cross term factors through the residualized Gram (cross terms vanish) have hDj : ∀ j, (∑ i, ∑ t, Dtilde i t k * D i t j) = ∑ i, ∑ t, Dtilde i t k * Dtilde i t j := by intro j have horth : (∑ i, ∑ t, Dtilde i t k * Dproj i t j) = 0 := hDtilde_orth k (fun i t => Dproj i t j) (hDproj_mem j) calc (∑ i, ∑ t, Dtilde i t k * D i t j) = (∑ i, ∑ t, Dtilde i t k * Dproj i t j) + (∑ i, ∑ t, Dtilde i t k * Dtilde i t j) := by rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun i _ => ?_) rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun t _ => ?_) rw [hD i t j]; ring _ = ∑ i, ∑ t, Dtilde i t k * Dtilde i t j := by rw [horth]; ring have hjsum : (∑ j, (∑ i, ∑ t, Dtilde i t k * D i t j) * β j) = ∑ j, (∑ i, ∑ t, Dtilde i t k * Dtilde i t j) * β j := Finset.sum_congr rfl (fun j _ => by rw [hDj j]) rw [hsum4, hmv, hYproj_orth k, hDtilde_orth k Hβ hHβ_mem, sum_dotRegressor Dtilde D β k, hjsum] unfold numerOf ring -- assemble: gramOf.mulVec β = numerOf have hmatrix : (gramOf Dtilde).mulVec β = numerOf Dtilde Ytilde := by funext k have := hexp k rw [hDt_e k] at this linarith [this] -- invert rw [← hmatrix, Matrix.mulVec_mulVec, Matrix.nonsing_inv_mul _ hgram_unit, Matrix.one_mulVec]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.matrix_fwl_eq_of_normalEqs · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:77
  • vector_mundlak_nuisance_unit_time theorem — Vector two-way Mundlak nuisance terms are unit/time additive, so the optional controls lie inside the same orthogonality class as for the scalar case.
    X :
    Unit → Time → K → ℝ
    Zvar :
    Z → Unit → ℝ
    Mvar :
    M → Time → ℝ
    h :
    Unit → Time → ℝ
    hh :
    IsUnitTimeAdditive h
    Proof (Lean source)
    theorem vector_mundlak_nuisance_unit_time (X : Unit → Time → K → ℝ) (Zvar : Z → Unit → ℝ) (Mvar : M → Time → ℝ) {h : Unit → Time → ℝ} (hh : IsVectorTwoWayMundlakNuisance X Zvar Mvar h) : IsUnitTimeAdditive h := by rcases hh with ⟨c, γu, γt, ζ, μ, hrep⟩ refine ⟨fun i => c + (∑ k, γu k * unitMean (fun i t => X i t k) i) + ∑ z, ζ z * Zvar z i, fun t => (∑ k, γt k * timeMean (fun i t => X i t k) t) + ∑ m, μ m * Mvar m t, ?_⟩ intro i t rw [hrep i t]; ring
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.vector_mundlak_nuisance_unit_time · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:188
  • sum_ite_one_mul theorem — Selecting a single coordinate via a 0/1 indicator collapses the coordinate sum to that coordinate's value.
    k :
    K
    f :
    K → ℝ
    (∑ k', (if k' = k then (1 : ℝ) else 0) * f k') = f k
    Proof (Lean source)
    theorem sum_ite_one_mul (k : K) (f : K → ℝ) : (∑ k', (if k' = k then (1 : ℝ) else 0) * f k') = f k := by rw [Finset.sum_eq_single k] · simp · intro k' _ hne; simp [hne] · intro h; exact absurd (Finset.mem_univ k) h
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.sum_ite_one_mul · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:203
  • vec_twfe_twm_optional_controls_invariant theorem — Adding or removing optional time-constant or time-only controls does not change the K-vector Mundlak coefficient, since both fits equal the vector TWFE coefficient.
    Z₁ M₁ Z₂ M₂ :
    Type*
    Fintype Z₁
    Fintype M₁
    Fintype Z₂
    Fintype M₂
    P :
    Zvar₁ :
    Z₁ → Unit → ℝ
    Mvar₁ :
    M₁ → Time → ℝ
    Zvar₂ :
    Z₂ → Unit → ℝ
    Mvar₂ :
    M₂ → Time → ℝ
    fit₁ :
    VectorTWMFit P Zvar₁ Mvar₁
    fit₂ :
    VectorTWMFit P Zvar₂ Mvar₂
    fit₁.beta = fit₂.beta
    Proof (Lean source)
    theorem vec_twfe_twm_optional_controls_invariant {Z₁ M₁ Z₂ M₂ : Type*} [Fintype Z₁] [Fintype M₁] [Fintype Z₂] [Fintype M₂] (P : VectorTWFEProblem Unit Time K) (Zvar₁ : Z₁ → Unit → ℝ) (Mvar₁ : M₁ → Time → ℝ) (Zvar₂ : Z₂ → Unit → ℝ) (Mvar₂ : M₂ → Time → ℝ) (fit₁ : VectorTWMFit P Zvar₁ Mvar₁) (fit₂ : VectorTWMFit P Zvar₂ Mvar₂) : fit₁.beta = fit₂.beta := by rw [vec_twfe_twm_equivalence P Zvar₁ Mvar₁ fit₁, vec_twfe_twm_equivalence P Zvar₂ Mvar₂ fit₂]
    Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.vec_twfe_twm_optional_controls_invariant · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorMundlak.lean:301