diff_diff.BaconDecompositionResults#
- class diff_diff.BaconDecompositionResults[source]#
Bases:
objectResults from Goodman-Bacon decomposition of TWFE.
This decomposition shows that the TWFE estimate equals a weighted average of all possible 2x2 DiD comparisons between timing groups.
- twfe_estimate#
The overall TWFE coefficient (should equal weighted sum of 2x2 estimates).
- Type:
- comparisons#
List of all 2x2 comparisons with their estimates and weights.
- Type:
List[Comparison2x2]
- total_weight_later_vs_earlier#
Total weight on later vs earlier treated comparisons (forbidden).
- Type:
- weighted_avg_treated_vs_never#
Weighted average effect from treated vs never-treated comparisons.
- Type:
- weighted_avg_earlier_vs_later#
Weighted average effect from earlier vs later comparisons.
- Type:
- weighted_avg_later_vs_earlier#
Weighted average effect from later vs earlier comparisons.
- Type:
- n_always_treated_remapped#
Number of units whose
first_treatwas at or before the first observable period (first_treat <= min(time), excluding the never-treated sentinels0andnp.inf) and which were automatically remapped to theU(untreated) bucket per Goodman-Bacon (2021) footnote 11. Detection uses ordered-time logic so negative or zero-crossing period labels work correctly. Zero on inputs where the user only used thefirst_treat ∈ {0, np.inf}sentinels. The user’s originalfirst_treatcolumn is preserved unchanged on the inputdataframe; remapping happens in an internal column.- Type:
- timing_groups#
List of treatment timing cohorts.
- Type:
List[Any]
Methods
__init__(twfe_estimate, comparisons, ...[, ...])effect_by_type()Get weighted average effect by comparison type.
print_summary()Print the summary to stdout.
summary()Generate a formatted summary of the decomposition.
to_dataframe()Convert comparisons to a DataFrame.
weight_by_type()Get total weight by comparison type.
Attributes
decomposition_errorn_obssurvey_metadata- __init__(twfe_estimate, comparisons, total_weight_treated_vs_never, total_weight_earlier_vs_later, total_weight_later_vs_earlier, weighted_avg_treated_vs_never, weighted_avg_earlier_vs_later, weighted_avg_later_vs_earlier, n_timing_groups, n_never_treated, timing_groups, n_obs=0, decomposition_error=0.0, n_always_treated_remapped=0, survey_metadata=None)#
- Parameters:
twfe_estimate (float)
comparisons (List[Comparison2x2])
total_weight_treated_vs_never (float)
total_weight_earlier_vs_later (float)
total_weight_later_vs_earlier (float)
weighted_avg_treated_vs_never (float | None)
weighted_avg_earlier_vs_later (float | None)
weighted_avg_later_vs_earlier (float | None)
n_timing_groups (int)
n_never_treated (int)
n_obs (int)
decomposition_error (float)
n_always_treated_remapped (int)
survey_metadata (Any | None)
- Return type:
None
- classmethod __new__(*args, **kwargs)#