Skip to content
Submodule
causalis.scenarios.did.model

model

Submodule causalis.scenarios.did.model with no child pages and 12 documented members.

Classes

Jump directly into the documented classes for this page.

1 items

Data

Jump directly into the documented data for this page.

4 items
data
causalis.scenarios.did.model.Estimator

Estimator

Value: None

None

Canonical target

causalis.scenarios.did.model.Estimator

Link to this symbol
data
causalis.scenarios.did.model.AggregateKind

AggregateKind

Value: None

None

Canonical target

causalis.scenarios.did.model.AggregateKind

Link to this symbol
data
causalis.scenarios.did.model.BasePeriod

BasePeriod

Value: None

None

Canonical target

causalis.scenarios.did.model.BasePeriod

Link to this symbol
class
causalis.scenarios.did.model.CallawaySantAnnaDID

CallawaySantAnnaDID

Callaway-Sant’Anna staggered-adoption DID estimator.

The model estimates group-time average treatment effects ATT(g,t)ATT(g,t) for cohorts (groups) first treated in period gg and calendar times tt. Estimation is performed using the doubly robust or inverse-probability weighting methods proposed by Callaway and Sant’Anna (2021).

Parameters

estimator{“dr”, “ipw”}, default “dr”

The estimator to use for ATT(g,t)ATT(g,t) cells. - “dr”: Doubly robust AIPW-style estimator. - “ipw”: Inverse probability weighting estimator.

control_group{“not_yet_or_never”, “never_treated”}, default “not_yet_or_never”

Which units to use as the comparison group. - “not_yet_or_never”: Includes units not yet treated by time tt and never-treated units. - “never_treated”: Includes only never-treated units.

anticipationint, default 0

Number of periods before actual treatment start where units are considered treated (e.g., due to announcement effects).

base_period{“universal”, “varying”}, default “universal”

Definition of the ‘before’ period in the DID comparison. - “universal”: Uses g1anticipationg - 1 - \text{anticipation} as the base for all tt. - “varying”: Uses t1t - 1 as the base for all tt.

include_pre_periodsbool, default False

Whether to estimate ATT(g,t)ATT(g,t) for t<gt < g (pre-treatment testing).

alphafloat, default 0.05

Significance level for confidence intervals.

diagnostic_databool, default True

Whether to store diagnostic information (overlap, balance, etc.).

propensity_clipfloat, default 1e-4

Clipping threshold for propensity scores to avoid division by zero.

logit_ridgefloat, default 1e-4

L2 regularization strength for the logistic propensity score model.

optimizer_tolfloat, default 1e-8

Tolerance for the propensity score optimizer.

optimizer_maxiterint, default 1000

Maximum iterations for the propensity score optimizer.

min_treated_per_cellint, default 30

Minimum number of treated units required in a (g,t)(g,t) cell.

min_control_per_cellint, default 30

Minimum number of control units required in a (g,t)(g,t) cell.

min_control_essfloat, default 20.0

Minimum effective sample size for control units in a (g,t)(g,t) cell.

max_propensity_clip_sharefloat, default 0.05

Maximum fraction of units that can be clipped before skipping a cell.

max_condition_numberfloat, default 1e5

Maximum condition number for covariate matrices.

bootstrap_replicationsint, default 0

Number of multiplier bootstrap replications for simultaneous confidence bands. If 0, uses asymptotic normal approximation for pointwise intervals.

random_stateint, optional, default None

Random seed for bootstrap multipliers.

Examples

Generate synthetic staggered-adoption panel data

Notes

In a staggered adoption design, units ii are treated at different times Gi{g1,,gK,}G_i \in \{g_1, \dots, g_K, \infty\}. The group-time average treatment effect is defined as:

ATT(g,t)=E[Yt(g)Yt()G=g]ATT(g,t) = \mathbb{E}[Y_t(g) - Y_t(\infty) \mid G=g]

where Yt(g)Y_t(g) is the potential outcome at time tt if treated at time gg, and Yt()Y_t(\infty) is the potential outcome if never treated.

This implementation follows Callaway and Sant’Anna (2021) and uses logistic regression for propensity scores and linear regression for outcome models (in “dr” mode). The doubly robust estimator for ATT(g,t)ATT(g,t) is:

θDR(g,t)=E[(GgE[Gg]pg(X)C1pg(X)E[pg(X)C1pg(X)])(YtYbasemg,t(X))]\theta_{DR}(g,t) = \mathbb{E} \left[ \left( \frac{G_g}{\mathbb{E}[G_g]} - \frac{\frac{p_g(X) C}{1-p_g(X)}}{\mathbb{E}[\frac{p_g(X) C}{1-p_g(X)}]} \right) (Y_t - Y_{base} - m_{g,t}(X)) \right]

where Gg=1{G=g}G_g = \mathbb{1}\{G=g\}, CC is the control group indicator, pg(X)p_g(X) is the propensity score, and mg,t(X)m_{g,t}(X) is the outcome regression.

Simultaneous confidence bands are computed using the multiplier bootstrap on the influence functions of the ATT(g,t)ATT(g,t) estimates.

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID

Sections

ParametersNotesExamples
Link to this symbol
method
causalis.scenarios.did.model.CallawaySantAnnaDID.fit

fit

Fit all supported ATT(g,t)ATT(g,t) cells on a validated :class:PanelDataDID.

This method prepares the panel data, identifies valid comparison groups for each cohort-time cell, and estimates the group-time average treatment effects.

Parameters

dataPanelDataDID

The validated panel data container.

Returns

CallawaySantAnnaDID

The fitted model instance.

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID.fit

Sections

ParametersReturns
Link to this symbol
method
causalis.scenarios.did.model.CallawaySantAnnaDID.estimate

estimate

Aggregate group-time effects and perform inference.

This method computes simple, cohort, calendar, and event-study aggregations from the fitted ATT(g,t)ATT(g,t) cells. It also performs inference using either asymptotic normal approximation or the multiplier bootstrap.

Parameters

alphafloat, optional

Significance level. If None, uses the value from __init__.

diagnostic_databool, optional

Whether to include diagnostic data in the result. If None, uses the value from __init__.

bootstrap_replicationsint, optional

Number of multiplier bootstrap replications. If None, uses the value from __init__.

random_stateint, optional

Random seed for bootstrap. If None, uses the value from __init__.

Returns

CallawaySantAnnaDIDEstimate

The estimation results including aggregations and inference.

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID.estimate

Sections

ParametersReturns
Link to this symbol
property
causalis.scenarios.did.model.CallawaySantAnnaDID.is_fitted

is_fitted

Whether the model has been fitted on data.

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID.is_fitted

Link to this symbol
property
causalis.scenarios.did.model.CallawaySantAnnaDID.support_

support_

A table of units and their inclusion status in various ATT(g,t)ATT(g,t) cells.

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID.support_

Link to this symbol
property
causalis.scenarios.did.model.CallawaySantAnnaDID.skipped_cells_

skipped_cells_

A table of cohort-time cells that were skipped due to insufficient data or quality issues.

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID.skipped_cells_

Link to this symbol
property
causalis.scenarios.did.model.CallawaySantAnnaDID.cell_diagnostics_

cell_diagnostics_

Detailed diagnostic information for each ATT(g,t)ATT(g,t) cell.

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID.cell_diagnostics_

Link to this symbol
method
causalis.scenarios.did.model.CallawaySantAnnaDID.__repr__

__repr__

Canonical target

causalis.scenarios.did.model.CallawaySantAnnaDID.__repr__

Link to this symbol
data
causalis.scenarios.did.model.__all__

__all__

Value: ['AggregateKind', 'BasePeriod', 'CallawaySantAnnaDID', 'CallawaySantAnnaDIDEstimate', 'Estimator']

[‘AggregateKind’, ‘BasePeriod’, ‘CallawaySantAnnaDID’, ‘CallawaySantAnnaDIDEstimate’, ‘Estimator’]

Canonical target

causalis.scenarios.did.model.__all__

Link to this symbol