You are given individual-level observational data for an experiment-like setting with:
-
period[i]
∈ {0,1}: 0 = pre period, 1 = post period
-
treatment[i]
∈ {0,1}: 1 = treated group, 0 = control group
-
outcome[i]
∈ ℝ: numeric outcome
All three arrays have the same length N, and row i corresponds to one observation.
Tasks
-
Compute the
Difference-in-Differences (DiD) estimate
of the treatment effect:
DiD=(YˉT,post−YˉT,pre)−(YˉC,post−YˉC,pre)
where the bars denote sample means over the corresponding subsets.
-
Compute a
pretrend flag
using the following simplified rule:
-
Let
dpre=∣YˉT,pre−YˉC,pre∣
.
-
Given a real number
threshold
, return
pretrend=True
if
dpre>threshold
, else
False
.
Output
Return:
-
did_estimate
(float)
-
pretrend
(boolean)
Assumptions / edge cases
-
If any of the required cells (T/C × pre/post) has zero observations, specify and implement a reasonable behavior (e.g., raise an error or return NaN).