Per-Segment Treatment Lift Table from User-Level Experiment Data

Last updated: November 29, 2026

Quick Overview

Given user-level experiment results (user_id, arm, platform, country, metric), produce a table with one row per platform segment and overall: control mean, treatment mean, absolute delta, percent lift, and a 95 percent confidence interval for the delta using Welch's standard error.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given user-level experiment results (user_id, arm, platform, country, metric), produce a table with one row per platform segment and overall: control mean, treatment mean, absolute delta, percent lift, and a 95 percent confidence interval for the delta using Welch's standard error.

Meta's experimentation tools show deltas and confidence intervals per segment, and analysts often rebuild these in pandas to explore cuts. This onsite question checks multi-level groupby on arms and segments, unstacking arms into columns, and computing an unpooled standard error correctly per row.

What the Interviewer Expects
  • Aggregate mean, variance and count per segment and arm
  • Unstack arms into side-by-side columns
  • Compute delta, percent lift and Welch SE vectorized
  • Append an overall row computed from user level, not averaged from segments
  • Warn about multiple comparisons across many segments
Key Topics to Cover
groupby agg
unstack
Welch standard error
confidence intervals
segmentation
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you adjust for testing 20 segments at once?
  • When is a percent-lift confidence interval not just the delta CI divided by the control mean?
  • How would CUPED change these numbers?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

res(user_id, arm, platform, metric) with arms 'control' and 'treatment', one row per user. Use the normal approximation, z = 1.96. Lift is delta / control_mean. Output columns: segment, n_c, `...

Approach

Write one helper that takes a grouping key: groupby([key, 'arm']).metric.agg(['mean','var','count']).unstack('arm'). From the wide frame, delta is mean_t - mean_c and `se = sqrt(var_t/n_t + var_c/...


Submit Your Answer
Markdown supported