Panel.Estimand­Characterization.Heterogeneous­TWFE

de Chaisemartin-D'Haultfœuille: negative-weight diagnostics for TWFE under heterogeneous effects.

Finite­Panel 18 core · 11 supporting This file formalizes the finite group-time algebra behind the de Chaisemartin-D'Haultfoeuille two-way fixed-effect estimand. ★ twfe_eq_untreatedBias_add_DWeightedTau★ twfe_eq_untreatedBias_add_treated_weighted_tau★ twfe_eq_treated_weighted_tau_of_zeroUntreatedContrast★ treated_omega_sum_eq_one★ treated_omega_neg_iff_Dtilde_neg★ treated_omega_pos_iff_Dtilde_pos★ treated_omega_zero_iff_Dtilde_zero★ exists_panel_with_positive_treated_effects_twfe_negative_of_negative_component

DCDH Finite Panel Algebra

This file formalizes the finite group-time algebra behind the de Chaisemartin-D'Haultfoeuille two-way fixed-effect estimand. DCDHPanel packages weighted cells, binary treatment, potential untreated means, treatment effects, and a residualized-treatment witness. The main results decompose DCDHPanel.betaTWFE into untreated bias plus treated-cell weighted effects (twfe_eq_untreatedBias_add_treated_weighted_tau), show that treated DCDH weights sum to one and have the sign of Dtilde, and prove finite sign-reversal constructions such as exists_panel_with_positive_treated_effects_twfe_negative_of_negative_component.

abbrev IsGTFE reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE

Group-time fixed-effect span, represented as additive group and period components.

Definition (Lean source)
abbrev IsGTFE {G T : Type*} (h : G → T → ℝ) : Prop := IsUnitTimeAdditive h
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.IsGTFE · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:84
structure DCDHPanel reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE

A finite de Chaisemartin-D'Haultfoeuille group-time panel: it bundles group-time cell weights, a binary treatment indicator, the observed outcome, the untreated potential outcome, cell-level treatment effects, and a residualized-treatment witness, subject to strict positivity and unit sum of the weights, the treatment indicator taking only the values zero and one, potential-outcome consistency — the observed outcome equals the untreated outcome plus the treatment indicator times the treatment effect, the residualized witness differing from the treatment indicator by a group-plus-time additive function, its orthogonality, in the weighted inner product, to every group-plus-time additive function, and a strictly positive weighted sum of its squares.

Definition (Lean source)
G T :
pi :
G → T → ℝ
D :
G → T → ℝ
Y :
G → T → ℝ
Y0 :
G → T → ℝ
tau :
G → T → ℝ
Dtilde :
G → T → ℝ
pi_pos :
∀ g t, 0 < pi g t
pi_sum_one :
∑ g, ∑ t, pi g t = 1
D_binary :
∀ g t, D g t = 0 ∨ D g t = 1
consistency :
∀ g t, Y g t = Y0 g t + D g t * tau g t
D_minus_resid_mem :
IsGTFE (fun g t => D g t - Dtilde g t)
Dtilde_orthogonal :
∀ h : G → T → ℝ
if
then
∑ g, ∑ t, pi g t * Dtilde g t * h g t = 0
SD_pos :
0 < ∑ g, ∑ t, pi g t * (Dtilde g t)^2
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:91
def SD reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Residualized-treatment denominator S_D.

Definition (Lean source)
def SD (P : DCDHPanel G T) : ℝ := ∑ g, ∑ t, P.pi g t * (P.Dtilde g t)^2
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.SD · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:122 · uses DCDHPanel
def betaTWFE reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Finite FWL/TWFE coefficient.

Definition (Lean source)
noncomputable def betaTWFE (P : DCDHPanel G T) : ℝ := (∑ g, ∑ t, P.pi g t * P.Dtilde g t * P.Y g t) / P.SD
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.betaTWFE · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:126 · uses DCDHPanel
def untreatedBias reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Untreated residual contrast divided by the residualized-treatment denominator.

Definition (Lean source)
noncomputable def untreatedBias (P : DCDHPanel G T) : ℝ := (∑ g, ∑ t, P.pi g t * P.Dtilde g t * P.Y0 g t) / P.SD
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.untreatedBias · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:130 · uses DCDHPanel
def omega reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Normalized DCDH cell weight, interpreted on treated cells.

Definition (Lean source)
noncomputable def omega (P : DCDHPanel G T) (g : G) (t : T) : ℝ := (P.pi g t * P.Dtilde g t) / P.SD
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.omega · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:135 · uses DCDHPanel
def treatedCells reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Treated cells {(g,t) | D_gt = 1}.

Definition (Lean source)
noncomputable def treatedCells (P : DCDHPanel G T) : Finset (G × T) := Finset.univ.filter (fun gt : G × T => P.D gt.1 gt.2 = 1)
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.treatedCells · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:139 · uses DCDHPanel
def DWeightedTau reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

All-cell treatment-effect component using the binary treatment indicator.

Definition (Lean source)
noncomputable def DWeightedTau (P : DCDHPanel G T) : ℝ := ∑ g, ∑ t, ((P.pi g t * P.Dtilde g t * P.D g t) / P.SD) * P.tau g t
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.DWeightedTau · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:143 · uses DCDHPanel
def treatedWeightedTau reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Treated-cell weighted treatment-effect component.

Definition (Lean source)
noncomputable def treatedWeightedTau (P : DCDHPanel G T) : ℝ := ∑ gt ∈ P.treatedCells, P.omega gt.1 gt.2 * P.tau gt.1 gt.2
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.treatedWeightedTau · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:147 · uses DCDHPanel
def zeroUntreatedResidualContrast reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Zero untreated residual contrast, the bias-free DCDH condition.

Definition (Lean source)
def zeroUntreatedResidualContrast (P : DCDHPanel G T) : Prop := ∑ g, ∑ t, P.pi g t * P.Dtilde g t * P.Y0 g t = 0
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.zeroUntreatedResidualContrast · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:151 · uses DCDHPanel
theorem twfe_eq_untreatedBias_add_DWeightedTau reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

DCDH finite TWFE decomposition (all-cell weighting). For a DCDH panel, the finite two-way fixed-effects (TWFE) coefficient decomposes as the sum of the untreated bias and the all-cell D-weighted treatment-effect component.

Formal statement
P :
P.betaTWFE = P.untreatedBias + P.DWeightedTau
Proof (Lean source)
theorem twfe_eq_untreatedBias_add_DWeightedTau (P : DCDHPanel G T) : P.betaTWFE = P.untreatedBias + P.DWeightedTau := by rw [betaTWFE, untreatedBias, DWeightedTau] simp_rw [P.consistency] simp_rw [mul_add, Finset.sum_add_distrib] rw [add_div] congr 1 rw [div_eq_mul_inv] rw [Finset.sum_mul] simp_rw [Finset.sum_mul] apply Finset.sum_congr rfl intro g _hg apply Finset.sum_congr rfl intro t _ht ring
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.twfe_eq_untreatedBias_add_DWeightedTau · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:201 · uses DCDHPanel , DWeightedTau , betaTWFE , untreatedBias
theorem twfe_eq_untreatedBias_add_treated_weighted_tau reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

DCDH finite TWFE decomposition (treated-cell weighting). For a DCDH panel, the finite TWFE coefficient decomposes as the sum of the untreated bias and the normalized treated-cell weighted sum of treatment effects.

Formal statement
P :
P.betaTWFE = P.untreatedBias + P.treatedWeightedTau
Proof (Lean source)
theorem twfe_eq_untreatedBias_add_treated_weighted_tau (P : DCDHPanel G T) : P.betaTWFE = P.untreatedBias + P.treatedWeightedTau := by rw [twfe_eq_untreatedBias_add_DWeightedTau, DWeightedTau_eq_treatedWeightedTau]
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.twfe_eq_untreatedBias_add_treated_weighted_tau · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:233 · uses DCDHPanel , betaTWFE , treatedWeightedTau , untreatedBias
theorem twfe_eq_treated_weighted_tau_of_zeroUntreatedContrast reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Zero untreated bias implies TWFE equals the treated-cell weighted effect. If the untreated-outcome residual contrast vanishes — the residualized-treatment-weighted average of the untreated potential outcome Y0 over the whole panel is zero, then the finite two-way fixed-effects (TWFE) coefficient equals the treated-cell weighted sum of treatment effects.

Formal statement
P :
h0 :
P.zeroUntreatedResidualContrast
P.betaTWFE = P.treatedWeightedTau
Proof (Lean source)
theorem twfe_eq_treated_weighted_tau_of_zeroUntreatedContrast (P : DCDHPanel G T) (h0 : P.zeroUntreatedResidualContrast) : P.betaTWFE = P.treatedWeightedTau := by rw [twfe_eq_untreatedBias_add_treated_weighted_tau] rw [untreatedBias, h0] simp
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.twfe_eq_treated_weighted_tau_of_zeroUntreatedContrast · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:240 · uses DCDHPanel , betaTWFE , treatedWeightedTau , zeroUntreatedResidualContrast
theorem treated_omega_sum_eq_one reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

DCDH weights sum to one. For a DCDH panel, the normalized DCDH weights sum to one over all treated cells.

Formal statement
P :
gt ∈ P.treatedCells, P.omega gt.1 gt.2 = 1
Proof (Lean source)
theorem treated_omega_sum_eq_one (P : DCDHPanel G T) : ∑ gt ∈ P.treatedCells, P.omega gt.1 gt.2 = 1 := by have hnum : ∑ gt ∈ P.treatedCells, P.pi gt.1 gt.2 * P.Dtilde gt.1 gt.2 = P.SD := by rw [← inner_Dtilde_D_eq_SD P] unfold treatedCells rw [← Fintype.sum_prod_type' (fun g t => P.pi g t * P.Dtilde g t * P.D g t)] simp_rw [Finset.sum_filter] exact (Finset.sum_congr rfl (fun gt _hgt => by rcases gt with ⟨g, t⟩ rcases P.D_binary g t with hD | hD · simp [hD] · simp [hD])).symm calc ∑ gt ∈ P.treatedCells, P.omega gt.1 gt.2 = (∑ gt ∈ P.treatedCells, P.pi gt.1 gt.2 * P.Dtilde gt.1 gt.2) / P.SD := by unfold omega simp_rw [div_eq_mul_inv] rw [← Finset.sum_mul] _ = 1 := by rw [hnum] exact div_self (ne_of_gt P.SD_pos)
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.treated_omega_sum_eq_one · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:253 · uses DCDHPanel , omega , treatedCells
theorem treated_omega_neg_iff_Dtilde_neg reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Sign equivalence for the DCDH weight (negative direction). For a DCDH panel and any cohort-period cell, the normalized weight ω_gt is negative exactly when the residualized treatment D̃_gt is negative.

Formal statement
P :
g :
G
t :
T
P.omega g t < 0 ↔ P.Dtilde g t < 0
Proof (Lean source)
theorem treated_omega_neg_iff_Dtilde_neg (P : DCDHPanel G T) {g : G} {t : T} : P.omega g t < 0 ↔ P.Dtilde g t < 0 := by simpa [omega, SD] using normalized_weight_neg_iff_residual_neg (P.pi_pos g t) P.SD_pos
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.treated_omega_neg_iff_Dtilde_neg · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:294 · uses DCDHPanel , omega
theorem treated_omega_pos_iff_Dtilde_pos reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Positive-weight direction of the DCDH sign characterization. For a DCDH panel and any cohort-period cell, the normalized weight ω_gt is positive exactly when the residualized treatment D̃_gt is positive.

Formal statement
P :
g :
G
t :
T
0 < P.omega g t ↔ 0 < P.Dtilde g t
Proof (Lean source)
theorem treated_omega_pos_iff_Dtilde_pos (P : DCDHPanel G T) {g : G} {t : T} : 0 < P.omega g t ↔ 0 < P.Dtilde g t := by simpa [omega, SD] using normalized_weight_pos_iff_residual_pos (P.pi_pos g t) P.SD_pos
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.treated_omega_pos_iff_Dtilde_pos · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:321 · uses DCDHPanel , omega
theorem treated_omega_zero_iff_Dtilde_zero reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Zero-weight direction of the DCDH sign characterization. For a DCDH panel and any cohort-period cell, the normalized weight ω_gt is zero exactly when the residualized treatment D̃_gt is zero.

Formal statement
P :
g :
G
t :
T
P.omega g t = 0 ↔ P.Dtilde g t = 0
Proof (Lean source)
theorem treated_omega_zero_iff_Dtilde_zero (P : DCDHPanel G T) {g : G} {t : T} : P.omega g t = 0 ↔ P.Dtilde g t = 0 := by simpa [omega, SD] using normalized_weight_zero_iff_residual_zero (P.pi_pos g t) P.SD_pos
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.treated_omega_zero_iff_Dtilde_zero · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:351 · uses DCDHPanel , omega
theorem exists_panel_with_positive_treated_effects_twfe_negative_of_negative_component reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE

Panel-level DCDH sign reversal. If the untreated-outcome residual contrast vanishes and the treated cells with negative normalized DCDH weight carry a strictly negative total weight, then there exists another finite DCDH panel — sharing the same cell weights, treatment indicator, untreated potential outcomes, and residualized treatment, but with strictly positive treatment effects on every cell and zero untreated residual contrast — whose two-way fixed-effects (TWFE) coefficient is strictly negative.

Formal statement
G T :
P :
h0 :
P.zeroUntreatedResidualContrast
h_neg_component :
gt ∈ (P.treatedCells.filter fun gt => P.omega gt.1 gt.2 < 0), P.omega gt.1 gt.2 < 0
∃ P' : DCDHPanel G T,
(∀ g t, P'.pi g t = P.pi g t) ∧
(∀ g t, P'.D g t = P.D g t) ∧
(∀ g t, P'.Y0 g t = P.Y0 g t) ∧
(∀ g t, P'.Dtilde g t = P.Dtilde g t) ∧
(∀ g t, 0 < P'.tau g t) ∧
P'.zeroUntreatedResidualContrast ∧
P'.betaTWFE < 0
Proof (Lean source)
theorem exists_panel_with_positive_treated_effects_twfe_negative_of_negative_component {G T : Type*} [Fintype G] [Fintype T] (P : DCDHPanel G T) (h0 : P.zeroUntreatedResidualContrast) (h_neg_component : ∑ gt ∈ (P.treatedCells.filter fun gt => P.omega gt.1 gt.2 < 0), P.omega gt.1 gt.2 < 0) : ∃ P' : DCDHPanel G T, (∀ g t, P'.pi g t = P.pi g t) ∧ (∀ g t, P'.D g t = P.D g t) ∧ (∀ g t, P'.Y0 g t = P.Y0 g t) ∧ (∀ g t, P'.Dtilde g t = P.Dtilde g t) ∧ (∀ g t, 0 < P'.tau g t) ∧ P'.zeroUntreatedResidualContrast ∧ P'.betaTWFE < 0 := by classical let w : G × T → ℝ := fun gt => if gt ∈ P.treatedCells then P.omega gt.1 gt.2 else 0 have hsum_w : ∑ gt, w gt = 1 := by calc ∑ gt, w gt = ∑ gt ∈ P.treatedCells, P.omega gt.1 gt.2 := by simp [w] _ = 1 := DCDHPanel.treated_omega_sum_eq_one P have hneg_w : ∑ gt ∈ (Finset.univ.filter fun gt => w gt < 0), w gt < 0 := by have hsum_eq : ∑ gt ∈ (Finset.univ.filter fun gt => w gt < 0), w gt = ∑ gt ∈ (P.treatedCells.filter fun gt => P.omega gt.1 gt.2 < 0), P.omega gt.1 gt.2 := by apply Finset.sum_congr · ext gt by_cases htreated : gt ∈ P.treatedCells · simp [w, htreated] · simp [w, htreated] · intro gt hgt have htreated : gt ∈ P.treatedCells := by exact (Finset.mem_filter.mp hgt).1 simp [w, htreated] rw [hsum_eq] exact h_neg_component obtain ⟨tau, htau_pos, hweighted_neg⟩ := exists_positive_effects_negative_weighted_sum_of_negative_component w hneg_w let P' : DCDHPanel G T := { pi := P.pi D := P.D Y := fun g t => P.Y0 g t + P.D g t * tau (g, t) Y0 := P.Y0 tau := fun g t => tau (g, t) Dtilde := P.Dtilde pi_pos := P.pi_pos pi_sum_one := P.pi_sum_one D_binary := P.D_binary consistency := by intro g t rfl D_minus_resid_mem := P.D_minus_resid_mem Dtilde_orthogonal := P.Dtilde_orthogonal SD_pos := P.SD_pos } have hzero' : P'.zeroUntreatedResidualContrast := by simpa [P', DCDHPanel.zeroUntreatedResidualContrast] using h0 have htreated_sum : P'.treatedWeightedTau = ∑ gt, w gt * tau gt := by calc P'.treatedWeightedTau = ∑ gt ∈ P.treatedCells, P.omega gt.1 gt.2 * tau gt := by simp [P', DCDHPanel.treatedWeightedTau, DCDHPanel.treatedCells, DCDHPanel.omega, DCDHPanel.SD] _ = ∑ gt, w gt * tau gt := by simp [w] refine ⟨P', ?_, ?_, ?_, ?_, ?_, hzero', ?_⟩ · intro g t rfl · intro g t rfl · intro g t rfl · intro g t rfl · intro g t exact htau_pos (g, t) · rw [DCDHPanel.twfe_eq_treated_weighted_tau_of_zeroUntreatedContrast P' hzero'] rw [htreated_sum] exact hweighted_neg
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.exists_panel_with_positive_treated_effects_twfe_negative_of_negative_component · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:455 · uses DCDHPanel , betaTWFE , omega , treatedCells , zeroUntreatedResidualContrast
11 supporting declarations (lemmas, instances)
  • inner_Dtilde_D_eq_SD_core theorem — Orthogonality of the residualized treatment against D - Dtilde gives the DCDH denominator identity.
    pi D Dtilde :
    G → T → ℝ
    hmem :
    IsGTFE (fun g t => D g t - Dtilde g t)
    horth :
    ∀ h : G → T → ℝ
    if
    then
    ∑ g, ∑ t, pi g t * Dtilde g t * h g t = 0
    ∑ g, ∑ t, pi g t * Dtilde g t * D g t = ∑ g, ∑ t, pi g t * (Dtilde g t)^2
    Proof (Lean source)
    theorem inner_Dtilde_D_eq_SD_core (pi D Dtilde : G → T → ℝ) (hmem : IsGTFE (fun g t => D g t - Dtilde g t)) (horth : ∀ h : G → T → ℝ, IsGTFE h → ∑ g, ∑ t, pi g t * Dtilde g t * h g t = 0) : ∑ g, ∑ t, pi g t * Dtilde g t * D g t = ∑ g, ∑ t, pi g t * (Dtilde g t)^2 := by have horth' : ∑ g, ∑ t, pi g t * Dtilde g t * (D g t - Dtilde g t) = 0 := horth (fun g t => D g t - Dtilde g t) hmem have hdiff : (∑ g, ∑ t, pi g t * Dtilde g t * D g t) - (∑ g, ∑ t, pi g t * (Dtilde g t)^2) = 0 := by rw [← horth'] simp_rw [mul_sub, Finset.sum_sub_distrib, pow_two] ring_nf exact sub_eq_zero.mp hdiff
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.inner_Dtilde_D_eq_SD_core · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:155
  • inner_Dtilde_D_eq_SD theorem — Orthogonality of the residualized treatment against D - Dtilde gives the DCDH denominator identity.
    P :
    ∑ g, ∑ t, P.pi g t * P.Dtilde g t * P.D g t = P.SD
    Proof (Lean source)
    theorem inner_Dtilde_D_eq_SD (P : DCDHPanel G T) : ∑ g, ∑ t, P.pi g t * P.Dtilde g t * P.D g t = P.SD := by simpa [SD] using inner_Dtilde_D_eq_SD_core P.pi P.D P.Dtilde P.D_minus_resid_mem P.Dtilde_orthogonal
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.inner_Dtilde_D_eq_SD · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:175
  • weighted_residual_contrast_eq_zero_of_isGTFE theorem — A weighted residual is orthogonal to every additive array, so its contrast with an additive untreated-outcome array vanishes.
    pi Dtilde Y0 :
    G → T → ℝ
    horth :
    ∀ h : G → T → ℝ
    if
    then
    ∑ g, ∑ t, pi g t * Dtilde g t * h g t = 0
    hY0 :
    ∑ g, ∑ t, pi g t * Dtilde g t * Y0 g t = 0
    Proof (Lean source)
    theorem weighted_residual_contrast_eq_zero_of_isGTFE (pi Dtilde Y0 : G → T → ℝ) (horth : ∀ h : G → T → ℝ, IsGTFE h → ∑ g, ∑ t, pi g t * Dtilde g t * h g t = 0) (hY0 : IsGTFE Y0) : ∑ g, ∑ t, pi g t * Dtilde g t * Y0 g t = 0 := horth Y0 hY0
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.weighted_residual_contrast_eq_zero_of_isGTFE · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:182
  • zeroUntreatedResidualContrast_of_Y0_mem_gtfe theorem — Group-plus-period untreated means imply the zero untreated residual contrast.
    P :
    hY0 :
    IsGTFE P.Y0
    P.zeroUntreatedResidualContrast
    Proof (Lean source)
    theorem zeroUntreatedResidualContrast_of_Y0_mem_gtfe (P : DCDHPanel G T) (hY0 : IsGTFE P.Y0) : P.zeroUntreatedResidualContrast := by simpa [zeroUntreatedResidualContrast] using weighted_residual_contrast_eq_zero_of_isGTFE P.pi P.Dtilde P.Y0 P.Dtilde_orthogonal hY0
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.zeroUntreatedResidualContrast_of_Y0_mem_gtfe · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:192
  • DWeightedTau_eq_treatedWeightedTau theorem — The all-cell D-weighted component is the same as the treated-cell sum.
    P :
    P.DWeightedTau = P.treatedWeightedTau
    Proof (Lean source)
    theorem DWeightedTau_eq_treatedWeightedTau (P : DCDHPanel G T) : P.DWeightedTau = P.treatedWeightedTau := by unfold DWeightedTau treatedWeightedTau treatedCells omega rw [← Fintype.sum_prod_type' (fun g t => P.pi g t * P.Dtilde g t * P.D g t / P.SD * P.tau g t)] simp_rw [Finset.sum_filter] exact Finset.sum_congr rfl (fun gt _hgt => by rcases gt with ⟨g, t⟩ rcases P.D_binary g t with hD | hD · simp [hD] · simp [hD])
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.DWeightedTau_eq_treatedWeightedTau · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:220
  • normalized_weight_neg_iff_residual_neg theorem — Dividing a positive cell mass times a residual by a positive normalizer preserves whether the residual is negative.
    pi Dtilde SD :
    hpi :
    0 < pi
    hSD :
    0 < SD
    pi * Dtilde / SD < 0 ↔ Dtilde < 0
    Proof (Lean source)
    theorem normalized_weight_neg_iff_residual_neg {pi Dtilde SD : ℝ} (hpi : 0 < pi) (hSD : 0 < SD) : pi * Dtilde / SD < 0 ↔ Dtilde < 0 := by constructor · intro h have hnum : pi * Dtilde < 0 := ((div_neg_iff.mp h).resolve_left (fun hpos => not_lt_of_gt hSD hpos.2)).1 nlinarith [hpi] · intro h exact div_neg_of_neg_of_pos (mul_neg_of_pos_of_neg hpi h) hSD
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.normalized_weight_neg_iff_residual_neg · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:280
  • normalized_weight_pos_iff_residual_pos theorem — Dividing a positive cell mass times a residual by a positive normalizer preserves whether the residual is positive.
    pi Dtilde SD :
    hpi :
    0 < pi
    hSD :
    0 < SD
    0 < pi * Dtilde / SD ↔ 0 < Dtilde
    Proof (Lean source)
    theorem normalized_weight_pos_iff_residual_pos {pi Dtilde SD : ℝ} (hpi : 0 < pi) (hSD : 0 < SD) : 0 < pi * Dtilde / SD ↔ 0 < Dtilde := by rw [div_pos_iff_of_pos_right hSD] constructor · intro h rcases lt_trichotomy Dtilde 0 with h' | h' | h' · exact absurd (mul_neg_of_pos_of_neg hpi h') (not_lt.mpr (le_of_lt h)) · simp [h'] at h · exact h' · intro h exact mul_pos hpi h
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.normalized_weight_pos_iff_residual_pos · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:306
  • normalized_weight_zero_iff_residual_zero theorem — A positive cell mass and positive normalizer make the normalized weight zero exactly when its residual is zero.
    pi Dtilde SD :
    hpi :
    0 < pi
    hSD :
    0 < SD
    pi * Dtilde / SD = 0 ↔ Dtilde = 0
    Proof (Lean source)
    theorem normalized_weight_zero_iff_residual_zero {pi Dtilde SD : ℝ} (hpi : 0 < pi) (hSD : 0 < SD) : pi * Dtilde / SD = 0 ↔ Dtilde = 0 := by rw [div_eq_zero_iff] constructor · intro h rcases h with hnum | hSD0 · rcases mul_eq_zero.mp hnum with hpi0 | hDt · exact absurd hpi0 (ne_of_gt hpi) · exact hDt · exact absurd hSD0 (ne_of_gt hSD) · intro h left rw [h, mul_zero]
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.normalized_weight_zero_iff_residual_zero · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:334
  • two_cell_signed_weights_positive_effects_negative_sum theorem — Two-cell signed-weight calculation from the DCDH sign-reversal example.
    c ε M :
    hc :
    0 < c
    :
    0 < ε
    hM :
    ((1 + c) * ε) / c < M
    0 < ε ∧ 0 < M ∧ (1 + c) * ε + (-c) * M < 0
    Proof (Lean source)
    theorem two_cell_signed_weights_positive_effects_negative_sum {c ε M : ℝ} (hc : 0 < c) (hε : 0 < ε) (hM : ((1 + c) * ε) / c < M) : 0 < ε ∧ 0 < M ∧ (1 + c) * ε + (-c) * M < 0 := by constructor · exact hε constructor · have hnum_pos : 0 < (1 + c) * ε := by nlinarith have hfrac_pos : 0 < ((1 + c) * ε) / c := by positivity linarith · have hdom : (1 + c) * ε < c * M := by have hmul := mul_lt_mul_of_pos_left hM hc field_simp [hc.ne'] at hmul nlinarith nlinarith
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.two_cell_signed_weights_positive_effects_negative_sum · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:365
  • exists_positive_effects_negative_weighted_sum_of_negative_component theorem — Finite signed-average construction: if normalized weights have a strictly negative component, some strictly positive effects have a negative weighted sum.
    ι :
    Type*
    w :
    ι → ℝ
    h_neg_component :
    ∑ i ∈ (Finset.univ.filter fun i => w i < 0), w i < 0
    ∃ tau : ι → ℝ, (∀ i, 0 < tau i) ∧ ∑ i, w i * tau i < 0
    Proof (Lean source)
    theorem exists_positive_effects_negative_weighted_sum_of_negative_component {ι : Type*} [Fintype ι] (w : ι → ℝ) (h_neg_component : ∑ i ∈ (Finset.univ.filter fun i => w i < 0), w i < 0) : ∃ tau : ι → ℝ, (∀ i, 0 < tau i) ∧ ∑ i, w i * tau i < 0 := by classical let N : Finset ι := Finset.univ.filter fun i => w i < 0 let B : ℝ := ∑ i ∈ (Finset.univ.filter fun i => ¬ w i < 0), w i have hAneg : (∑ i ∈ N, w i) < 0 := by simpa [N] using h_neg_component have hden_pos : 0 < -(∑ i ∈ N, w i) := by linarith obtain ⟨M, hM⟩ := exists_gt (max 0 (B / (-(∑ i ∈ N, w i)))) have hMpos : 0 < M := lt_of_le_of_lt (le_max_left _ _) hM have hBlt : B < M * (-(∑ i ∈ N, w i)) := by have hratio : B / (-(∑ i ∈ N, w i)) < M := lt_of_le_of_lt (le_max_right _ _) hM have hmul := mul_lt_mul_of_pos_right hratio hden_pos rw [div_mul_cancel₀ B (ne_of_gt hden_pos)] at hmul simpa [mul_comm, mul_left_comm, mul_assoc] using hmul refine ⟨fun i => if w i < 0 then M else 1, ?_, ?_⟩ · intro i by_cases hi : w i < 0 · simp [hi, hMpos] · simp [hi] · have hsum_split : ∑ i, w i * (if w i < 0 then M else 1) = M * (∑ i ∈ N, w i) + B := by simp only [N, B, Finset.sum_filter] simp_rw [mul_ite, mul_one] rw [Finset.mul_sum, ← Finset.sum_add_distrib] apply Finset.sum_congr rfl intro i _hi by_cases hneg : w i < 0 · simp [hneg] ring · simp [hneg] rw [hsum_split] nlinarith
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.exists_positive_effects_negative_weighted_sum_of_negative_component · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:384
  • neg_component_of_exists_Dtilde_neg theorem — If some treated cell has negative residualized treatment, then the total weight over negatively weighted treated cells is strictly negative.
    G T :
    P :
    h :
    ∃ (g : G) (t : T), P.D g t = 1 ∧ P.Dtilde g t < 0
    gt ∈ (P.treatedCells.filter fun gt => P.omega gt.1 gt.2 < 0), P.omega gt.1 gt.2 < 0
    Proof (Lean source)
    theorem neg_component_of_exists_Dtilde_neg {G T : Type*} [Fintype G] [Fintype T] (P : DCDHPanel G T) (h : ∃ (g : G) (t : T), P.D g t = 1 ∧ P.Dtilde g t < 0) : ∑ gt ∈ (P.treatedCells.filter fun gt => P.omega gt.1 gt.2 < 0), P.omega gt.1 gt.2 < 0 := by obtain ⟨g₀, t₀, hD, hDt⟩ := h let S := P.treatedCells.filter (fun gt => P.omega gt.1 gt.2 < 0) have hmem : (g₀, t₀) ∈ S := by simp only [S, mem_filter, DCDHPanel.treatedCells, mem_filter, Finset.mem_univ, true_and] exact ⟨hD, (DCDHPanel.treated_omega_neg_iff_Dtilde_neg P).mpr hDt⟩ have hle : ∀ gt ∈ S, P.omega gt.1 gt.2 ≤ 0 := fun gt hgt => le_of_lt (Finset.mem_filter.mp hgt).2 -- Finset.sum_lt_sum : (∀ i ∈ s, f i ≤ g i) → (∃ i ∈ s, f i < g i) → sum f < sum g have key : ∑ gt ∈ S, P.omega gt.1 gt.2 < ∑ _gt ∈ S, (0 : ℝ) := Finset.sum_lt_sum hle ⟨(g₀, t₀), hmem, (Finset.mem_filter.mp hmem).2⟩ simpa using key
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.neg_component_of_exists_Dtilde_neg · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FinitePanel.lean:426
FWLBridge 3 core · 2 supporting FinitePanel.lean takes the residualized treatment D̃ as a *primitive orthogonality witness*: it merely posits the membership D − D̃ ∈ H_GT, the orthogonality ∑ π D̃ h = 0, and positivity S_D > 0. ★ ofTwoWayPanel★ ofTwoWayPanel_betaTWFE

DCDH residualized treatment as a derived FWL residual

FinitePanel.lean takes the residualized treatment as a primitive orthogonality witness: it merely posits the membership D − D̃ ∈ H_GT, the orthogonality ∑ π D̃ h = 0, and positivity S_D > 0. The paper, however, derives as the Frisch–Waugh–Lovell residual of the treatment projected on the two-way fixed-effect span — i.e. the double-demeaned treatment .

This file verifies, for the uniform balanced panel, that the DCDH residualized treatment can be constructed from the usual two-way fixed-effect residual. It builds a genuine DCDHPanel whose Dtilde is the double-demeaned treatment UniformTwoWayPanel.ddot D, with the membership and orthogonality fields proved from UniformTwoWayPanel (sub_ddot_eq_unitTimeProjection, unitTimeProjection_additive, ddot_orthogonal_unit_time) rather than assumed.

Only S_D > 0 (nonzero double-demeaned treatment variation — the genuine identification input that the treatment is not collinear with the FE span) and the binary-treatment / consistency primitives remain as hypotheses, exactly as in the source. No measure theory is used: the construction is pure uniform finite-panel algebra.

def uniformWeight reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE

Uniform unit-period cell weight 1/(|G|·|T|).

Definition (Lean source)
noncomputable def uniformWeight (G T : Type*) [Fintype G] [Fintype T] : ℝ := ((Fintype.card G : ℝ) * (Fintype.card T : ℝ))⁻¹
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.uniformWeight · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FWLBridge.lean:41
def ofTwoWayPanel reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE

Builds the uniform balanced-panel DCDH structure whose residualized treatment is the Frisch-Waugh-Lovell double-demeaned treatment.

Definition (Lean source)
noncomputable def ofTwoWayPanel (balanced : UniformTwoWayPanel.BalancedPanel G T) (D Y Y0 tau : G → T → ℝ) (hD_binary : ∀ g t, D g t = 0 ∨ D g t = 1) (hconsistency : ∀ g t, Y g t = Y0 g t + D g t * tau g t) (hSD : 0 < ∑ g, ∑ t, uniformWeight G T * (ddot D g t) ^ 2) : DCDHPanel G T where pi := fun _ _ => uniformWeight G T D := D Y := Y Y0 := Y0 tau := tau Dtilde := ddot D pi_pos := fun _ _ => @uniformWeight_pos G T _ _ (Fintype.card_pos_iff.mp (lt_of_lt_of_le (by decide : 0 < 2) balanced.unit_card_ge_two)) (Fintype.card_pos_iff.mp (lt_of_lt_of_le (by decide : 0 < 2) balanced.time_card_ge_two)) pi_sum_one := by have hcard : ((Fintype.card G : ℝ) * (Fintype.card T : ℝ)) ≠ 0 := by have hG : (0 : ℝ) < (Fintype.card G : ℝ) := by exact_mod_cast lt_of_lt_of_le (by decide : 0 < 2) balanced.unit_card_ge_two have hT : (0 : ℝ) < (Fintype.card T : ℝ) := by exact_mod_cast lt_of_lt_of_le (by decide : 0 < 2) balanced.time_card_ge_two exact ne_of_gt (mul_pos hG hT) simp only [uniformWeight, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] rw [← mul_assoc] rw [mul_inv_cancel₀ hcard] D_binary := hD_binary consistency := hconsistency D_minus_resid_mem := by refine ⟨unitMean D, fun t => timeMean D t - grandMean D, ?_⟩ intro i t have := UniformTwoWayPanel.sub_ddot_eq_unitTimeProjection D i t simp only [UniformTwoWayPanel.unitTimeProjection] at this linarith [this] Dtilde_orthogonal := by intro h hh have horth : inner (ddot D) h = 0 := UniformTwoWayPanel.ddot_orthogonal_unit_time (lt_of_lt_of_le (by decide) balanced.unit_card_ge_two) (lt_of_lt_of_le (by decide) balanced.time_card_ge_two) D h hh have : ∑ g, ∑ t, uniformWeight G T * ddot D g t * h g t = uniformWeight G T * inner (ddot D) h := by unfold inner rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun g _ => ?_) rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun t _ => ?_) ring rw [this, horth, mul_zero] SD_pos := hSD
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.ofTwoWayPanel · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FWLBridge.lean:55 · uses DCDHPanel , uniformWeight , BalancedPanel , ddot
theorem ofTwoWayPanel_betaTWFE reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE

The DCDH TWFE coefficient of the FWL-derived panel equals the uniform-panel Frisch–Waugh–Lovell residualized coefficient of Y on the double-demeaned treatment. For a uniform balanced panel and outcome, treatment, untreated-outcome, and effect arrays Y, D, Y0, tau, suppose the treatment is binary, the observed outcome equals the untreated outcome plus the treatment times the effect (consistency), and the double-demeaned treatment has strictly positive uniformly-weighted variation. Then the two-way fixed-effects (TWFE) coefficient of the DCDH panel built from this data by ofTwoWayPanel equals the Frisch–Waugh–Lovell residualized coefficient of Y regressed on the double-demeaned treatment ddot D.

Formal statement
balanced :
UniformTwoWayPanel.BalancedPanel G T
D Y Y0 tau :
G → T → ℝ
hD_binary :
∀ g t, D g t = 0 ∨ D g t = 1
hconsistency :
∀ g t, Y g t = Y0 g t + D g t * tau g t
hSD :
0 < ∑ g, ∑ t, uniformWeight G T * (ddot D g t) ^ 2
(ofTwoWayPanel balanced D Y Y0 tau hD_binary hconsistency hSD).betaTWFE
Proof (Lean source)
theorem ofTwoWayPanel_betaTWFE (balanced : UniformTwoWayPanel.BalancedPanel G T) (D Y Y0 tau : G → T → ℝ) (hD_binary : ∀ g t, D g t = 0 ∨ D g t = 1) (hconsistency : ∀ g t, Y g t = Y0 g t + D g t * tau g t) (hSD : 0 < ∑ g, ∑ t, uniformWeight G T * (ddot D g t) ^ 2) : (ofTwoWayPanel balanced D Y Y0 tau hD_binary hconsistency hSD).betaTWFE = finiteResidualizedCoefficient (ddot D) Y := by have hwpos : 0 < uniformWeight G T := @uniformWeight_pos G T _ _ (Fintype.card_pos_iff.mp (lt_of_lt_of_le (by decide : 0 < 2) balanced.unit_card_ge_two)) (Fintype.card_pos_iff.mp (lt_of_lt_of_le (by decide : 0 < 2) balanced.time_card_ge_two)) set P := ofTwoWayPanel balanced D Y Y0 tau hD_binary hconsistency hSD with hP have hnum : (∑ g, ∑ t, P.pi g t * P.Dtilde g t * P.Y g t) = uniformWeight G T * inner (ddot D) Y := by change (∑ g, ∑ t, uniformWeight G T * ddot D g t * Y g t) = uniformWeight G T * inner (ddot D) Y unfold inner rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun g _ => ?_) rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun t _ => ?_) ring have hden : P.SD = uniformWeight G T * inner (ddot D) (ddot D) := by change (∑ g, ∑ t, uniformWeight G T * (ddot D g t) ^ 2) = uniformWeight G T * inner (ddot D) (ddot D) unfold inner rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun g _ => ?_) rw [Finset.mul_sum] refine Finset.sum_congr rfl (fun t _ => ?_) ring rw [DCDHPanel.betaTWFE, hnum, hden, finiteResidualizedCoefficient] rw [mul_div_mul_left _ _ (ne_of_gt hwpos)]
2 supporting declarations (lemmas, instances)
  • uniformWeight_pos theorem — For finite nonempty group and time types, the uniform unit-period cell weight is strictly positive.
    Nonempty G
    Nonempty T
    Proof (Lean source)
    theorem uniformWeight_pos [Nonempty G] [Nonempty T] : 0 < uniformWeight G T := by have hG : (0 : ℝ) < (Fintype.card G : ℝ) := by exact_mod_cast (Fintype.card_pos : 0 < Fintype.card G) have hT : (0 : ℝ) < (Fintype.card T : ℝ) := by exact_mod_cast (Fintype.card_pos : 0 < Fintype.card T) exact inv_pos.mpr (mul_pos hG hT)
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.uniformWeight_pos · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FWLBridge.lean:45
  • ofTwoWayPanel_Dtilde theorem — The residualized treatment of ofTwoWayPanel is exactly the double-demeaned treatment D̈.
    balanced :
    UniformTwoWayPanel.BalancedPanel G T
    D Y Y0 tau :
    G → T → ℝ
    hD_binary :
    ∀ g t, D g t = 0 ∨ D g t = 1
    hconsistency :
    ∀ g t, Y g t = Y0 g t + D g t * tau g t
    hSD :
    0 < ∑ g, ∑ t, uniformWeight G T * (ddot D g t) ^ 2
    (ofTwoWayPanel balanced D Y Y0 tau hD_binary hconsistency hSD).Dtilde = ddot D
    Proof (Lean source)
    @[simp] theorem ofTwoWayPanel_Dtilde (balanced : UniformTwoWayPanel.BalancedPanel G T) (D Y Y0 tau : G → T → ℝ) (hD_binary : ∀ g t, D g t = 0 ∨ D g t = 1) (hconsistency : ∀ g t, Y g t = Y0 g t + D g t * tau g t) (hSD : 0 < ∑ g, ∑ t, uniformWeight G T * (ddot D g t) ^ 2) : (ofTwoWayPanel balanced D Y Y0 tau hD_binary hconsistency hSD).Dtilde = ddot D := rfl
    Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.ofTwoWayPanel_Dtilde · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/FWLBridge.lean:119
Population­Bridge 1 core · 0 supporting This file connects the finite DCDH panel fields to a probability model with cell events and potential outcomes. ★ ofPopulation

DCDH Population Bridge

This file connects the finite DCDH panel fields to a probability model with cell events and potential outcomes. The constructor DCDHPanel.ofPopulation builds a finite panel whose cell weights are cell probabilities, whose Y and Y0 fields are population cell means, and whose tau field is the difference between the Y1 and Y0 cell means. Its consistency and pi_sum_one fields are derived from the shared cell-partition mean-consistency and finite-partition mass identities.

def ofPopulation reviewed
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel

Builds a finite DCDH panel from a population model.

Definition (Lean source)
noncomputable def DCDHPanel.ofPopulation {G T : Type*} [Fintype G] [Fintype T] {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (cellEvent : G → T → Set Ω) (Yfac Y0pop Y1pop : Ω → ℝ) (d : G → T → ℝ) (Dtilde : G → T → ℝ) (hmeas : ∀ g t, MeasurableSet (cellEvent g t)) (hdisj : Pairwise (onFun Disjoint (fun p : G × T => cellEvent p.1 p.2))) (hcov : (⋃ p : G × T, cellEvent p.1 p.2) = univ) (hpos : ∀ g t, 0 < (μ (cellEvent g t)).toReal) (hdbin : ∀ g t, d g t = 0 ∨ d g t = 1) (hcons : ∀ g t, ∀ ω ∈ cellEvent g t, Yfac ω = Y0pop ω + d g t * (Y1pop ω - Y0pop ω)) (hDmem : IsGTFE (fun g t => d g t - Dtilde g t)) (hDorth : ∀ h : G → T → ℝ, IsGTFE h → ∑ g, ∑ t, (μ (cellEvent g t)).toReal * Dtilde g t * h g t = 0) (hSD : 0 < ∑ g, ∑ t, (μ (cellEvent g t)).toReal * (Dtilde g t) ^ 2) : DCDHPanel G T := let cells : CellPartition μ (G × T) := { cell := fun p => cellEvent p.1 p.2 cell_meas := fun p => hmeas p.1 p.2 cell_disj := hdisj cell_cov := hcov cell_pos := fun p => hpos p.1 p.2 } { pi := fun g t => cells.mass (g, t) D := d Y := fun g t => cells.mean Yfac (g, t) Y0 := fun g t => cells.mean Y0pop (g, t) tau := fun g t => cells.mean Y1pop (g, t) - cells.mean Y0pop (g, t) Dtilde := Dtilde pi_pos := hpos pi_sum_one := by rw [← Fintype.sum_prod_type]; exact cells.mass_sum_one D_binary := hdbin consistency := fun g t => cells.mean_consistency (g, t) Yfac Y0pop Y1pop (hdbin g t) (hcons g t) D_minus_resid_mem := hDmem Dtilde_orthogonal := hDorth SD_pos := hSD }
Causalean.Panel.EstimandCharacterization.HeterogeneousTWFE.DCDHPanel.ofPopulation · Causalean/Panel/EstimandCharacterization/HeterogeneousTWFE/PopulationBridge.lean:45 · uses DCDHPanel , IsGTFE