diff_diff.ContinuousDiD#

class diff_diff.ContinuousDiD[source]#

Bases: object

Continuous Difference-in-Differences estimator.

Implements the methodology from Callaway, Goodman-Bacon & Sant’Anna (2024) for estimating dose-response curves when treatment has a continuous intensity.

Parameters:
  • degree (int, default=3) – B-spline degree (3 = cubic).

  • num_knots (int, default=0) – Number of interior knots for the B-spline basis.

  • dvals (array-like, optional) – Custom dose evaluation grid. If None, uses quantile-based default.

  • control_group (str, default="never_treated") – "never_treated" or "not_yet_treated".

  • anticipation (int, default=0) – Number of periods of treatment anticipation.

  • base_period (str, default="varying") – "varying" or "universal".

  • alpha (float, default=0.05) – Significance level for confidence intervals.

  • n_bootstrap (int, default=0) – Number of multiplier bootstrap iterations. 0 for analytical SEs only.

  • bootstrap_weights (str, default="rademacher") – Bootstrap weight type: "rademacher", "mammen", or "webb".

  • seed (int, optional) – Random seed for reproducibility.

  • rank_deficient_action (str, default="warn") – Action for rank-deficient B-spline OLS: "warn", "error", or "silent".

Examples

>>> from diff_diff import ContinuousDiD, generate_continuous_did_data
>>> data = generate_continuous_did_data(n_units=200, seed=42)
>>> est = ContinuousDiD(n_bootstrap=199, seed=42)
>>> results = est.fit(data, outcome="outcome", unit="unit",
...                   time="period", first_treat="first_treat",
...                   dose="dose", aggregate="dose")
>>> results.overall_att

Methods

__init__([degree, num_knots, dvals, ...])

fit(data, outcome, unit, time, first_treat, dose)

Fit the continuous DiD estimator.

get_params()

Return estimator parameters as a dictionary.

set_params(**params)

Set estimator parameters and return self.

__init__(degree=3, num_knots=0, dvals=None, control_group='never_treated', anticipation=0, base_period='varying', alpha=0.05, n_bootstrap=0, bootstrap_weights='rademacher', seed=None, rank_deficient_action='warn')[source]#
Parameters:
  • degree (int)

  • num_knots (int)

  • dvals (ndarray | None)

  • control_group (str)

  • anticipation (int)

  • base_period (str)

  • alpha (float)

  • n_bootstrap (int)

  • bootstrap_weights (str)

  • seed (int | None)

  • rank_deficient_action (str)

classmethod __new__(*args, **kwargs)#