Skip to content
Scenario9 min read

Difference in difference

We call 'Uncofoundedness' a scenario where a treatment is not randomly assigned to participants, so confounders effect on treatment assignment and outcome. We h...

Difference in difference

We call 'Uncofoundedness' a scenario where a treatment is not randomly assigned to participants, so confounders effect on treatment assignment and outcome. We have client - level data. Confounders were measured before treatment and outcome after

Result
unit_idregionsegmentis_treated_unitcohortcalendar_timeevent_timeobservedtreated_timeyy_cftau_realized_truemu_cfmu_treatedtau_mean_trueexposureavg_order_valuemarket_competitionmacro_indexseasonality_index
0control_market_01centralcore0NaT2021-01<NA>10469.338527469.3385270.0898.785094898.7850940.00.68090247.3169360.4920921.0030481.080000
1control_market_01centralcore0NaT2021-02<NA>101994.6296951994.6296950.01041.6646841041.6646840.00.73033447.3964580.4396170.9780261.120000
2control_market_01centralcore0NaT2021-03<NA>10998.702702998.7027020.01091.3277521091.3277520.00.73762146.3294610.4585861.0130551.098564
3control_market_01centralcore0NaT2021-04<NA>10894.775432894.7754320.01037.0730271037.0730270.00.66685846.7788860.4474661.0417841.080000
4control_market_01centralcore0NaT2021-05<NA>10813.824651813.8246510.01281.7740571281.7740570.00.80015948.7052520.4033321.0256561.098564
...............................................................
95control_market_03centralcore0NaT2023-08<NA>101122.5512401122.5512400.01267.1145191267.1145190.00.99811447.1571640.4032990.9608640.960000
96control_market_04westcore0NaT2021-01<NA>101889.0102761889.0102760.01902.9347701902.9347700.01.10210948.7824390.4347941.0030481.080000
97control_market_04westcore0NaT2021-02<NA>101895.9060121895.9060120.02010.5123652010.5123650.01.04259753.5809880.4594830.9780261.120000
98control_market_04westcore0NaT2021-03<NA>101842.5050091842.5050090.01994.3389401994.3389400.01.09032051.8404100.4340641.0130551.098564
99control_market_04westcore0NaT2021-04<NA>102528.6091842528.6091840.01814.6426811814.6426810.01.08960051.1776340.4411891.0417841.080000

100 rows × 20 columns

Result

is_treated_unit calendar_time 0 2021-01 111361.364257 2021-02 134519.803467 2021-03 113694.756303 2021-04 114740.158294 2021-05 120531.965221 ...
1 2023-04 45478.239469 2023-05 46485.637847 2023-06 53933.427314 2023-07 45364.853988 2023-08 39330.677225 Name: y, Length: 64, dtype: float64

Pre-fit diagnostics for Callaway-SantAnna DID

Run these checks after PanelDataDID(...) and before CallawaySantAnnaDID(...).fit(...). They use the same control-group, anticipation, and base-period choices that the model will use.

Result
testflagvaluethresholdmessage
0requested_cs_post_supportGREEN18>= 1At least one post-treatment ATT(g,t) cell is s...
1unsupported_post_cell_shareGREEN0.0<= 0.25Unsupported post-treatment cell share is withi...
2min_complete_treated_per_post_cellGREEN5>= 4Complete treated units per supported post cell...
3min_complete_control_per_post_cellGREEN60>= 10Complete control units per supported post cell...
4min_control_to_treated_ratioGREEN12.0>= 1Control-to-treated ratios are within tolerance...
5min_pair_completion_rateGREEN1.0>= 0.8Complete-pair rates are within tolerance for s...
6control_pool_retentionGREEN0.8>= 0.25Comparison-pool retention is within tolerance ...
7cluster_readinessGREEN{'n_clusters': 5, 'unstable_units': 0}stable within unit and clusters >= 2cluster_col is stable within unit and has enou...
8pre_period_depthGREEN24>= 2There are enough pre-periods for basic pre-tre...
9raw_pretrend_placeboYELLOW3.067697max |t| <= 2Raw pre-treatment DID placebo cells show a lar...
10max_base_covariate_smdGREEN0.693189<= 1Base-period covariate imbalance is within tole...
11base_control_design_rankGREEN00 rank-deficient cellsSupported post-cell control designs have full ...
12base_control_design_conditionGREEN301.005577<= 1e+08Supported post-cell control-design condition n...
Result
support_cell_idcohorttimebase_timeevent_timecontrol_groupanticipationbase_periodis_post_treatmentn_treated_available...n_control_availablen_control_completen_treatedn_controlis_supportedunsupported_reasontreated_completion_ratecontrol_completion_ratecontrol_to_treated_ratiocell_type
002023-012021-022022-12-23not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
112023-012021-032022-12-22not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
222023-012021-042022-12-21not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
332023-012021-052022-12-20not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
442023-012021-062022-12-19not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
552023-012021-072022-12-18not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
662023-012021-082022-12-17not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
772023-012021-092022-12-16not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
882023-012021-102022-12-15not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
992023-012021-112022-12-14not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
10102023-012021-122022-12-13not_yet_or_never0universalFalse5...8080580True1.01.016.0pre
11112023-012022-012022-12-12not_yet_or_never0universalFalse5...8080580True1.01.016.0pre

12 rows × 21 columns

Result
support_cell_idcohorttimebase_timeevent_timeis_post_treatmentn_treatedn_controltreated_mean_deltacontrol_mean_deltaraw_didset_stat
002023-012021-022021-01-23False580-206.544908375.522044-582.066952574.674760-1.012863
112023-012021-032021-02-22False580-186.238498-302.499241116.260743319.9406800.363382
222023-012021-042021-03-21False580-612.700743-31.611245-581.089498357.810278-1.624016
332023-012021-052021-04-20False580461.31548245.099147416.216335255.6691871.627949
442023-012021-062021-05-19False580814.911845132.274127682.637719548.5808641.244370
552023-012021-072021-06-18False580-565.330195-142.703435-422.626759265.750929-1.590312
662023-012021-082021-07-17False580-110.234414-348.372906238.138493353.7202710.673240
772023-012021-092021-08-16False580-334.544159-300.715106-33.829053409.454813-0.082620
882023-012021-102021-09-15False580-636.351333-134.316059-502.035274399.128508-1.257829
992023-012021-112021-10-14False580235.406651178.70336356.703288136.2668520.416119
10102023-012021-122021-11-13False580651.805273403.386921248.418353219.5119571.131685
11112023-012022-012021-12-12False580191.998377389.663062-197.664684286.485648-0.689964
Result

png

Result

png

Fit the model

Use the same cs_options after the diagnostics look acceptable.

Result
value
field
estimandATT
modelCallawaySantAnnaStaggeredDID
estimatordr
control_groupnot_yet_or_never
anticipation0
base_perioduniversal
include_pre_periodsTrue
value-29.0576 (ci_abs: -567.9037, 509.7884)
std_error274.9265
alpha0.0500
p_value0.9158
is_significantFalse
n_att_gt_cells120
n_skipped_cells0
inferenceclustered_influence
time2026-05-06

Post-inference diagnostics

Run these after model.fit(panel_data).estimate(). They inspect the fitted Callaway-SantAnna inference artifacts and produce a direct reliability statement in the overall_inference_reliability row. The thresholds below are set for this small synthetic example; tighten them for production review.

Result
testflagvaluethresholdmessage
0overall_inference_reliabilityGREENgreenall checks GREEN for robust relianceI can rely on the results: post-inference diag...
1data_estimate_alignmentGREENalignedno mismatchesPanelDataDID metadata matches the fitted estim...
2diagnostic_payload_availableGREENavailableunit_level, overlap, influence_scores availableDiagnostic payload required for post-inference...
3fitted_post_cell_supportGREEN{'fitted_post_cells': 18, 'skipped_post_cell_s...skipped share <= 0.2Fitted post-treatment cell support is within t...
4cell_warning_flagsGREEN{'green': 120}0 red cells, 0 yellow cellsNo fitted cells have model diagnostic warnings.
5min_control_weight_essGREEN33.849867>= 5Comparison weight effective sample sizes are w...
6max_propensity_clip_shareGREEN0.0<= 0.05Propensity clipping is within tolerance.
7weighted_covariate_balanceGREEN0.349443max |weighted SMD| <= 1Weighted covariate balance is within tolerance.
8unit_influence_concentrationGREEN{'top_unit_share': 0.14722357015468135, 'influ...top unit share <= 0.2; influence ESS >= 10Unit-level influence concentration is within t...
9cluster_influence_concentrationGREEN{'n_clusters': 5, 'top_cluster_share': 0.5}clusters >= 2; top cluster share <= 0.6Cluster influence concentration is within tole...
10fitted_pre_period_placeboGREEN22.488386max |t| <= 25Fitted pre-period placebo cells are within the...
11simple_aggregate_cell_weightGREEN0.055556max cell weight <= 0.1Simple aggregate cell weights are not overly c...
12simple_aggregate_inference_finiteGREEN{'se': 274.926504057058, 'ci_lower': -567.9036...finite SE, ordered CI, p-value in [0, 1]Simple aggregate inference outputs are finite ...
13multiplier_bootstrap_inferenceGREEN0optionalAsymptotic influence inference was used; set r...
Result
flagmessage
0GREENI can rely on the results: post-inference diag...
Result
cell_idcohorttimeevent_timeis_post_treatmentattset_statdiagnostic_statusdiagnostic_flagscontrol_weight_esspropensity_clip_share
002023-012021-02-23False-314.113235295.157749-1.064222green54.9979810.0
112023-012021-03-22False-18.492365177.720767-0.104053green54.9979810.0
222023-012021-04-21False-570.654340171.655151-3.324423green54.9979810.0
332023-012021-05-20False-128.625147132.517841-0.970625green54.9979810.0
442023-012021-06-19False542.506507124.3422054.363012green54.9979810.0
552023-012021-07-18False-96.303894259.571095-0.371012green54.9979810.0
662023-012021-08-17False413.29991194.7065374.364006green54.9979810.0
772023-012021-09-16False379.81890081.6811474.650019green54.9979810.0
882023-012021-10-15False-232.400743131.276347-1.770317green54.9979810.0
992023-012021-11-14False-182.560217169.134466-1.079379green54.9979810.0
10102023-012021-12-13False179.96958041.6408054.321952green54.9979810.0
11112023-012022-01-12False-49.695089163.915133-0.303176green54.9979810.0
Result
unit_idregionrankinfluence_scoreabs_influence_scoreabs_influence_share
0treated_market_10central114091.21139814091.2113980.147224
1treated_market_20north2-5661.7482645661.7482640.059153
2treated_market_07south35432.4201655432.4201650.056757
3treated_market_16north4-5108.0714555108.0714550.053369
4treated_market_08north5-4970.1435704970.1435700.051928
5treated_market_04east63714.3662473714.3662470.038807
6treated_market_09east7-3634.0327603634.0327600.037968
7treated_market_13central8-3356.5349043356.5349040.035069
8treated_market_06east93210.2424763210.2424760.033540
9treated_market_01west10-3100.3334993100.3334990.032392
Result
regionrankinfluence_scoreabs_influence_scoreabs_influence_share
0north1-16544.42309016544.4230900.500000
1south27704.7992387704.7992380.232852
2central37226.6564937226.6564930.218402
3east41245.6877781245.6877780.037647
4west5367.279581367.2795810.011100
Result

png

Result

png