Skip to content

Commit eb59806

Browse files
authored
docs(v4): PR 5a-ii of the 4.0 cut - migrate the documented readers of the overall_* field names to the canonical quintet (#874)
1 parent 0fd4590 commit eb59806

45 files changed

Lines changed: 449 additions & 335 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎benchmarks/python/benchmark_callaway.py‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
from pathlib import Path
1414

15+
1516
# IMPORTANT: Parse --backend and set environment variable BEFORE importing diff_diff
1617
# This ensures the backend configuration is respected by all modules
1718
def _get_backend_from_args():
@@ -21,6 +22,7 @@ def _get_backend_from_args():
2122
args, _ = parser.parse_known_args()
2223
return args.backend
2324

25+
2426
_requested_backend = _get_backend_from_args()
2527
if _requested_backend in ("python", "rust"):
2628
os.environ["DIFF_DIFF_BACKEND"] = _requested_backend
@@ -44,9 +46,7 @@ def _get_backend_from_args():
4446

4547

4648
def parse_args():
47-
parser = argparse.ArgumentParser(
48-
description="Benchmark Callaway-Sant'Anna estimator"
49-
)
49+
parser = argparse.ArgumentParser(description="Benchmark Callaway-Sant'Anna estimator")
5050
parser.add_argument("--data", required=True, help="Path to input CSV data")
5151
parser.add_argument("--output", required=True, help="Path to output JSON results")
5252
parser.add_argument(
@@ -62,12 +62,15 @@ def parse_args():
6262
help="Control group definition",
6363
)
6464
parser.add_argument(
65-
"--backend", default="auto", choices=["auto", "python", "rust"],
66-
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)"
65+
"--backend",
66+
default="auto",
67+
choices=["auto", "python", "rust"],
68+
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)",
6769
)
6870
parser.add_argument(
69-
"--warmup", action="store_true",
70-
help="Run one untimed fit before the timed fit (JIT/cache warm-up)"
71+
"--warmup",
72+
action="store_true",
73+
help="Run one untimed fit before the timed fit (JIT/cache warm-up)",
7174
)
7275
return parser.parse_args()
7376

@@ -153,20 +156,24 @@ def main():
153156
# run_refresh.py joins these records against R on `event_time`.
154157
es_effects = []
155158
for row in es.to_dataframe().sort_values("event_time").itertuples(index=False):
156-
es_effects.append({
157-
"event_time": int(row.event_time),
158-
"att": float(row.att),
159-
"se": float(row.se),
160-
})
159+
es_effects.append(
160+
{
161+
"event_time": int(row.event_time),
162+
"att": float(row.att),
163+
"se": float(row.se),
164+
}
165+
)
161166

162167
# Format group effects from the post-fit container (joined on `group`).
163168
grp_effects = []
164169
for row in grp.to_dataframe().sort_values("label").itertuples(index=False):
165-
grp_effects.append({
166-
"group": int(row.label),
167-
"att": float(row.att),
168-
"se": float(row.se),
169-
})
170+
grp_effects.append(
171+
{
172+
"group": int(row.label),
173+
"att": float(row.att),
174+
"se": float(row.se),
175+
}
176+
)
170177

171178
# Build output
172179
output = {
@@ -175,8 +182,8 @@ def main():
175182
"method": args.method,
176183
"control_group": args.control_group,
177184
# Overall ATT
178-
"overall_att": float(results.overall_att),
179-
"overall_se": float(results.overall_se),
185+
"overall_att": float(results.att),
186+
"overall_se": float(results.se),
180187
# Group-time effects
181188
"group_time_effects": gt_effects,
182189
# Event study

‎benchmarks/python/benchmark_imputation.py‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import sys
1515
from pathlib import Path
1616

17+
1718
# IMPORTANT: Parse --backend and set environment variable BEFORE importing diff_diff
1819
# This ensures the backend configuration is respected by all modules
1920
def _get_backend_from_args():
@@ -23,6 +24,7 @@ def _get_backend_from_args():
2324
args, _ = parser.parse_known_args()
2425
return args.backend
2526

27+
2628
_requested_backend = _get_backend_from_args()
2729
if _requested_backend in ("python", "rust"):
2830
os.environ["DIFF_DIFF_BACKEND"] = _requested_backend
@@ -38,14 +40,14 @@ def _get_backend_from_args():
3840

3941

4042
def parse_args():
41-
parser = argparse.ArgumentParser(
42-
description="Benchmark Imputation DiD estimator"
43-
)
43+
parser = argparse.ArgumentParser(description="Benchmark Imputation DiD estimator")
4444
parser.add_argument("--data", required=True, help="Path to input CSV data")
4545
parser.add_argument("--output", required=True, help="Path to output JSON results")
4646
parser.add_argument(
47-
"--backend", default="auto", choices=["auto", "python", "rust"],
48-
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)"
47+
"--backend",
48+
default="auto",
49+
choices=["auto", "python", "rust"],
50+
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)",
4951
)
5052
return parser.parse_args()
5153

@@ -98,19 +100,21 @@ def main():
98100
for row in es.to_dataframe().sort_values("event_time").itertuples(index=False):
99101
if bool(row.is_reference):
100102
continue
101-
es_effects.append({
102-
"event_time": int(row.event_time),
103-
"att": float(row.att),
104-
"se": float(row.se),
105-
})
103+
es_effects.append(
104+
{
105+
"event_time": int(row.event_time),
106+
"att": float(row.att),
107+
"se": float(row.se),
108+
}
109+
)
106110

107111
# Build output
108112
output = {
109113
"estimator": "diff_diff.ImputationDiD",
110114
"backend": actual_backend,
111115
# Overall ATT
112-
"overall_att": float(results.overall_att),
113-
"overall_se": float(results.overall_se),
116+
"overall_att": float(results.att),
117+
"overall_se": float(results.se),
114118
# Event study
115119
"event_study": es_effects,
116120
# Timing
@@ -135,7 +139,7 @@ def main():
135139
with open(output_path, "w") as f:
136140
json.dump(output, f, indent=2)
137141

138-
print(f"Overall ATT: {results.overall_att:.6f} (SE: {results.overall_se:.6f})")
142+
print(f"Overall ATT: {results.att:.6f} (SE: {results.se:.6f})")
139143
print(f"Completed in {total_time:.3f} seconds")
140144
return output
141145

‎benchmarks/python/benchmark_stacked_did.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def main():
134134
"estimator": "diff_diff.StackedDiD",
135135
"backend": actual_backend,
136136
# Overall ATT
137-
"overall_att": float(results.overall_att),
138-
"overall_se": float(results.overall_se),
137+
"overall_att": float(results.att),
138+
"overall_se": float(results.se),
139139
# Event study
140140
"event_study": es_effects,
141141
# Timing
@@ -164,7 +164,7 @@ def main():
164164
with open(output_path, "w") as f:
165165
json.dump(output, f, indent=2)
166166

167-
print(f"Overall ATT: {results.overall_att:.6f} (SE: {results.overall_se:.6f})")
167+
print(f"Overall ATT: {results.att:.6f} (SE: {results.se:.6f})")
168168
if results.event_study_effects:
169169
for h, eff in sorted(results.event_study_effects.items()):
170170
if eff.get("n_obs", 1) > 0:

‎benchmarks/python/benchmark_sun_abraham.py‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
from pathlib import Path
1717

18+
1819
# IMPORTANT: Parse --backend and set environment variable BEFORE importing diff_diff
1920
def _get_backend_from_args():
2021
"""Parse --backend argument without importing diff_diff."""
@@ -23,6 +24,7 @@ def _get_backend_from_args():
2324
args, _ = parser.parse_known_args()
2425
return args.backend
2526

27+
2628
_requested_backend = _get_backend_from_args()
2729
if _requested_backend in ("python", "rust"):
2830
os.environ["DIFF_DIFF_BACKEND"] = _requested_backend
@@ -43,8 +45,10 @@ def parse_args():
4345
parser.add_argument("--data", required=True, help="Path to input CSV data")
4446
parser.add_argument("--output", required=True, help="Path to output JSON results")
4547
parser.add_argument(
46-
"--backend", default="auto", choices=["auto", "python", "rust"],
47-
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)"
48+
"--backend",
49+
default="auto",
50+
choices=["auto", "python", "rust"],
51+
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)",
4852
)
4953
return parser.parse_args()
5054

@@ -78,19 +82,21 @@ def main():
7882
first_treat="first_treat",
7983
)
8084

81-
overall_att = results.overall_att
82-
overall_se = results.overall_se
83-
overall_pvalue = results.overall_p_value
85+
overall_att = results.att
86+
overall_se = results.se
87+
overall_pvalue = results.p_value
8488

8589
# Extract event study effects
8690
event_study = []
8791
for e in sorted(results.event_study_effects.keys()):
8892
eff = results.event_study_effects[e]
89-
event_study.append({
90-
"event_time": int(e),
91-
"att": float(eff["effect"]),
92-
"se": float(eff["se"]),
93-
})
93+
event_study.append(
94+
{
95+
"event_time": int(e),
96+
"att": float(eff["effect"]),
97+
"se": float(eff["se"]),
98+
}
99+
)
94100

95101
total_time = timer.elapsed
96102

‎benchmarks/python/benchmark_wooldridge.py‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
from pathlib import Path
1717

18+
1819
# IMPORTANT: Parse --backend and set environment variable BEFORE importing diff_diff
1920
def _get_backend_from_args():
2021
"""Parse --backend argument without importing diff_diff."""
@@ -23,6 +24,7 @@ def _get_backend_from_args():
2324
args, _ = parser.parse_known_args()
2425
return args.backend
2526

27+
2628
_requested_backend = _get_backend_from_args()
2729
if _requested_backend in ("python", "rust"):
2830
os.environ["DIFF_DIFF_BACKEND"] = _requested_backend
@@ -38,14 +40,14 @@ def _get_backend_from_args():
3840

3941

4042
def parse_args():
41-
parser = argparse.ArgumentParser(
42-
description="Benchmark WooldridgeDiD (ETWFE) estimator"
43-
)
43+
parser = argparse.ArgumentParser(description="Benchmark WooldridgeDiD (ETWFE) estimator")
4444
parser.add_argument("--data", required=True, help="Path to input CSV data (mpdta format)")
4545
parser.add_argument("--output", required=True, help="Path to output JSON results")
4646
parser.add_argument(
47-
"--backend", default="auto", choices=["auto", "python", "rust"],
48-
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)"
47+
"--backend",
48+
default="auto",
49+
choices=["auto", "python", "rust"],
50+
help="Backend to use: auto (default), python (pure Python), rust (Rust backend)",
4951
)
5052
return parser.parse_args()
5153

@@ -91,31 +93,35 @@ def main():
9193
# Format ATT(g,t) effects
9294
gt_effects_out = []
9395
for (g, t), cell in sorted(results.group_time_effects.items()):
94-
gt_effects_out.append({
95-
"cohort": int(g),
96-
"time": int(t),
97-
"att": float(cell["att"]),
98-
"se": float(cell["se"]),
99-
})
96+
gt_effects_out.append(
97+
{
98+
"cohort": int(g),
99+
"time": int(t),
100+
"att": float(cell["att"]),
101+
"se": float(cell["se"]),
102+
}
103+
)
100104

101105
# Format event study effects
102106
es_effects = []
103107
if results.event_study_effects:
104108
for rel_t, effect_data in sorted(results.event_study_effects.items()):
105-
es_effects.append({
106-
"event_time": int(rel_t),
107-
"att": float(effect_data["att"]),
108-
"se": float(effect_data["se"]),
109-
})
109+
es_effects.append(
110+
{
111+
"event_time": int(rel_t),
112+
"att": float(effect_data["att"]),
113+
"se": float(effect_data["se"]),
114+
}
115+
)
110116

111117
output = {
112118
"estimator": "diff_diff.WooldridgeDiD",
113119
"method": "ols",
114120
"control_group": "not_yet_treated",
115121
"backend": actual_backend,
116122
# Overall ATT
117-
"overall_att": float(results.overall_att),
118-
"overall_se": float(results.overall_se),
123+
"overall_att": float(results.att),
124+
"overall_se": float(results.se),
119125
# Group-time ATT(g,t)
120126
"group_time_effects": gt_effects_out,
121127
# Event study
@@ -140,7 +146,7 @@ def main():
140146
with open(output_path, "w") as f:
141147
json.dump(output, f, indent=2)
142148

143-
print(f"Overall ATT: {results.overall_att:.6f} (SE: {results.overall_se:.6f})")
149+
print(f"Overall ATT: {results.att:.6f} (SE: {results.se:.6f})")
144150
print(f"Completed in {total_time:.3f} seconds")
145151
return output
146152

‎benchmarks/speed_review/bench_solve_ols_fastpath.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def fit(d):
129129
# fit(aggregate="all") route, removed at 4.0).
130130
res.aggregate("event_study")
131131
res.aggregate("group")
132-
return float(res.overall_att), float(res.overall_se)
132+
return float(res.att), float(res.se)
133133

134134
return df, fit
135135
if scenario == "survey_absorb":

0 commit comments

Comments
 (0)