Katkat

Compute DID estimate and pretrend flag

RobloxData Scientist · Online Assessment

Last 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 period
  • treat[i] ∈ {0,1}: 1 = treated group, 0 = control group
  • y[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, return pretrend=True if (|d_{pre}| > threshold), else False.

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).