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

For finite sets of cohorts, periods, and covariate cells and a staggered-adoption cell system, the treated-cell set is the finite set of all cohort--period pairs designated as treated by that system.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
treatedCells P :
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

For finite sets of cohorts, periods, and covariate cells and a staggered-adoption cell system, the untreated-cell set is the finite set of all cohort--period pairs designated as untreated and used to fit the untreated-outcome regression.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
untreatedCells P :
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:81 · uses StaggeredATTCells
def tauCell reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

For finite sets of cohorts, periods, and covariate cells, a staggered-adoption cell system, a cohort, and a period, the cell average treatment effect on the treated is the covariate- weighted average, within that cohort, of the treated potential outcome minus the untreated potential outcome in that period.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
g :
Cohort
t :
Time
tauCell P g t :
∑ 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:89 · uses StaggeredATTCells
def tauAgg reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.StaggeredATTCells

For finite sets of cohorts, periods, and covariate cells, a staggered-adoption cell system, and a cohort-period weighting function, the aggregate average treatment effect on the treated is the weighted sum of cell average treatment effects over all treated cells.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
a :
Cohort → Time → ℝ
tauAgg P a :
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:98 · uses StaggeredATTCells
structure AggregateWeights reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

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

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
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:108 · uses StaggeredATTCells
def NoAnticipation reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells and a staggered-adoption cell system, no anticipation means that, for every cohort, every period designated untreated, and every covariate cell, that cohort's potential outcome equals its untreated potential outcome.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
g :
Cohort
t :
Time
P.untreatedCell g t
c :
NoAnticipation P :
Prop
P.YgMean g t c = P.Y0Mean g t c
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.NoAnticipation · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:115 · uses StaggeredATTCells
def ConditionalParallelTrendsAdditive reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells and a staggered-adoption cell system, conditional parallel trends in additive form means that there exist cohort-by-covariate and period-by- covariate functions whose sum equals the untreated potential-outcome mean for every cohort, period, and covariate cell.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
ConditionalParallelTrendsAdditive P :
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:123 · uses StaggeredATTCells
def IsCellAdditive reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells and a cohort-period-covariate function, the cell-additivity condition means that there exist cohort-by-covariate and period-by- covariate functions whose sum equals that function at every cell.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
d :
Cohort → Time → Covar → ℝ
IsCellAdditive d :
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:133
def UntreatedDesignIdentifies reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells and a staggered-adoption cell system, the untreated-design identification condition means that every additive cohort-period- covariate function which vanishes at every untreated cell also vanishes at every treated cell.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
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 :
UntreatedDesignIdentifies P :
Prop
d g t c = 0
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.UntreatedDesignIdentifies · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:141 · 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)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
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:159 · 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)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
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:209 · uses StaggeredATTCells
def toUntreatedFitWitness reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression

For finite sets of cohorts, periods, and covariate cells, the staggered-adoption cell system underlying the regression, and a saturated untreated-outcome regression, the untreated-fit witness retains its fitted untreated mean, additivity, untreated-cell weights, positivity condition, and untreated normal equations, while omitting its target-support and design-identification conditions.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
StaggeredATTCells Cohort Time Covar
shared
toUntreatedFitWitness S :
clause 1
m0 := S.m0
clause 2
additive := S.additive
clause 3
untreatedWeight := S.untreatedWeight
clause 4
untreatedWeight_pos := S.untreatedWeight_pos
clause 5
untreatedNormalEq := S.untreatedNormalEq
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.SaturatedUntreatedRegression.toUntreatedFitWitness · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/DID.lean:225 · 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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
StaggeredATTCells Cohort Time Covar
shared
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:320 · uses ConditionalParallelTrendsAdditive , NoAnticipation , SaturatedUntreatedRegression , StaggeredATTCells
def imputationTheta reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells, a staggered-adoption cell system, a saturated untreated-outcome regression, a cohort, and a period, the imputation residual mean is the within-cohort covariate-weighted average of the observed cell mean minus the fitted untreated mean.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
g :
Cohort
t :
Time
imputationTheta P S g t :
∑ 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:367 · uses SaturatedUntreatedRegression , StaggeredATTCells
def cellResidualNormalEq reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells, a staggered-adoption cell system, a saturated untreated-outcome regression, a proposed cell coefficient, a cohort, and a period, the cell residual normal equation states that the within-cohort covariate-weighted mean of observed outcome minus fitted untreated outcome minus that coefficient is zero.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
theta :
g :
Cohort
t :
Time
cellResidualNormalEq P S theta g t :
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:383 · uses SaturatedUntreatedRegression , StaggeredATTCells
def cellIndicator reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts and periods, a cohort, and a period, the saturated treated-cell indicator is one at that cohort--period pair and zero at every other pair.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
g :
Cohort
t :
Time
cellIndicator g t :
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:425
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)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
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:479 · 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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
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:513 · 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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
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:528 · uses FlexibleDIDEstimands , SaturatedUntreatedRegression , StaggeredATTCells , imputationTheta
def psiImp reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells, a staggered-adoption cell system, a saturated untreated-outcome regression, a flexible-DID estimand collection, and a cohort-period weighting function, the aggregate imputation estimand is the weighted sum of imputation coefficients over treated cells.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
a :
Cohort → Time → ℝ
psiImp P E a :
gt ∈ P.treatedCells, a gt.1 gt.2 * E.thetaImp gt.1 gt.2
def psiPOLS reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells, a staggered-adoption cell system, a saturated untreated-outcome regression, a flexible-DID estimand collection, and a cohort-period weighting function, the aggregate pooled-least-squares estimand is the weighted sum of pooled-least-squares coefficients over treated cells.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
a :
Cohort → Time → ℝ
psiPOLS P E a :
gt ∈ P.treatedCells, a gt.1 gt.2 * E.thetaPOLS gt.1 gt.2
def psiETWFE reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of cohorts, periods, and covariate cells, a staggered-adoption cell system, a saturated untreated-outcome regression, a flexible-DID estimand collection, and a cohort-period weighting function, the aggregate extended two-way- fixed-effects estimand is the weighted sum of extended two-way-fixed- effects coefficients over treated cells.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
a :
Cohort → Time → ℝ
psiETWFE P E a :
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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
hNA :
NoAnticipation P
g :
Cohort
t :
Time
hgt :
P.treatedCell g t
conclusion 1
E.thetaImp g t = P.tauCell g t
conclusion 2
E.thetaPOLS g t = P.tauCell g t
conclusion 3
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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
hNA :
NoAnticipation P
a :
Cohort → Time → ℝ
conclusion 1
psiImp P E a = P.tauAgg a
conclusion 2
psiPOLS P E a = P.tauAgg a
conclusion 3
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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
P :
StaggeredATTCells Cohort Time Covar
hNA :
NoAnticipation P
conclusion 1
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
conclusion 2
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.
    Cohort :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Covar :
    Type u_3
    StaggeredATTCells Cohort Time Covar
    shared
    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:242
  • cellResidualNormalEq_eq_imputationTheta theorem — A finite-cell residual normal equation identifies the coefficient with the imputation residual mean.
    Cohort :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Covar :
    Type u_3
    shared
    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:395
  • cellIndicator_normalEq_eq_cellResidual theorem — Saturated block-diagonalization for treated-cell indicators.
    Cohort :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Covar :
    Type u_3
    shared
    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:432
  • 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.
    Cohort :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Covar :
    Type u_3
    shared
    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:544
  • 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.
    Cohort :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Covar :
    Type u_3
    shared
    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:554
  • imputationTheta_eq_tauCell theorem — Imputation recovers the ATT cell once the saturated untreated prediction equals the untreated potential-outcome mean in target cells.
    Cohort :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Covar :
    Type u_3
    shared
    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:599
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

For finite sets of units and periods and a scalar two-way-fixed-effects regression problem, the residualized-design denominator is the sum of squared doubly demeaned regressor values over all unit--period observations.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
P :
twfeDenominator P :
∑ 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

For finite sets of units and periods and a scalar two-way-fixed-effects regression problem, the residualized numerator is the sum, over all unit--period observations, of the doubly demeaned regressor times the doubly demeaned outcome.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
P :
twfeNumerator P :
∑ i, ∑ t, ddot P.X i t * ddot P.Y i t
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.twfeNumerator · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:52 · uses ScalarTWFEProblem
def betaTWFE reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

For finite sets of units and periods and a scalar two-way-fixed-effects regression problem, the scalar two-way-fixed- effects coefficient is the residualized numerator divided by the residualized-design denominator.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
P :
betaTWFE P :
P.twfeNumerator / P.twfeDenominator
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem.betaTWFE · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/TWFE.lean:59 · uses ScalarTWFEProblem
def twfeNormalEq reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

For finite sets of units and periods, a scalar two-way- fixed-effects regression problem, and a proposed coefficient, the scalar two-way-fixed-effects normal equation states that the sum of the doubly demeaned regressor times the corresponding residual is zero.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
P :
β :
twfeNormalEq P β :
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:66 · uses ScalarTWFEProblem
def IsTwoWayMundlakNuisance reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite sets of units, periods, unit-level controls, and period-level controls, a scalar regressor, unit-level control functions, period-level control functions, and a candidate nuisance function, the two-way Mundlak nuisance condition holds exactly when the candidate is a constant plus arbitrary multiples of the regressor's unit means and period means and linear combinations of the supplied unit-level and period-level controls.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
Z :
Type u_3
shared
M :
Type u_4
shared
X :
Unit → Time → ℝ
Zvar :
Z → Unit → ℝ
Mvar :
M → Time → ℝ
h :
Unit → Time → ℝ
IsTwoWayMundlakNuisance X Zvar Mvar h :
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:148
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)
Unit :
Type u_1
shared
Time :
Type u_2
shared
Z :
Type u_3
shared
M :
Type u_4
shared
P :
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:178 · 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
Unit :
Type u_1
shared
Time :
Type u_2
shared
Z :
Type u_3
shared
M :
Type u_4
shared
P :
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:213 · 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    P :
    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:73
  • betaTWFE_unique theorem — Scalar full-rank uniqueness of the TWFE normal-equation solution.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    P :
    β :
    :
    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:105
  • 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Z :
    Type u_3
    shared
    M :
    Type u_4
    shared
    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:164
  • twfe_twm_residual_common theorem — Residualizing the scalar regressor against the two-way Mundlak nuisance span leaves the same residual as double demeaning.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    Z :
    Type u_3
    shared
    M :
    Type u_4
    shared
    P :
    Zvar :
    Z → Unit → ℝ
    Mvar :
    M → Time → ℝ
    conclusion 1
    IsUnitTimeAdditive (fun i t => P.X i t - ddot P.X i t)
    conclusion 2
    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:195
  • 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    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₁ :
    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:270
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

For finite unit, time-period, and regressor-coordinate sets, a vector-valued regressor array, a unit, a time period, and a regressor coordinate, the componentwise double-demeaned regressor is the scalar double demean of that coordinate over the finite balanced panel.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
X :
Unit → Time → K → ℝ
i :
Unit
t :
Time
k :
K
ddotVec X i t 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

For finite unit, time-period, and regressor-coordinate sets and a vector-valued regressor array, the residualized Gram matrix has entry (j,k)(j,k) equal to the finite sum, over units and time periods, of the product of the double-demeaned jj-th and kk-th regressor coordinates.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
X :
Unit → Time → K → ℝ
gram X :
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:49
def numer reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak

For finite unit, time-period, and regressor-coordinate sets, a vector-valued regressor array, and an outcome array, the residualized numerator vector has coordinate kk equal to the finite sum of the product of the double-demeaned kk-th regressor and the double-demeaned outcome.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
X :
Unit → Time → K → ℝ
Y :
Unit → Time → ℝ
numer X Y :
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:55
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:61
def betaTWFE reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem

For finite unit, time-period, and regressor-coordinate sets and a vector two-way-fixed-effects problem, the closed-form vector TWFE coefficient is the inverse residualized Gram matrix multiplied by the residualized outcome-regressor numerator vector.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
P :
VectorTWFEProblem Unit Time K
betaTWFE P :
K → ℝ
(gram P.X)⁻¹.mulVec (numer P.X P.Y)
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem.betaTWFE · Causalean/Panel/EstimandCharacterization/FlexibleDIDMundlak/VectorTWFE.lean:75 · uses VectorTWFEProblem
def vecTwfeNormalEq reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.VectorTWFEProblem

For finite unit, time-period, and regressor-coordinate sets, a vector two-way-fixed-effects problem, and a candidate coefficient vector, the vector TWFE normal-equation condition requires that, for every regressor coordinate, the finite inner product of its double-demeaned regressor with the double-demeaned outcome residual is zero.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
P :
VectorTWFEProblem Unit Time K
β :
K → ℝ
k :
vecTwfeNormalEq P β :
Prop
∑ 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:81 · 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
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
P :
VectorTWFEProblem Unit Time K
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:149 · 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
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
P :
VectorTWFEProblem Unit Time K
β :
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:158 · uses VectorTWFEProblem , betaTWFE , vecTwfeNormalEq
def toVector reviewed
Causalean.Panel.EstimandCharacterization.FlexibleDIDMundlak.ScalarTWFEProblem

For finite unit and time-period sets and a scalar two-way-fixed-effects problem, the associated one-coordinate vector two-way-fixed-effects problem has the same panel and outcome, uses the scalar regressor as its sole coordinate, and has a nonsingular residualized Gram matrix because the scalar double-demeaned regressor has a strictly positive sum of squares.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
P :
toVector P :
VectorTWFEProblem Unit Time (Fin 1)
clause 1
panel := P.panel
clause 2
Y := P.Y
clause 3
X := fun i t _ => P.X i t
clause 4
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:174 · 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    K :
    Type u_3
    shared
    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:92
  • 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    P :
    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:197
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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
Ω :
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

For finite cohort, time-period, and covariate sets, a measurable sample space with a measure, cohort-time-covariate cell events, untreated, cohort-specific, and observed population outcome functions, treated and untreated cell indicators, cohort shares, and within-cohort covariate weights, if every cell event is measurable, every cell has strictly positive measure, each of the three outcome functions is integrable on every cell, cohort shares are strictly positive on treated cells, covariate weights are nonnegative and sum to one within every cohort, and the observed outcome agrees pointwise with the cohort-specific outcome on treated cells and with the untreated outcome on untreated cells, the finite staggered-DID cell system uses the supplied shares, weights, and indicators and defines each outcome mean as its population event-conditional mean.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
Ω :
μ :
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 ω
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 :
StaggeredATTCells Cohort Time Covar
clause 1
cohortShare := cohortShare
clause 2
covarWeight := covarWeight
clause 3
treatedCell := treatedCell
clause 4
untreatedCell := untreatedCell
clause 5
Y0Mean g t c := eventCondExp μ (cellEvent g t c) Y0pop
clause 6
YgMean g t c := eventCondExp μ (cellEvent g t c) Ygpop
clause 7
observedMean g t c := eventCondExp μ (cellEvent g t c) Yobspop
clause 8
cohortShare_pos_on_treated := cohortShare_pos_on_treated
clause 9
covarWeight_nonneg := covarWeight_nonneg
clause 10
covarWeight_sum_one := covarWeight_sum_one
clause 11
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)
clause 12
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

For finite cohort, time-period, and covariate sets, a measurable sample space with a probability measure, cohort-time-covariate cell events, untreated, cohort-specific, and observed population outcome functions, treated and untreated cell indicators, cohort shares, and within-cohort covariate weights, if every cell event is measurable, every cell has strictly positive probability, each outcome function is integrable on every cell, cohort shares are strictly positive on treated cells, covariate weights are nonnegative and sum to one within every cohort, and pointwise consistency holds on treated and untreated cells, the finite staggered-DID cell system is the system constructed from the same data by the measure-based constructor.

Definition (Lean source)
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
Ω :
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 ω
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 :
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:121 · 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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
Ω :
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
Cohort :
Type u_1
shared
Time :
Type u_2
shared
Covar :
Type u_3
shared
Ω :
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

For finite sets of units, periods, and regressor coordinates and a residualized vector regressor, the residualized Gram matrix has as its coordinate pair entry the sum over unit--period observations of the product of the corresponding two regressor coordinates.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
Dt :
Unit → Time → K → ℝ
gramOf Dt :
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

For finite sets of units, periods, and regressor coordinates, a residualized vector regressor, and a residualized outcome, the residualized numerator vector has as each coordinate the sum over unit--period observations of that regressor coordinate times the outcome.

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

For finite sets of units, periods, regressor coordinates, unit-level controls, and period-level controls, a vector regressor, unit-level control functions, period-level control functions, and a candidate nuisance function, the vector two-way Mundlak nuisance condition holds exactly when the candidate is a constant plus linear combinations of every regressor coordinate's unit and period means and of the supplied unit-level and period-level controls.

Definition (Lean source)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
Z :
Type u_4
shared
M :
Type u_5
shared
X :
Unit → Time → K → ℝ
Zvar :
Z → Unit → ℝ
Mvar :
M → Time → ℝ
h :
Unit → Time → ℝ
IsVectorTwoWayMundlakNuisance X Zvar Mvar h :
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:182
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)
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
Z :
Type u_4
shared
M :
Type u_5
shared
P :
VectorTWFEProblem Unit Time K
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:223 · 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
Unit :
Type u_1
shared
Time :
Type u_2
shared
K :
Type u_3
shared
Z :
Type u_4
shared
M :
Type u_5
shared
P :
VectorTWFEProblem Unit Time K
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:243 · uses VectorTWFEProblem , betaTWFE , VectorTWMFit
7 supporting declarations (lemmas, instances)
  • gram_eq_gramOf theorem — gram is the residualized instance of the generic version.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    K :
    Type u_3
    shared
    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:52
  • numer_eq_numerOf theorem — numer is the residualized instance of the generic version.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    K :
    Type u_3
    shared
    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:56
  • sum_dotRegressor theorem — Reshuffle: a residualized regressor against a β-combination of regressors factors through the cross-Gram.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    K :
    Type u_3
    shared
    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:61
  • 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    K :
    Type u_3
    shared
    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:83
  • 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    K :
    Type u_3
    shared
    Z :
    Type u_4
    shared
    M :
    Type u_5
    shared
    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:199
  • sum_ite_one_mul theorem — Selecting a single coordinate via a 0/1 indicator collapses the coordinate sum to that coordinate's value.
    K :
    Type u_3
    shared
    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:214
  • 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.
    Unit :
    Type u_1
    shared
    Time :
    Type u_2
    shared
    K :
    Type u_3
    shared
    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
    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:312