Panel.Estimand­Characterization.Staggered­TWFEDecomposition.Pairwise

This file reduces Goodman-Bacon denominator and numerator terms to ordered-pair centered-treatment contributions.

Algebra 4 core · 11 supporting This file reduces Goodman-Bacon denominator and numerator terms to ordered-pair centered-treatment contributions. ★ VD_eq_pairwise_centeredD

Goodman-Bacon Pairwise Algebra

This file reduces Goodman-Bacon denominator and numerator terms to ordered-pair centered-treatment contributions. It is the algebraic bridge between generic finite weighted covariance identities and the adoption-window case analysis that produces the three comparison types in the decomposition.

def centeredD reviewed
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition

For a cohort panel, a cohort, and a period, the cohort-demeaned treatment path is that cohort's treatment indicator in the period minus its average treatment indicator across all periods.

Definition (Lean source)
𝒢 :
Type u_1
shared
T :
ℕ
shared
P :
g :
𝒢
t :
Fin T
centeredD P g t :
ℝ
D P g t - barD P g
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.centeredD · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:122 · uses CohortPanel
def vdPairContribution reviewed
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition

For a cohort panel and two cohorts, the ordered-pair contribution to residualized-treatment variance is one half of their share product divided by the number of periods, multiplied by the sum of squared differences between their cohort-demeaned treatment paths.

Definition (Lean source)
𝒢 :
Type u_1
shared
T :
ℕ
shared
P :
g u :
𝒢
vdPairContribution P g u :
ℝ
(P.p g * P.p u / (2 * (T : ℝ))) * ∑ t, (centeredD P g t - centeredD P u t)^2
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.vdPairContribution · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:126 · uses CohortPanel
def numPairContribution reviewed
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition

For a cohort panel and two cohorts, the ordered-pair contribution to the two-way-fixed-effects numerator is one half of their share product divided by the number of periods, multiplied by the sum of the product of their demeaned-treatment difference and factual-outcome difference.

Definition (Lean source)
𝒢 :
Type u_1
shared
T :
ℕ
shared
P :
g u :
𝒢
numPairContribution P g u :
ℝ
(P.p g * P.p u / (2 * (T : ℝ))) * ∑ t, (centeredD P g t - centeredD P u t) * (P.Y g t - P.Y u t)
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.numPairContribution · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:136 · uses CohortPanel
lemma VD_eq_pairwise_centeredD reviewed
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition

For a cohort panel, the residualized-treatment variance VD P equals the sum, over all ordered pairs of cohorts, of their pairwise centered-treatment contribution vdPairContribution P g u.

Formal statement
𝒢 :
Type u_1
shared
T :
ℕ
shared
P :
VD P = ∑ g, ∑ u, vdPairContribution P g u
Proof (Lean source)
lemma VD_eq_pairwise_centeredD (P : CohortPanel 𝒢 T) : VD P = ∑ g, ∑ u, vdPairContribution P g u := by classical calc VD P = (T : ℝ)⁻¹ * ∑ t, ∑ g, P.p g * (Dtilde P g t)^2 := by unfold VD exact sum_weight_over_T_commute P (fun g t => (Dtilde P g t)^2) _ = (T : ℝ)⁻¹ * ∑ t, ∑ g, P.p g * (centeredD P g t - ∑ h, P.p h * centeredD P h t)^2 := by congr 1 refine Finset.sum_congr rfl ?_ intro t _ht refine Finset.sum_congr rfl ?_ intro g _hg rw [Dtilde_eq_centeredD_sub_weighted_mean] _ = (T : ℝ)⁻¹ * ∑ t, ((1 / 2) * ∑ g, ∑ u, P.p g * P.p u * (centeredD P g t - centeredD P u t)^2) := by congr 1 refine Finset.sum_congr rfl ?_ intro t _ht exact weighted_center_var (fun g => P.p g) (fun g => centeredD P g t) P.p_sum_one (by norm_num) _ = ∑ g, ∑ u, vdPairContribution P g u := by unfold vdPairContribution exact pairwise_sum_normalize P (fun g u t => (centeredD P g t - centeredD P u t)^2)
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.VD_eq_pairwise_centeredD · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:396 · uses CohortPanel , VD , vdPairContribution
11 supporting declarations (lemmas, instances)
  • weighted_center_cov_uncentered_right lemma — For a finite collection with weights summing to one, the weighted sum of deviations of one quantity from its weighted mean times another quantity equals one half of the weighted sum of pairwise differences in the two quantities.
    ι :
    Type*
    p x y :
    ι → ℝ
    hp :
    ∑ i, p i = 1
    ∑ i, p i * (x i - ∑ j, p j * x j) * y i
    = (1 / 2) * ∑ i, ∑ j, p i * p j * (x i - x j) * (y i - y j)
    Proof (Lean source)
    lemma weighted_center_cov_uncentered_right {ι : Type*} [Fintype ι] (p x y : ι → ℝ) (hp : ∑ i, p i = 1) : ∑ i, p i * (x i - ∑ j, p j * x j) * y i = (1 / 2) * ∑ i, ∑ j, p i * p j * (x i - x j) * (y i - y j) := by classical let mx := ∑ j, p j * x j let my := ∑ j, p j * y j have hzero : ∑ i, p i * (x i - mx) = 0 := by calc ∑ i, p i * (x i - mx) = (∑ i, p i * x i) - ∑ i, p i * mx := by simp [mul_sub, Finset.sum_sub_distrib] _ = mx - (∑ i, p i) * mx := by simp [Finset.sum_mul, mx] _ = 0 := by rw [hp] ring have hmy : ∑ i, p i * (x i - mx) * my = 0 := by calc ∑ i, p i * (x i - mx) * my = (∑ i, p i * (x i - mx)) * my := by rw [Finset.sum_mul] _ = 0 := by rw [hzero] ring have hcenter : ∑ i, p i * (x i - mx) * y i = ∑ i, p i * (x i - mx) * (y i - my) := by calc ∑ i, p i * (x i - mx) * y i = ∑ i, (p i * (x i - mx) * (y i - my) + p i * (x i - mx) * my) := by refine Finset.sum_congr rfl ?_ intro i _hi ring _ = ∑ i, p i * (x i - mx) * (y i - my) + ∑ i, p i * (x i - mx) * my := by rw [Finset.sum_add_distrib] _ = ∑ i, p i * (x i - mx) * (y i - my) := by rw [hmy] ring calc ∑ i, p i * (x i - ∑ j, p j * x j) * y i = ∑ i, p i * (x i - mx) * y i := by rfl _ = ∑ i, p i * (x i - mx) * (y i - my) := hcenter _ = ∑ i, p i * (x i - ∑ j, p j * x j) * (y i - ∑ j, p j * y j) := by rfl _ = (1 / 2) * ∑ i, ∑ j, p i * p j * (x i - x j) * (y i - y j) := weighted_center_cov p x y hp (by norm_num)
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.weighted_center_cov_uncentered_right · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:43
  • sum_weight_over_T_commute lemma — In a finite cohort panel, a cohort-weighted sum over cohorts and periods with equal period weight equals the average over periods of the corresponding cohort-weighted sums.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    f :
    𝒢 → Fin T → ℝ
    (∑ g, ∑ t, (P.p g / (T : ℝ)) * f g t) = (T : ℝ)⁻¹ * ∑ t, ∑ g, P.p g * f g t
    Proof (Lean source)
    lemma sum_weight_over_T_commute (P : CohortPanel 𝒢 T) (f : 𝒢 → Fin T → ℝ) : (∑ g, ∑ t, (P.p g / (T : ℝ)) * f g t) = (T : ℝ)⁻¹ * ∑ t, ∑ g, P.p g * f g t := by classical rw [Finset.sum_comm] simp [div_eq_mul_inv, Finset.mul_sum, mul_left_comm, mul_comm]
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.sum_weight_over_T_commute · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:91
  • pairwise_sum_normalize lemma — In a finite cohort panel, averaging half the ordered-pair weighted total at each period equals the ordered-pair weighted total of the time sums with the same normalization.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    f :
    𝒢 → 𝒢 → Fin T → ℝ
    (T : ℝ)⁻¹ * ∑ t, ((1 / 2) * ∑ g, ∑ u, P.p g * P.p u * f g u t)
    = ∑ g, ∑ u, (P.p g * P.p u / (2 * (T : ℝ))) * ∑ t, f g u t
    Proof (Lean source)
    lemma pairwise_sum_normalize (P : CohortPanel 𝒢 T) (f : 𝒢 → 𝒢 → Fin T → ℝ) : (T : ℝ)⁻¹ * ∑ t, ((1 / 2) * ∑ g, ∑ u, P.p g * P.p u * f g u t) = ∑ g, ∑ u, (P.p g * P.p u / (2 * (T : ℝ))) * ∑ t, f g u t := by classical calc (T : ℝ)⁻¹ * ∑ t, ((1 / 2) * ∑ g, ∑ u, P.p g * P.p u * f g u t) = (T : ℝ)⁻¹ * ∑ t, ∑ g, ∑ u, (1 / 2) * (P.p g * P.p u * f g u t) := by simp [Finset.mul_sum] _ = (T : ℝ)⁻¹ * ∑ g, ∑ u, ∑ t, (1 / 2) * (P.p g * P.p u * f g u t) := by congr 1 rw [Finset.sum_comm] refine Finset.sum_congr rfl ?_ intro g _hg rw [Finset.sum_comm] _ = ∑ g, ∑ u, (P.p g * P.p u / (2 * (T : ℝ))) * ∑ t, f g u t := by simp [div_eq_mul_inv, Finset.mul_sum, Finset.sum_mul, mul_assoc, mul_left_comm, mul_comm]
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.pairwise_sum_normalize · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:102
  • D_eq_zero_of_isInf lemma — In a cohort panel, a cohort that is never treated has a zero treatment indicator in every period.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    u :
    𝒢
    hu :
    AdoptionPath.isInfinite (P.A u)
    t :
    Fin T
    D P u t = 0
    Proof (Lean source)
    lemma D_eq_zero_of_isInf (P : CohortPanel 𝒢 T) {u : 𝒢} (hu : AdoptionPath.isInfinite (P.A u)) (t : Fin T) : D P u t = 0 := by classical unfold D rw [show P.A u = ⊤ from hu] simp
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.D_eq_zero_of_isInf · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:145
  • D_sq_eq_D lemma — In a cohort panel, the binary treatment indicator for any cohort and time period equals its own square.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    g :
    𝒢
    t :
    Fin T
    D P g t ^ 2 = D P g t
    Proof (Lean source)
    lemma D_sq_eq_D (P : CohortPanel 𝒢 T) (g : 𝒢) (t : Fin T) : D P g t ^ 2 = D P g t := by unfold D by_cases h : P.A g ≤ (t : WithTop (Fin T)) <;> simp [h]
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.D_sq_eq_D · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:156
  • binary_time_variance lemma — For a binary quantity observed over the panel's time periods, its average squared deviation from its time mean equals that mean times one minus that mean.
    T :
    ℕ
    shared
    hT_pos :
    0 < T
    x :
    Fin T → ℝ
    hx :
    ∀ t, x t ^ 2 = x t
    (T : ℝ)⁻¹ * ∑ t, (x t - ((T : ℝ)⁻¹ * ∑ t, x t)) ^ 2
    = ((T : ℝ)⁻¹ * ∑ t, x t) * (1 - ((T : ℝ)⁻¹ * ∑ t, x t))
    Proof (Lean source)
    lemma binary_time_variance (hT_pos : 0 < T) (x : Fin T → ℝ) (hx : ∀ t, x t ^ 2 = x t) : (T : ℝ)⁻¹ * ∑ t, (x t - ((T : ℝ)⁻¹ * ∑ t, x t)) ^ 2 = ((T : ℝ)⁻¹ * ∑ t, x t) * (1 - ((T : ℝ)⁻¹ * ∑ t, x t)) := by classical let m : ℝ := (T : ℝ)⁻¹ * ∑ t, x t have hTne : (T : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hT_pos) have hsum_sq : ∑ t, x t ^ 2 = ∑ t, x t := by exact Finset.sum_congr rfl (by intro t _ht; exact hx t) have hsum_expand : ∑ t, (x t ^ 2 - 2 * m * x t + m ^ 2) = ∑ t, x t - 2 * m * ∑ t, x t + (T : ℝ) * m ^ 2 := by calc ∑ t, (x t ^ 2 - 2 * m * x t + m ^ 2) = ∑ t, x t ^ 2 - ∑ t, 2 * m * x t + ∑ _t : Fin T, m ^ 2 := by simp [Finset.sum_sub_distrib, Finset.sum_add_distrib] _ = ∑ t, x t - 2 * m * ∑ t, x t + (T : ℝ) * m ^ 2 := by rw [hsum_sq] simp [Finset.mul_sum, Fintype.card_fin] calc (T : ℝ)⁻¹ * ∑ t, (x t - ((T : ℝ)⁻¹ * ∑ t, x t)) ^ 2 = (T : ℝ)⁻¹ * ∑ t, (x t ^ 2 - 2 * m * x t + m ^ 2) := by congr 1 refine Finset.sum_congr rfl ?_ intro t _ht simp [m] ring _ = ((T : ℝ)⁻¹ * ∑ t, x t) * (1 - ((T : ℝ)⁻¹ * ∑ t, x t)) := by rw [hsum_expand] simp [m] field_simp [hTne] ring
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.binary_time_variance · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:164
  • binary_time_cov_filter_mean lemma — For an indicator of a nonempty set of periods, the time-average product of its centered value and another quantity equals its variance times the difference between the selected-period and unselected-period averages of that quantity.
    T :
    ℕ
    shared
    hT_pos :
    0 < T
    p :
    Fin T → Prop
    z :
    Fin T → ℝ
    hcard1 :
    ((Finset.univ.filter p).card : ℝ) ≠ 0
    (T : ℝ)⁻¹ * ∑ t, ((if p t then (1 : ℝ) else 0) - ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0))) * z t
    = ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0)) * (1 - ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0))) * (((Finset.univ.filter p).card : ℝ)⁻¹ * (∑ t ∈ (Finset.univ.filter p), z t) - ((Finset.univ.filter (fun t => ¬ p t)).card : ℝ)⁻¹ * (∑ t ∈ (Finset.univ.filter (fun t => ¬ p t)), z t))
    Proof (Lean source)
    lemma binary_time_cov_filter_mean (hT_pos : 0 < T) (p : Fin T → Prop) [DecidablePred p] (z : Fin T → ℝ) (hcard1 : ((Finset.univ.filter p).card : ℝ) ≠ 0) : (T : ℝ)⁻¹ * ∑ t, ((if p t then (1 : ℝ) else 0) - ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0))) * z t = ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0)) * (1 - ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0))) * (((Finset.univ.filter p).card : ℝ)⁻¹ * (∑ t ∈ (Finset.univ.filter p), z t) - ((Finset.univ.filter (fun t => ¬ p t)).card : ℝ)⁻¹ * (∑ t ∈ (Finset.univ.filter (fun t => ¬ p t)), z t)) := by classical have hTne : (T : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hT_pos) let A : ℝ := ((Finset.univ.filter p).card : ℝ) let B : ℝ := ((Finset.univ.filter (fun t => ¬ p t)).card : ℝ) let Z1 : ℝ := ∑ t ∈ (Finset.univ.filter p), z t let Z0 : ℝ := ∑ t ∈ (Finset.univ.filter (fun t => ¬ p t)), z t have hA : A ≠ 0 := by simpa [A] using hcard1 have hsum_if : (∑ t, (if p t then (1 : ℝ) else 0)) = A := by simp [A] have hsum_if_z : (∑ t, (if p t then (1 : ℝ) else 0) * z t) = Z1 := by simp [Z1, Finset.sum_filter] have hsum_z : (∑ t, z t) = Z1 + Z0 := by simp [Z1, Z0, Finset.sum_filter] rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl ?_ intro t _ by_cases ht : p t <;> simp [ht] have hcard_total : A + B = (T : ℝ) := by have hnat : (Finset.univ.filter p).card + (Finset.univ.filter (fun t => ¬ p t)).card = T := by calc (Finset.univ.filter p).card + (Finset.univ.filter (fun t => ¬ p t)).card = ((Finset.univ.filter p) ∪ (Finset.univ.filter (fun t => ¬ p t))).card := by rw [Finset.card_union_of_disjoint] simp [Finset.disjoint_left] _ = T := by have hunion : (Finset.univ.filter p) ∪ (Finset.univ.filter (fun t => ¬ p t)) = (Finset.univ : Finset (Fin T)) := by ext t simp [em] simp [hunion] simpa [A, B] using (show (((Finset.univ.filter p).card : ℝ) + ((Finset.univ.filter (fun t => ¬ p t)).card : ℝ) = (T : ℝ)) by exact_mod_cast hnat) have hmain : (T : ℝ)⁻¹ * (Z1 - ((T : ℝ)⁻¹ * A) * (Z1 + Z0)) = ((T : ℝ)⁻¹ * A) * (1 - ((T : ℝ)⁻¹ * A)) * (A⁻¹ * Z1 - B⁻¹ * Z0) := by by_cases hB : B = 0 · have hZT0 : Z0 = 0 := by have hempty : Finset.univ.filter (fun t => ¬ p t) = ∅ := by apply Finset.card_eq_zero.mp have hB' : ((Finset.univ.filter (fun t => ¬ p t)).card : ℝ) = 0 := by simpa [B] using hB exact_mod_cast hB' simp [Z0, hempty] have hAeq : A = (T : ℝ) := by linarith rw [hZT0, hAeq] field_simp [hTne] ring · have hABne : A + B ≠ 0 := by rw [hcard_total] exact hTne rw [← hcard_total] field_simp [hA, hB, hABne] ring calc (T : ℝ)⁻¹ * ∑ t, ((if p t then (1 : ℝ) else 0) - ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0))) * z t = (T : ℝ)⁻¹ * (Z1 - ((T : ℝ)⁻¹ * A) * (Z1 + Z0)) := by rw [hsum_if] calc (T : ℝ)⁻¹ * ∑ t, ((if p t then (1 : ℝ) else 0) - (T : ℝ)⁻¹ * A) * z t = (T : ℝ)⁻¹ * (∑ t, (if p t then (1 : ℝ) else 0) * z t - ∑ t, ((T : ℝ)⁻¹ * A) * z t) := by congr 1 rw [← Finset.sum_sub_distrib] refine Finset.sum_congr rfl ?_ intro t _ ring _ = (T : ℝ)⁻¹ * (Z1 - ((T : ℝ)⁻¹ * A) * (Z1 + Z0)) := by rw [hsum_if_z, ← Finset.mul_sum, hsum_z] _ = ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0)) * (1 - ((T : ℝ)⁻¹ * ∑ t, (if p t then (1 : ℝ) else 0))) * (((Finset.univ.filter p).card : ℝ)⁻¹ * (∑ t ∈ (Finset.univ.filter p), z t) - ((Finset.univ.filter (fun t => ¬ p t)).card : ℝ)⁻¹ * (∑ t ∈ (Finset.univ.filter (fun t => ¬ p t)), z t)) := by rw [hmain, hsum_if]
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.binary_time_cov_filter_mean · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:202
  • TN_treated_window_card_ne_zero lemma — Given a finite-cohort panel and a cohort, if the cohort has a finite adoption date, then the real-valued cardinality of its treated-period window is nonzero.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    g :
    𝒢
    hg :
    AdoptionPath.isFinite (P.A g)
    ((Finset.univ.filter (fun t => AdoptionPath.le (P.A g) t)).card : ℝ) ≠ 0
    Proof (Lean source)
    lemma TN_treated_window_card_ne_zero (P : CohortPanel 𝒢 T) {g : 𝒢} (hg : AdoptionPath.isFinite (P.A g)) : ((Finset.univ.filter (fun t => AdoptionPath.le (P.A g) t)).card : ℝ) ≠ 0 := by cases hA : P.A g with | top => exact False.elim (hg hA) | coe a => have hmem : a ∈ Finset.univ.filter (fun t => AdoptionPath.le (P.A g) t) := by simp [AdoptionPath.le, hA] have hpos : 0 < (Finset.univ.filter (fun t => AdoptionPath.le (P.A g) t)).card := Finset.card_pos.mpr ⟨a, hmem⟩ have hne : ((Finset.univ.filter (fun t => AdoptionPath.le (P.A g) t)).card : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hpos) simpa [hA] using hne
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.TN_treated_window_card_ne_zero · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:307
  • TT_middle_window_card_ne_zero lemma — Given a finite-cohort panel and two cohorts, if the first adopts before the second, then the real-valued cardinality of the periods between their adoption dates is nonzero. This includes the case where the second cohort never adopts.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    e ℓ :
    𝒢
    hord :
    P.A e < P.A ℓ
    ((Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t)).card : ℝ)
    ≠ 0
    Proof (Lean source)
    lemma TT_middle_window_card_ne_zero (P : CohortPanel 𝒢 T) {e ℓ : 𝒢} (hord : P.A e < P.A ℓ) : ((Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t)).card : ℝ) ≠ 0 := by cases he : P.A e with | top => have hbad := hord simp [he] at hbad | coe a => cases hℓA : P.A ℓ with | top => have hmem : a ∈ Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t) := by simp [AdoptionPath.le, AdoptionPath.lt, he, hℓA] have hpos : 0 < (Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t)).card := Finset.card_pos.mpr ⟨a, hmem⟩ have hne : ((Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t)).card : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hpos) simpa [he, hℓA] using hne | coe b => have hab : (a : WithTop (Fin T)) < (b : WithTop (Fin T)) := by simpa [he, hℓA] using hord have habFin : a < b := by exact (WithTop.coe_lt_coe (a := b) (b := a)).mp hab have hmem : a ∈ Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t) := by simp [AdoptionPath.le, AdoptionPath.lt, he, hℓA, habFin] have hpos : 0 < (Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t)).card := Finset.card_pos.mpr ⟨a, hmem⟩ have hne : ((Finset.univ.filter (fun t => AdoptionPath.le (P.A e) t ∧ AdoptionPath.lt (P.A ℓ) t)).card : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hpos) simpa [he, hℓA] using hne
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.TT_middle_window_card_ne_zero · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:328
  • Dtilde_eq_centeredD_sub_weighted_mean lemma — The explicit double-demeaning formula for Dtilde is the weighted centering, across cohorts, of the cohort-demeaned treatment path.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    g :
    𝒢
    t :
    Fin T
    Dtilde P g t = centeredD P g t - ∑ h, P.p h * centeredD P h t
    Proof (Lean source)
    lemma Dtilde_eq_centeredD_sub_weighted_mean (P : CohortPanel 𝒢 T) (g : 𝒢) (t : Fin T) : Dtilde P g t = centeredD P g t - ∑ h, P.p h * centeredD P h t := by rw [weighted_centeredD_mean P t] rw [Dtilde_eq] unfold centeredD ring
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.Dtilde_eq_centeredD_sub_weighted_mean · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:386
  • twfe_numerator_eq_pairwise_centeredD_Y lemma — Pairwise representation of the TWFE numerator.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    (∑ g, ∑ t, (P.p g / (T : ℝ)) * Dtilde P g t * P.Y g t)
    = ∑ g, ∑ u, numPairContribution P g u
    Proof (Lean source)
    lemma twfe_numerator_eq_pairwise_centeredD_Y (P : CohortPanel 𝒢 T) : (∑ g, ∑ t, (P.p g / (T : ℝ)) * Dtilde P g t * P.Y g t) = ∑ g, ∑ u, numPairContribution P g u := by classical calc (∑ g, ∑ t, (P.p g / (T : ℝ)) * Dtilde P g t * P.Y g t) = ∑ g, ∑ t, (P.p g / (T : ℝ)) * (Dtilde P g t * P.Y g t) := by refine Finset.sum_congr rfl ?_ intro g _hg refine Finset.sum_congr rfl ?_ intro t _ht ring _ = (T : ℝ)⁻¹ * ∑ t, ∑ g, P.p g * (Dtilde P g t * P.Y g t) := by exact sum_weight_over_T_commute P (fun g t => Dtilde P g t * P.Y g t) _ = (T : ℝ)⁻¹ * ∑ t, ∑ g, P.p g * (centeredD P g t - ∑ h, P.p h * centeredD P h t) * P.Y g t := by congr 1 refine Finset.sum_congr rfl ?_ intro t _ht refine Finset.sum_congr rfl ?_ intro g _hg rw [Dtilde_eq_centeredD_sub_weighted_mean] ring _ = (T : ℝ)⁻¹ * ∑ t, ((1 / 2) * ∑ g, ∑ u, P.p g * P.p u * (centeredD P g t - centeredD P u t) * (P.Y g t - P.Y u t)) := by congr 1 refine Finset.sum_congr rfl ?_ intro t _ht exact weighted_center_cov_uncentered_right (fun g => P.p g) (fun g => centeredD P g t) (fun g => P.Y g t) P.p_sum_one _ = ∑ g, ∑ u, numPairContribution P g u := by unfold numPairContribution simpa [mul_assoc] using pairwise_sum_normalize P (fun g u t => (centeredD P g t - centeredD P u t) * (P.Y g t - P.Y u t))
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.twfe_numerator_eq_pairwise_centeredD_Y · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/Algebra.lean:431
Goodman­Bacon 1 core · 4 supporting This part proves the treated-never-treated and treated-treated pairwise denominator and numerator contribution formulas used by the staggered-TWFE decomposition. ★ TN_pair_contribution_eq_lambda_delta

Goodman-Bacon Pairwise Contribution Formulas

This part proves the treated-never-treated and treated-treated pairwise denominator and numerator contribution formulas used by the staggered-TWFE decomposition.

lemma TN_pair_contribution_eq_lambda_delta reviewed
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition

TN numerator pair. For a treated cohort g with finite adoption date and a never-treated cohort u with infinite adoption date, the sum of the two ordered pairwise-covariance contributions between g and u in the finite cohort panel P equals the product of the TN comparison weight and the treated-versus-never contrast, λ_TN P g u · Δ_TN P g u.

Formal statement
𝒢 :
Type u_1
shared
T :
ℕ
shared
P :
g u :
𝒢
hg :
AdoptionPath.isFinite (P.A g)
hu :
AdoptionPath.isInfinite (P.A u)
Proof (Lean source)
lemma TN_pair_contribution_eq_lambda_delta (P : CohortPanel 𝒢 T) {g u : 𝒢} (hg : AdoptionPath.isFinite (P.A g)) (hu : AdoptionPath.isInfinite (P.A u)) : numPairContribution P g u + numPairContribution P u g = lambdaTN P g u * Δ_TN P g u := by rw [numPairContribution_add_swap] have hTne : (T : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt P.T_pos) have hcov := TN_time_cov_eq_lambda_delta_core P hg hu calc (P.p g * P.p u / (T : ℝ)) * ∑ t, (centeredD P g t - centeredD P u t) * (P.Y g t - P.Y u t) = P.p g * P.p u * ((T : ℝ)⁻¹ * ∑ t, (centeredD P g t - centeredD P u t) * (P.Y g t - P.Y u t)) := by field_simp [hTne] _ = lambdaTN P g u * Δ_TN P g u := by rw [hcov] unfold lambdaTN ring
Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.TN_pair_contribution_eq_lambda_delta · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/GoodmanBacon.lean:595 · uses isFinite , isInfinite , CohortPanel , lambdaTN , numPairContribution , Δ_TN
4 supporting declarations (lemmas, instances)
  • disjoint_union_mean_eq_card_weighted_mean lemma — When two finite sets are disjoint and the second is nonempty, the mean of a quantity over their union is the cardinality-weighted combination of its means over the two sets.
    α :
    Type*
    A B :
    z :
    α → ℝ
    hdisj :
    hB :
    ((B.card : ℝ) ≠ 0)
    (((A ∪ B).card : ℝ)⁻¹ * ∑ t ∈ A ∪ B, z t)
    = ((A.card : ℝ) / ((A ∪ B).card : ℝ)) * ((A.card : ℝ)⁻¹ * ∑ t ∈ A, z t)
    + (1 - ((A.card : ℝ) / ((A ∪ B).card : ℝ))) * ((B.card : ℝ)⁻¹ * ∑ t ∈ B, z t)
    Proof (Lean source)
    lemma disjoint_union_mean_eq_card_weighted_mean {α : Type*} [DecidableEq α] (A B : Finset α) (z : α → ℝ) (hdisj : Disjoint A B) (hB : ((B.card : ℝ) ≠ 0)) : (((A ∪ B).card : ℝ)⁻¹ * ∑ t ∈ A ∪ B, z t) = ((A.card : ℝ) / ((A ∪ B).card : ℝ)) * ((A.card : ℝ)⁻¹ * ∑ t ∈ A, z t) + (1 - ((A.card : ℝ) / ((A ∪ B).card : ℝ))) * ((B.card : ℝ)⁻¹ * ∑ t ∈ B, z t) := by classical let a : ℝ := A.card let b : ℝ := B.card let ZA : ℝ := ∑ t ∈ A, z t let ZB : ℝ := ∑ t ∈ B, z t have hsum : ∑ t ∈ A ∪ B, z t = ZA + ZB := by simp [ZA, ZB, Finset.sum_union hdisj] have hcard : ((A ∪ B).card : ℝ) = a + b := by have hnat : (A ∪ B).card = A.card + B.card := Finset.card_union_of_disjoint hdisj simp [a, b, hnat] have hb : b ≠ 0 := by simpa [b] using hB have hbpos : 0 < b := by have hBnat : B.card ≠ 0 := by exact_mod_cast hB dsimp [b] exact_mod_cast (Nat.pos_of_ne_zero hBnat) have hab : a + b ≠ 0 := by intro h have ha_nonneg : 0 ≤ a := by dsimp [a] exact_mod_cast (zero_le A.card) linarith by_cases ha : a = 0 · have hAempty : A = ∅ := by apply Finset.card_eq_zero.mp have : (A.card : ℝ) = 0 := by simpa [a] using ha exact Nat.cast_eq_zero.mp this have hZA : ZA = 0 := by simp [ZA, hAempty] rw [hsum, hcard, hZA, ha] simp [hAempty] field_simp [hb] ring · have haA : ((A.card : ℝ) ≠ 0) := by simpa [a] using ha have hAB : ((A.card : ℝ) + (B.card : ℝ)) ≠ 0 := by simpa [a, b] using hab rw [hsum, hcard] field_simp [haA, hB, hAB] simp [a, b, ZA, ZB] ring_nf
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.disjoint_union_mean_eq_card_weighted_mean · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/GoodmanBacon.lean:185
  • TN_pair_vd_contribution_eq_gap lemma — TN denominator pair: combining the two ordered pairwise-variance contributions gives the treated-vs-never raw denominator factor.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    g u :
    𝒢
    hu :
    AdoptionPath.isInfinite (P.A u)
    = P.p g * P.p u * q P g u * (1 - q P g u)
    Proof (Lean source)
    lemma TN_pair_vd_contribution_eq_gap (P : CohortPanel 𝒢 T) {g u : 𝒢} (hu : AdoptionPath.isInfinite (P.A u)) : vdPairContribution P g u + vdPairContribution P u g = P.p g * P.p u * q P g u * (1 - q P g u) := by rw [vdPairContribution_add_swap] have hTne : (T : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt P.T_pos) have hvar := TN_time_variance_eq_gap P (g := g) hu calc (P.p g * P.p u / (T : ℝ)) * ∑ t, (centeredD P g t - centeredD P u t)^2 = P.p g * P.p u * ((T : ℝ)⁻¹ * ∑ t, (centeredD P g t - centeredD P u t)^2) := by field_simp [hTne] _ = P.p g * P.p u * q P g u * (1 - q P g u) := by rw [hvar] ring
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.TN_pair_vd_contribution_eq_gap · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/GoodmanBacon.lean:553
  • TT_pair_vd_contribution_eq_gap lemma — Treated-treated denominator pair: combining the two ordered pairwise-variance contributions gives the timing-pair raw denominator factor.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    e ℓ :
    𝒢
    hord :
    P.A e < P.A ℓ
    = P.p e * P.p ℓ * q P e ℓ * (1 - q P e ℓ)
    Proof (Lean source)
    lemma TT_pair_vd_contribution_eq_gap (P : CohortPanel 𝒢 T) {e ℓ : 𝒢} (hord : P.A e < P.A ℓ) : vdPairContribution P e ℓ + vdPairContribution P ℓ e = P.p e * P.p ℓ * q P e ℓ * (1 - q P e ℓ) := by rw [vdPairContribution_add_swap] have hTne : (T : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt P.T_pos) have hvar := TT_time_variance_eq_gap P hord calc (P.p e * P.p ℓ / (T : ℝ)) * ∑ t, (centeredD P e t - centeredD P ℓ t)^2 = P.p e * P.p ℓ * ((T : ℝ)⁻¹ * ∑ t, (centeredD P e t - centeredD P ℓ t)^2) := by field_simp [hTne] _ = P.p e * P.p ℓ * q P e ℓ * (1 - q P e ℓ) := by rw [hvar] ring
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.TT_pair_vd_contribution_eq_gap · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/GoodmanBacon.lean:574
  • TT_pair_contribution_eq_lambda_delta_sum lemma — Treated-treated numerator pair: combining the two ordered pairwise-covariance contributions splits into the EL and LE comparison windows.
    𝒢 :
    Type u_1
    shared
    T :
    ℕ
    shared
    P :
    e ℓ :
    𝒢
    hord :
    P.A e < P.A ℓ
    hℓ :
    AdoptionPath.isFinite (P.A ℓ)
    = lambdaEL P e ℓ * Δ_EL P e ℓ + lambdaLE P e ℓ * Δ_LE P e ℓ
    Proof (Lean source)
    lemma TT_pair_contribution_eq_lambda_delta_sum (P : CohortPanel 𝒢 T) {e ℓ : 𝒢} (hord : P.A e < P.A ℓ) (hℓ : AdoptionPath.isFinite (P.A ℓ)) : numPairContribution P e ℓ + numPairContribution P ℓ e = lambdaEL P e ℓ * Δ_EL P e ℓ + lambdaLE P e ℓ * Δ_LE P e ℓ := by rw [numPairContribution_add_swap] have hTne : (T : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt P.T_pos) have hcov := TT_time_cov_eq_lambda_delta_core P hord hℓ calc (P.p e * P.p ℓ / (T : ℝ)) * ∑ t, (centeredD P e t - centeredD P ℓ t) * (P.Y e t - P.Y ℓ t) = P.p e * P.p ℓ * ((T : ℝ)⁻¹ * ∑ t, (centeredD P e t - centeredD P ℓ t) * (P.Y e t - P.Y ℓ t)) := by field_simp [hTne] _ = lambdaEL P e ℓ * Δ_EL P e ℓ + lambdaLE P e ℓ * Δ_LE P e ℓ := by rw [hcov] unfold lambdaEL lambdaLE ring
    Causalean.Panel.EstimandCharacterization.StaggeredTWFEDecomposition.TT_pair_contribution_eq_lambda_delta_sum · Causalean/Panel/EstimandCharacterization/StaggeredTWFEDecomposition/Pairwise/GoodmanBacon.lean:621