Post-Stratified ATE and Standard Error
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Implement `def stratified_ate_se(df: pd.DataFrame) -> dict` in `solution.py`. Each row is one stratum with columns `weight` ($w_s$, the stratum's population share; the shares sum to 1), `diff` ($d_s$, the treatment-minus-control effect in that stratum) and `se` ($se_s$, the standard error of $d_s$). Return the post-stratified estimate as a dict.
Requirements:
- `ate` is $\sum_s w_s d_s$.
- `se` is $\sqrt{\sum_s w_s^2 \, se_s^2}$. The strata are independent, so their variances add.
- Do not sum the linearly weighted standard errors $w_s \, se_s$.
- Return `{'ate': float, 'se': float}` with exactly those two keys.
Example:
```python
# strata (w, d, se):
# (2/7, 2.0, 0.30)
# (4/7, 3.0, 0.25)
# (1/7, 1.0, 0.40)
stratified_ate_se(df)
# -> {'ate': 2.4285714285714284, 'se': 0.17612611437054218}
```
```hint Variance of a weighted sum
Write out the variance of a weighted sum of independent estimates before you take any square root.
```
### Constraints & Assumptions
- One row per stratum, with numeric columns `weight`, `diff` and `se`.
- The weights are known population shares and sum to 1.
- The per-stratum estimates are independent of one another.
### What a Strong Answer Covers
- Computes the point estimate as the weighted sum of the within-stratum effects.
- Derives the combined variance from the variance of a weighted sum of independent terms, then takes the square root.
- Explains what goes wrong when the weighted standard errors are summed linearly, and in which direction the error goes.
- Returns exactly the two required keys as plain floats.
- States what the standard error assumes: independent strata and known weights.
### Follow-up Questions
- Why do the weights enter the variance squared, and what would summing $w_s \, se_s$ implicitly assume about the strata?
- What changes if the weights are estimated from the sample instead of being known?
- How would you turn the output into a 95% confidence interval, and when is the normal interval a poor choice?
- What would you do with a stratum that has no treated users or no control users?
Overview: Implement a pandas function that combines per-stratum treatment effects and their standard errors into a post-stratified average treatment effect and its standard error. It tests the variance of a weighted sum of independent estimates and why weighted standard errors cannot simply be added.