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 (Delta^SD) - “relative_magnitude”: Post violations <= M * max pre violation (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 violation 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()
__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)

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)

get_params()[source]

Get parameters for this estimator.

Return type:

Dict[str, Any]

set_params(**params)[source]

Set parameters for this estimator.

Return type:

HonestDiD

fit(results, M=None)[source]

Compute bounds and robust confidence intervals.

Parameters:
Returns:

Results containing bounds and robust confidence intervals.

Return type:

HonestDiDResults

sensitivity_analysis(results, M_grid=None)[source]

Perform sensitivity analysis over a grid of M values.

Parameters:
Returns:

Results containing bounds and CIs for each M value.

Return type:

SensitivityResults

breakdown_value(results, tol=0.01)[source]

Find the breakdown value directly using binary search.

The breakdown value is the smallest M where the robust confidence interval includes zero.

Parameters:
Returns:

Breakdown value, or None if effect is always significant.

Return type:

float or None