diff_diff.HonestDiD#

class diff_diff.HonestDiD[source]#

Bases: object

Honest DiD sensitivity analysis (Rambachan & Roth 2023).

Computes robust inference for difference-in-differences allowing for bounded violations of parallel trends.

Parameters:
  • method ({"smoothness", "relative_magnitude", "combined"}) – Type of restriction on trend violations: - “smoothness”: Bounds on second differences of trend violations (Delta^SD) - “relative_magnitude”: Post first differences <= M * max pre first difference (Delta^RM) - “combined”: Both restrictions (Delta^SDRM)

  • M (float, optional) – Restriction parameter. Interpretation depends on method: - smoothness: Max second difference - relative_magnitude: Scaling factor for max pre-period first difference Default is 1.0 for relative_magnitude, 0.0 for smoothness.

  • alpha (float) – Significance level for confidence intervals.

  • l_vec (array-like or None) – Weighting vector for scalar parameter (length = num_post_periods). If None, uses uniform weights (average effect).

Examples

>>> from diff_diff import MultiPeriodDiD
>>> from diff_diff.honest_did import HonestDiD
>>>
>>> # Fit event study
>>> mp_did = MultiPeriodDiD()
>>> results = mp_did.fit(data, outcome='y', treatment='treated',
...                      time='period', post_periods=[4,5,6,7])
>>>
>>> # Sensitivity analysis with relative magnitudes
>>> honest = HonestDiD(method='relative_magnitude', M=1.0)
>>> bounds = honest.fit(results)
>>> print(bounds.summary())
>>>
>>> # Sensitivity curve over M values
>>> sensitivity = honest.sensitivity_analysis(results, M_grid=[0, 0.5, 1, 1.5, 2])
>>> sensitivity.plot()

Methods

__init__([method, M, alpha, l_vec])

breakdown_value(results[, tol])

Find the breakdown value directly using binary search.

fit(results[, M])

Compute bounds and robust confidence intervals.

get_params()

Get parameters for this estimator.

sensitivity_analysis(results[, M_grid])

Perform sensitivity analysis over a grid of M values.

set_params(**params)

Set parameters for this estimator.

__init__(method='relative_magnitude', M=None, alpha=0.05, l_vec=None)[source]#
Parameters:
  • method (Literal['smoothness', 'relative_magnitude', 'combined'])

  • M (float | None)

  • alpha (float)

  • l_vec (ndarray | None)

classmethod __new__(*args, **kwargs)#