Functional API¶
The functional API mirrors the Stata command surface: a single call that takes the panel, returns a dict.
did_multiplegt_stat¶
did_multiplegt_stat ¶
did_multiplegt_stat(df: DataFrame, Y: str, ID: str, Time: str, D: str, Z: str | None = None, estimator: str | Sequence[str] | None = None, order: int | list[int] = 1, noextrapolation: bool = False, placebo: int = 0, switchers: str | None = None, disaggregate: bool = False, as_vs_was: bool = False, exact_match: bool = False, by: Sequence[str] | None = None, by_fd: int | None = None, by_baseline: int | None = None, other_treatments: Sequence[str] | None = None, cluster: str | None = None, weight: str | None = None, controls: Sequence[str] | None = None, cross_fitting: int = 0, trimming: float = 0, on_placebo_sample: bool = False, bootstrap: int = 0, twfe: bool | dict[str, Any] = False, seed: int = 0, cross_validation: dict[str, Any] | None = None, iv_method: str = 'manual', cf_folds_file: str | None = None, asinstata: bool = False, model_deltay=None, model_stayer=None, **legacy_options) -> dict[str, Any]
Python interface for did_multiplegt_stat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame - Panel data in long format.
|
|
required |
Y
|
str - Column names for outcome, unit ID, time, treatment.
|
|
required |
ID
|
str - Column names for outcome, unit ID, time, treatment.
|
|
required |
Time
|
str - Column names for outcome, unit ID, time, treatment.
|
|
required |
D
|
str - Column names for outcome, unit ID, time, treatment.
|
|
required |
Z
|
str, optional - Instrument variable for IV-WAS.
|
|
None
|
estimator
|
str or list - 'as', 'was', 'iv-was'.
|
|
None
|
as_vs_was
|
bool - Test equality of the AS and WAS estimators.
|
|
False
|
order
|
int or list of 1/4/8 ints - Polynomial order(s). 8 ints for IV: first 4=first-stage, last 4=reduced-form.
|
|
1
|
placebo
|
int - Number of placebos (0 = none).
|
|
0
|
iv_method
|
str - IV regression package: 'manual' (default, two OLS), 'linearmodels', or 'econtools'.
|
|
'manual'
|
controls
|
list of str - Control variables.
|
|
None
|
cross_fitting
|
int - Number of cross-fitting folds (0 = none).
|
|
0
|
trimming
|
float - Propensity score trimming threshold (0 = none).
|
|
0
|
on_placebo_sample
|
bool - Estimate only on stayer sample.
|
|
False
|
bootstrap
|
int - Number of bootstrap replications (0 = none).
|
|
0
|
twfe
|
bool or dict - Compare with TWFE regression. Dict keys: same_sample, percentile.
|
|
False
|
cross_validation
|
dict - CV options (algorithm, tolerance, max_k, seed, kfolds).
|
|
None
|
by_baseline
|
int - Number of quantile bins for baseline treatment.
|
|
None
|
cf_folds_file
|
str, optional - Path to CSV with cross-fitting fold IDs exported by Stata.
|
Columns: pairwise, placebo_index, estimator_type, ID_XX, cf_sample_id. When provided, fold assignments are read from this file instead of generated internally. |
None
|
asinstata
|
bool
|
(custom Newton-Raphson logit + statsmodels OLS). If False (default), use scikit-learn LinearRegression / LogisticRegression for all OLS and logit estimations. Note: changing this flag changes numerical results; Stata parity tests require asinstata=True. |
False - If True, use Stata-faithful regressions
|
model_deltay
|
object, optional - Custom regression model for E[DeltaY|D1,S=0].
|
Must implement .fit(X, y) and .predict(X) (sklearn-style). When provided, overrides the default OLS model (regardless of asinstata). Example: RandomForestRegressor(n_estimators=100). |
None
|
model_stayer
|
object, optional - Custom classification model for P(stayer|D1).
|
Must implement .fit(X, y) and .predict_proba(X) (sklearn-style). When provided, overrides the default logit model (regardless of asinstata). Example: RandomForestClassifier(n_estimators=100). |
None
|
Source code in src/did_multiplegt_stat/core.py
3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 | |
summary_did_multiplegt_stat¶
summary_did_multiplegt_stat ¶
Source code in src/did_multiplegt_stat/core.py
3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 | |
print_did_multiplegt_stat¶
print_did_multiplegt_stat ¶
Return value (dict)¶
The returned dict has the following keys (omitting placebo / by-group blocks when not requested):
| Key | Type | Description |
|---|---|---|
args |
dict |
A snapshot of every option passed to did_multiplegt_stat. |
results |
dict |
The single main-results block when no by/by_fd/by_baseline. |
results_by_{j} |
dict |
Per-by-group results block when by/by_fd/by_baseline is set. j runs from 1. |
by_levels |
list |
Levels in order, so by_levels[j-1] matches results_by_{j}. |
first_stage |
dict |
Same shape as the top-level dict, returned by the inner first-stage call when estimator="iv-was". |
twfe_comparison |
pd.DataFrame |
Bootstrap-based TWFE comparison table when twfe=True. |
val_quantiles |
list |
Quantile cut-points when by_fd / by_baseline is set. |
switch_df |
pd.DataFrame |
Per-bin switcher count + median |ΔD| when by_fd. |
_class |
str |
Always "did_multiplegt_stat". Useful sentinel for type checks. |
Inside each results* block:
| Key | Type | Description |
|---|---|---|
table |
pd.DataFrame |
Main effects table for this block. |
table_placebo_{p} |
pd.DataFrame |
Placebo table for placebo p ∈ {1, …, N}. |
N |
int |
Number of observations used in this block. |
n_clusters |
int |
Set only when cluster= was used. |
pairs |
int |
Number of consecutive-period pairs in the panel. |
as_vs_was |
pd.DataFrame |
Difference-test table when as_vs_was=True. |