diff_diff.TROP#

class diff_diff.TROP[source]#

Bases: TROPLocalMixin, TROPGlobalMixin

Triply Robust Panel (TROP) estimator.

Implements the exact methodology from Athey, Imbens, Qu & Viviano (2025). TROP combines three robustness components:

  1. Nuclear norm regularized factor model: Estimates interactive fixed effects L_it via matrix completion with nuclear norm penalty ||L||_*

  2. Exponential distance-based unit weights: ω_j = exp(-λ_unit × d(j,i)) where d(j,i) is the RMSE of outcome differences between units

  3. Exponential time decay weights: θ_s = exp(-λ_time × \(|s-t|\)) weighting pre-treatment periods by proximity to treatment

Tuning parameters (λ_time, λ_unit, λ_nn) are selected via leave-one-out cross-validation on control observations.

Parameters:
  • method (str, default='local') –

    Estimation method to use:

    • ’local’: Per-observation model fitting following Algorithm 2 of Athey et al. (2025). Computes observation-specific weights and fits a model for each treated observation, averaging the individual treatment effects. More flexible but computationally intensive.

    • ’global’: Computationally efficient adaptation using the (1-W) masking principle from Eq. 2. Fits a single model on control observations with global weights, then computes per-observation treatment effects as residuals: tau_it = Y_it - mu - alpha_i - beta_t - L_it for treated cells. ATT is the mean of these effects. For the paper’s full per-treated-cell estimator, use method='local'.

  • lambda_time_grid (list, optional) – Grid of time weight decay parameters. 0.0 = uniform weights (disabled). Must not contain inf. Default: [0, 0.1, 0.5, 1, 2, 5].

  • lambda_unit_grid (list, optional) – Grid of unit weight decay parameters. 0.0 = uniform weights (disabled). Must not contain inf. Default: [0, 0.1, 0.5, 1, 2, 5].

  • lambda_nn_grid (list, optional) – Grid of nuclear norm regularization parameters. inf = factor model disabled (L=0). Default: [0, 0.01, 0.1, 1].

  • max_iter (int, default=100) – Maximum iterations for nuclear norm optimization.

  • tol (float, default=1e-6) – Convergence tolerance for optimization.

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

  • n_bootstrap (int, default=200) – Number of bootstrap replications for variance estimation. Must be >= 2.

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

  • non_absorbing (bool, default=False) –

    Treatment-assignment scope for the treatment indicator.

    • False (default): require an ABSORBING STATE indicator (once treated, always treated). A non-monotonic indicator raises ValueError. This guards against the common mistake of encoding absorbing treatment as an event-style spike (a single D=1 period), which would silently bias the ATT.

    • True: accept general (on/off) assignment patterns, where treatment may switch on and off, per Athey et al. (2025) Eq. 12 / Algorithm 2. Supported for method='local' only (method='global' raises). Relies on the paper’s no-dynamic-effects (no carryover) assumption; the triple-robustness guarantee (Theorem 5.1) is proven only under block assignment, so a UserWarning is emitted on fit. The estimand averages the per-cell effects over the estimable treated (D=1) cells (Eq. 1): a cell is non-estimable (NaN, excluded) when its unit/time fixed effect alpha_i + beta_t is unidentified by the control fit – i.e. the target unit and target period are not in the same connected component of the observed-control graph (an always-treated unit, a fully-treated period, or disconnected control support). This matches the library non-estimable->NaN convention (see REGISTRY ## TROP “non-absorbing non-estimable-cell trimming”).

results_#

Estimation results after calling fit().

Type:

TROPResults

is_fitted_#

Whether the model has been fitted.

Type:

bool

Examples

>>> from diff_diff import TROP
>>> trop = TROP()
>>> results = trop.fit(
...     data,
...     outcome='outcome',
...     treatment='treated',
...     unit='unit',
...     time='period',
... )
>>> results.print_summary()

References

Athey, S., Imbens, G. W., Qu, Z., & Viviano, D. (2025). Triply Robust Panel Estimators. Working Paper. https://arxiv.org/abs/2508.21536

Methods

__init__([method, lambda_time_grid, ...])

fit(data, outcome, treatment, unit, time[, ...])

Fit the TROP model.

get_params()

Get estimator parameters.

set_params(**params)

Set estimator parameters.

Attributes

CONVERGENCE_TOL_SVD

max_iter

tol

n_bootstrap

seed

lambda_time_grid

lambda_unit_grid

lambda_nn_grid

alpha

results_

is_fitted_

__init__(method='local', lambda_time_grid=None, lambda_unit_grid=None, lambda_nn_grid=None, max_iter=100, tol=1e-06, alpha=0.05, n_bootstrap=200, seed=None, non_absorbing=False)[source]#
Parameters:
classmethod __new__(*args, **kwargs)#