Compute DID estimate and pretrend flag
RobloxData Scientist · Online AssessmentLast updated
This Analytics & Experimentation question evaluates basic causal-inference and data-manipulation skills by requiring computation of a difference-in-differences (DID) estimate and a binary pretrend flag from panel-like arrays, at an implementation-level focused on summary statistics and edge-case handling.
You are given three equal-length arrays describing observations from a panel-like dataset:
period[i]∈ {0,1}: 0 = pre period, 1 = post periodtreat[i]∈ {0,1}: 1 = treated group, 0 = control groupy[i](float): outcome
Tasks:
A) Compute the difference-in-differences (DID) estimate of the treatment effect: [ \text{DID} = (\bar y_{post,treated} - \bar y_{pre,treated}) - (\bar y_{post,control} - \bar y_{pre,control}) ]
B) Compute a simple pretrend flag:
- Let (d_{pre} = \bar y_{pre,treated} - \bar y_{pre,control}).
- Given a scalar
threshold≥ 0, returnpretrend=Trueif (|d_{pre}| > threshold), elseFalse.
Assumptions/requirements:
- Use simple means over the subsets implied by (
period,treat). - Describe how you would handle missing cells (e.g., no treated observations in pre period).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.