diff_diff.TROP

class diff_diff.TROP[source]

Bases: object

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='twostep') –

    Estimation method to use:

    • ’twostep’: 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.

    • ’joint’: Joint weighted least squares optimization. Estimates a single scalar treatment effect τ along with fixed effects and optional low-rank factor adjustment. Faster but assumes homogeneous treatment effects. Uses alternating minimization when nuclear norm penalty is finite.

  • 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.

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

__init__(method='twostep', 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)[source]
Parameters:

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

Tolerance for singular value truncation in soft-thresholding.

CONVERGENCE_TOL_SVD: float = 1e-10

Tolerance for singular value truncation in soft-thresholding.

Singular values below this threshold after soft-thresholding are treated as zero to improve numerical stability.

__init__(method='twostep', 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)[source]
Parameters:
fit(data, outcome, treatment, unit, time)[source]

Fit the TROP model.

Parameters:
  • data (pd.DataFrame) – Panel data with observations for multiple units over multiple time periods.

  • outcome (str) – Name of the outcome variable column.

  • treatment (str) –

    Name of the treatment indicator column (0/1).

    IMPORTANT: This should be an ABSORBING STATE indicator, not a treatment timing indicator. For each unit, D=1 for ALL periods during and after treatment:

    • D[t, i] = 0 for all t < g_i (pre-treatment periods)

    • D[t, i] = 1 for all t >= g_i (treatment and post-treatment)

    where g_i is the treatment start time for unit i.

    For staggered adoption, different units can have different g_i. The ATT averages over ALL D=1 cells per Equation 1 of the paper.

  • unit (str) – Name of the unit identifier column.

  • time (str) – Name of the time period column.

Returns:

Object containing the ATT estimate, standard error, factor estimates, and tuning parameters. The lambda_* attributes show the selected grid values. For λ_time and λ_unit, 0.0 means uniform weights; inf is not accepted. For λ_nn, ∞ is converted to 1e10 (factor model disabled).

Return type:

TROPResults

get_params()[source]

Get estimator parameters.

Return type:

Dict[str, Any]

set_params(**params)[source]

Set estimator parameters.

Return type:

TROP