Skip to content

Commit 17f4859

Browse files
committed
set up empirical coverage test for did binary
1 parent f28f107 commit 17f4859

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scripts/did/did_pa_atte_coverage.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@
2626
for dgp_type in dgp_types:
2727
datasets_dgp = []
2828
for i in range(n_rep):
29-
data = make_did_SZ2020(n_obs=n_obs, dgp_type=dgp_type, cross_sectional_data=False)
29+
df = make_did_SZ2020(n_obs=n_obs, dgp_type=dgp_type, cross_sectional_data=False, return_type='DataFrame', return_diff = False)
30+
# Add id variable
31+
df['id'] = np.arange(n_obs)
32+
# Reorganize the data in long format (one row per time period per individual)
33+
df = pd.wide_to_long(df, stubnames='y', i='id', j='t').reset_index().sort_values(['id', 't'])
34+
# add value of one to column t (periods 1 and 2)
35+
df['t'] = df['t'] + 1
36+
# Create a new column called G which is based on d: G = 2*d
37+
# G: 0 if (not/never) treated and 2 if treated in period 2
38+
df['G'] = df['d']*2
39+
# drop d
40+
df.drop(columns = ['d'], inplace = True)
41+
42+
data = dml.DoubleMLPanelData(df, y_col='y', d_cols='G' , t_col = "t", id_col = "id", x_cols=['Z1', 'Z2', 'Z3', 'Z4'])
3043
datasets_dgp.append(data)
3144
datasets.append(datasets_dgp)
3245

@@ -66,18 +79,20 @@
6679
for score in hyperparam_dict["score"]:
6780
for in_sample_normalization in hyperparam_dict["in sample normalization"]:
6881
if score == "experimental":
69-
dml_DiD = dml.DoubleMLDID(
82+
dml_DiD = dml.DoubleMLDIDBINARY(
7083
obj_dml_data=obj_dml_data,
7184
ml_g=ml_g,
7285
ml_m=None,
7386
score=score,
7487
in_sample_normalization=in_sample_normalization)
7588
else:
7689
assert score == "observational"
77-
dml_DiD = dml.DoubleMLDID(
90+
dml_DiD = dml.DoubleMLDIDBINARY(
7891
obj_dml_data=obj_dml_data,
7992
ml_g=ml_g,
8093
ml_m=ml_m,
94+
g_value = 2,
95+
t_value = 1,
8196
score=score,
8297
in_sample_normalization=in_sample_normalization)
8398
dml_DiD.fit(n_jobs_cv=5)

0 commit comments

Comments
 (0)