Extra Practice: Causation
Each group below is a set of practice problems. Almost all of them are conceptual questions or pen and paper exercises (a calculator is fine, but no code). There is one short, optional code exercise at the end.
I recommend working through them in order: they follow the order of the notes, from the definition of causation, to randomized experiments, to observational studies and matching.
Click a group to open it.
No data and no code. For each question, answer in a sentence or two.
Q1 “The streetlight outside my house went out because a squirrel chewed through the wire.” Using the counterfactual definition of causation, what would you need to know to decide whether the squirrel caused the light to go out?
Show answer
You would need to know that, in a world where the squirrel had not chewed the wire (and everything else stayed the same), the streetlight would not have gone out.
Q2 Two tutors are at the door handing out warmup sheets. Tutor 1 hands you a sheet. If Tutor 1 hadn’t, Tutor 2 would have handed you one instead. According to the counterfactual definition, did Tutor 1 cause you to have a sheet? Does that match your intuition?
Show answer
According to the definition, no: in a world where Tutor 1 didn’t hand you a sheet, you would still have a sheet (from Tutor 2), so the outcome doesn’t change. The same argument says Tutor 2 didn’t cause it either.
Most people’s intuition says Tutor 1 did cause it, since Tutor 1 is the one who handed it over. This is a known weak spot of the counterfactual definition: when there are “backup” causes, none of them counts as a cause on its own. The definition is very useful, but it is a choice, not the only possible notion of causation.
Q3 For each claim, identify the treatment variable \(D\) and the outcome variable \(Y\), and say what type of variable each one is (binary, categorical, numerical…).
(a) “Drinking coffee in the morning makes me more productive.” (b) “Raising the minimum wage reduces the number of people employed in a city.” (c) “Students who study more hours per week get better letter grades.”
Show answer
- (a) \(D\) = drinks coffee in the morning or not (binary, 1 or 0). \(Y\) = productivity, measured for example as tasks completed in a day (numerical).
- (b) \(D\) = minimum wage level (numerical, in dollars per hour), or “raised the minimum wage or not” (binary). \(Y\) = number of people employed in the city (numerical).
- (c) \(D\) = hours studied per week (numerical). \(Y\) = letter grade (categorical, ordinal).
Note that (c), as written, is not a causal claim: it describes the students who study more, without saying what would happen if a student changed how much they study. The causal version would be “studying more hours per week makes students get better grades”.
Q4 Is each of these a summary claim, a generalization claim, a prediction claim, or a causal claim?
(a) “In my section this semester, the students who sat in the front row had a higher average grade than the others.”
(b) “Based on a random sample of 300 students, Berkeley undergraduates who sit in the front row tend to get higher grades.”
(c) “Mia has a 3.8 GPA and always sits in the front row, so she will probably get an A in this class.”
(d) “Sitting in the front row would raise your grade.”
(e) “This vaccine reduces the risk of hospitalization.”
Show answer
- (a) Summary: it describes the data at hand (one section, this semester), and nothing beyond it.
- (b) Generalization: it uses a sample to make a claim about a larger population (all Berkeley undergraduates).
- (c) Prediction: it is about an observable value we haven’t seen yet (Mia’s grade).
- (d) Causal: it is about what would happen to you in a world where you changed where you sit.
- (e) Causal: it is about what would happen in a world where people got the vaccine versus one where they didn’t.
Notice that (a), (b), and (c) all involve the front row and grades, but none of them says that sitting in the front row changes your grade. A useful test: a causal claim is about what would happen if we changed the treatment. That’s why (a) and (b), even if true, don’t support (d): maybe students who choose the front row are more motivated to begin with.
Q5 The treatment is “minutes studied per day”, which can take any value between 0 and 120. How many potential outcomes does each student have?
Show answer
One for every possible value of the treatment: \(Y(0)\), \(Y(1.5)\), \(Y(30)\), \(Y(120)\), and so on. Since the treatment is continuous, that’s infinitely many potential outcomes for each student. Only one of them is ever observed: the one that corresponds to how much the student actually studied.
That’s why, in this class, we focus on a binary treatment, with just two potential outcomes, \(Y_t\) and \(Y_c\).
Q6 Why can we never directly observe an individual treatment effect?
Show answer
The individual treatment effect is \(Y_t - Y_c\), so we need both potential outcomes of the same person. But each person either takes the treatment or doesn’t: we observe \(Y_t\) for the treated and \(Y_c\) for the controls, never both for the same person at the same time. The other potential outcome lives in a counterfactual world that we can’t visit.
Q7 I took a painkiller and my headache went away in 30 minutes. A friend says: “That proves the painkiller works.” What’s wrong with that argument?
Show answer
It only looks at one world, the one where I took the painkiller (\(Y_t\) = 30 minutes). To say the painkiller caused the headache to go away faster, we would also need to know how long it would have taken without the painkiller (\(Y_c\)). Maybe my headache would have gone away in 30 minutes anyway. The argument skips the counterfactual completely.
This whole case study is meant for pen and paper. You can use a calculator, but no code.
A company sells a sleep app and claims that it makes people sleep longer. Here is a (tiny) population of 6 people. Like in the notes, we pretend that we know both potential outcomes of everyone:
| Variable | Meaning | Units of measurement |
|---|---|---|
| \(D\) | 1 if the person uses the app, 0 otherwise | none (it’s a category) |
| \(Y\) | hours of sleep per night | hours |
| Name | Hours of sleep with the app (\(Y_t\)) | Hours of sleep without the app (\(Y_c\)) |
|---|---|---|
| Kai | 7.5 | 7.0 |
| Lena | 6.0 | 6.0 |
| Omar | 8.0 | 7.0 |
| Priya | 5.5 | 6.0 |
| Rosa | 7.0 | 6.0 |
| Theo | 6.0 | 5.0 |
Q1 Compute the individual treatment effect of each person, with units. Who benefits from the app? Is anyone harmed by it? Is anyone unaffected?
Show answer
The individual treatment effect is \(\mbox{ITE} = Y_t - Y_c\), measured in hours (the same units as \(Y\)):
| Name | \(Y_t - Y_c\) (hours) |
|---|---|
| Kai | 7.5 − 7.0 = 0.5 |
| Lena | 6.0 − 6.0 = 0 |
| Omar | 8.0 − 7.0 = 1.0 |
| Priya | 5.5 − 6.0 = −0.5 |
| Rosa | 7.0 − 6.0 = 1.0 |
| Theo | 6.0 − 5.0 = 1.0 |
Kai, Omar, Rosa, and Theo benefit (positive effect). Priya is harmed: she would sleep half an hour less with the app. Lena is unaffected.
Q2 Compute the average treatment effect (ATE) of the app in this population, with units.
Show answer
The ATE is the population average of the individual treatment effects:
\[ \mbox{ATE} = E(Y_t - Y_c) = \frac{0.5 + 0 + 1.0 - 0.5 + 1.0 + 1.0}{6} = \frac{3.0}{6} = 0.5 \text{ hours} \]
On average, the app makes people sleep half an hour (30 minutes) more per night.
Q3 Now compute \(E(Y_t)\) and \(E(Y_c)\), the population averages of the two potential outcomes. What do you notice when you subtract them?
Show answer
\[ E(Y_t) = \frac{7.5 + 6.0 + 8.0 + 5.5 + 7.0 + 6.0}{6} = \frac{40}{6} \approx 6.67 \text{ hours} \]
\[ E(Y_c) = \frac{7.0 + 6.0 + 7.0 + 6.0 + 6.0 + 5.0}{6} = \frac{37}{6} \approx 6.17 \text{ hours} \]
\(E(Y_t) - E(Y_c) = 0.5\) hours, which is exactly the ATE. The average of the differences is the same as the difference of the averages:
\[ \mbox{ATE} = E(Y_t - Y_c) = E(Y_t) - E(Y_c) \]
Q4 The ATE is positive. Does that mean the app helps everyone? Who would you warn?
Show answer
No. A positive ATE means the app helps on average, not that it helps every single person. Priya would sleep less with the app. A population-level causal claim can be true while not applying to some individuals (like a medicine that helps most people, except those who are allergic to it).
Q5 In real life, people choose for themselves whether to use the app. Suppose Kai, Omar, and Rosa, who already sleep pretty well, are the ones who download it. Fill in the data that we would actually observe: for each person, write \(D\) and the observed outcome \(Y\).
Show answer
The treated (\(D = 1\)) show us \(Y_t\), the controls (\(D = 0\)) show us \(Y_c\), and the other potential outcome is hidden:
| Name | \(D\) | \(Y\) (hours) |
|---|---|---|
| Kai | 1 | 7.5 |
| Lena | 0 | 6.0 |
| Omar | 1 | 8.0 |
| Priya | 0 | 6.0 |
| Rosa | 1 | 7.0 |
| Theo | 0 | 5.0 |
Q6 Using only the observed data from Q5, compute the average outcome of the treated minus the average outcome of the controls. Compare it with the true ATE. What went wrong?
Show answer
\[ E(Y \mid D = 1) - E(Y \mid D = 0) = \frac{7.5 + 8.0 + 7.0}{3} - \frac{6.0 + 6.0 + 5.0}{3} = 7.5 - 5.67 \approx 1.83 \text{ hours} \]
That’s more than three times the true ATE of 0.5 hours. The people who chose the app are people who already sleep well without it (their \(Y_c\) values are 7.0, 7.0, 6.0, against 6.0, 6.0, 5.0 for the others). So part of the difference between the two groups has nothing to do with the app: the groups were different to begin with. This is self-selection bias, an example of confounding.
Q7 Find a different way of splitting the 6 people into 3 treated and 3 controls, such that the difference in averages would suggest that the app makes people sleep less.
Show answer
Put the people who sleep worst in the treatment group: for example, Lena, Priya, and Theo use the app, and Kai, Omar, and Rosa don’t. Then:
\[ \frac{6.0 + 5.5 + 6.0}{3} - \frac{7.0 + 7.0 + 6.0}{3} \approx 5.83 - 6.67 \approx -0.83 \text{ hours} \]
The same app, with the same true ATE of +0.5 hours, now looks harmful. Depending on who ends up in treatment, the difference in averages can be too big, too small, or even have the wrong sign.
Q8 How could the company make sure that who uses the app is unrelated to how well people sleep?
Show answer
Run a randomized experiment: instead of letting people choose, flip a coin for each person to decide who gets the app. Then, on average, the treated and the controls have the same potential outcomes, and the difference in averages is an unbiased estimate of the ATE.
No data and no code. For each question, answer in a sentence or two.
A professor wants to know whether 10 minutes of guided meditation right before an exam improves students’ exam scores. She teaches a large class, and is willing to run an experiment.
Q1 Identify the treatment variable \(D\) and the outcome variable \(Y\), with their units of measurement.
Show answer
- \(D\) = whether the student does the 10-minute guided meditation before the exam (1) or not (0). No units: it’s a category.
- \(Y\) = the student’s exam score, in percentage points (or points out of the exam’s total).
Q2 What should the control group do during those 10 minutes? Compare two options: (a) nothing special, they just arrive and start the exam, (b) they sit quietly for 10 minutes listening to a neutral podcast. How does the choice change the question being answered?
Show answer
- With (a), we compare “meditation” with “no break at all”. If the treated do better, it could be the meditation, or it could just be 10 minutes of sitting calmly before the exam.
- With (b), both groups get 10 quiet minutes, and the only difference is the meditation itself. This answers a sharper question: “is meditation better than just taking a calm break?”
Neither is wrong, but they answer different causal questions. The control protocol should match the real-life alternative we care about.
Q3 A colleague suggests letting students choose whether to meditate. Why is this a bad idea?
Show answer
Students would self-select. For example, very anxious students might be more likely to choose meditation, and anxious students might also tend to score differently on exams regardless of meditation. Then the two groups would be different to begin with, and the difference in average scores would mix the effect of meditation with the effect of those pre-existing differences (confounding).
Q4 Another colleague suggests assigning the morning section to meditation and the afternoon section to the control. Why is this also a bad idea?
Show answer
The two sections may differ in many ways besides meditation: different students (early risers vs. late risers), different times of day, maybe different TAs or rooms. Any of those differences could affect exam scores, so we couldn’t tell whether a difference in scores came from the meditation or from the section.
Q5 Describe a procedure to assign students to treatment and control that solves the problems of Q3 and Q4.
Show answer
Random assignment: for each student, flip a coin (or draw a random number). Heads, meditation; tails, control. This is done independently of everything about the student, so, on average, the two groups have the same mix of anxious and calm students, early and late risers, strong and weak students, and so on, for every characteristic, measured or not.
Q6 Can this experiment be blinded? Who could be kept unaware of the assignment?
Show answer
The students can’t really be blinded: you know whether you’re meditating or listening to a podcast. But the graders can easily be kept unaware of who meditated, so that their grading can’t be influenced (even unintentionally) by the assignment. That makes it a single-blind design (blind graders), not a double-blind one.
Q7 For each variable, say whether it is a valid covariate for this experiment, and why: (a) the student’s GPA at the start of the semester, (b) the student’s major, (c) how anxious the student feels right before the exam starts (measured after the 10 minutes), (d) the exam score.
Show answer
- (a) Valid. It was determined before the treatment was assigned, so the meditation can’t have affected it.
- (b) Valid. Also determined before the treatment.
- (c) Not valid. It is measured after the meditation, so the meditation may have changed it (that’s probably the whole point of meditating!). It’s really another outcome variable.
- (d) Not valid. It’s the outcome variable itself.
Q8 The professor runs the experiment only on the 20 students who volunteered after class. What problem could this create, even if the assignment among the volunteers is random?
Show answer
Two problems. First, volunteers may not be representative of all students (maybe they are more interested in meditation, or more motivated), so the ATE we estimate is the ATE among volunteers, which may differ from the ATE in the whole class. Second, 20 students is a small sample: randomization only balances things on average, and with so few students the two groups can easily end up different just by bad luck, so the estimate will be very imprecise.
This whole case study is meant for pen and paper. You can use a calculator, but no code.
The meditation experiment was run on 8 students, assigned at random. Here are the data. \(D\) = 1 if the student meditated, GPA is the GPA at the start of the semester, first_year = 1 if the student is in their first year, and \(Y\) is the exam score in percentage points.
| Name | \(D\) | GPA |
first_year |
\(Y\) (%) |
|---|---|---|---|---|
| Ana | 1 | 3.0 | 1 | 78 |
| Ben | 1 | 3.4 | 0 | 85 |
| Cleo | 1 | 3.6 | 0 | 90 |
| Dev | 1 | 3.2 | 1 | 80 |
| Eli | 0 | 3.1 | 0 | 74 |
| Fay | 0 | 3.5 | 0 | 84 |
| Gus | 0 | 2.9 | 0 | 70 |
| Hana | 0 | 3.3 | 1 | 79 |
Q1 Estimate the ATE of meditation on the exam score, with units. Why is it reasonable to use the difference in sample means here?
Show answer
\[ \widehat{\mbox{ATE}} = \bar{Y}_{D=1} - \bar{Y}_{D=0} = \frac{78 + 85 + 90 + 80}{4} - \frac{74 + 84 + 70 + 79}{4} = 83.25 - 76.75 = 6.5 \text{ percentage points} \]
It’s reasonable because the treatment was randomly assigned: in a randomized experiment, the difference in sample means is an unbiased estimator of the ATE. (With only 8 students, though, it is a very imprecise one.)
Q2 Compute the standardized mean difference (SMD) of GPA between the treated and the controls.
Use the definition from the notes: \(\mbox{SMD}(X) = \dfrac{\bar{X}_{D=1} - \bar{X}_{D=0}}{\sqrt{\frac{1}{2}s_{X,D=1}^2 + \frac{1}{2}s_{X, D=0}^2}}\), where the sample variances \(s^2\) divide by \(n - 1\).
Show answer
Means. Treated: \(\frac{3.0 + 3.4 + 3.6 + 3.2}{4} = 3.3\). Controls: \(\frac{3.1 + 3.5 + 2.9 + 3.3}{4} = 3.2\). Difference: \(3.3 - 3.2 = 0.1\).
Variances. Treated: the deviations from 3.3 are −0.3, 0.1, 0.3, −0.1, whose squares add up to 0.09 + 0.01 + 0.09 + 0.01 = 0.2, so \(s^2_{D=1} = \frac{0.2}{3} \approx 0.0667\). Controls: the deviations from 3.2 are −0.1, 0.3, −0.3, 0.1, with the same sum of squares 0.2, so \(s^2_{D=0} \approx 0.0667\).
Pooled standard deviation. \(\sqrt{\frac{1}{2} \cdot 0.0667 + \frac{1}{2} \cdot 0.0667} = \sqrt{0.0667} \approx 0.258\).
\[ \mbox{SMD}(\texttt{GPA}) = \frac{0.1}{0.258} \approx 0.39 \]
Q3 Compute the SMD of first_year (treat it as a 0/1 numerical variable).
Show answer
Means. Treated: \(\frac{1 + 0 + 0 + 1}{4} = 0.5\). Controls: \(\frac{0 + 0 + 0 + 1}{4} = 0.25\). Difference: \(0.25\).
Variances. Treated: deviations ±0.5, squares 0.25 each, sum 1, so \(s^2_{D=1} = \frac{1}{3} \approx 0.333\). Controls: deviations −0.25, −0.25, −0.25, 0.75, squares 0.0625 × 3 + 0.5625 = 0.75, so \(s^2_{D=0} = \frac{0.75}{3} = 0.25\).
Pooled standard deviation. \(\sqrt{\frac{1}{2} \cdot 0.333 + \frac{1}{2} \cdot 0.25} = \sqrt{0.292} \approx 0.54\).
\[ \mbox{SMD}(\texttt{first\_year}) = \frac{0.25}{0.54} \approx 0.46 \]
Q4 What are the units of measurement of the SMD? Why is that useful?
Show answer
The SMD has no units: it’s a difference in means (in the units of \(X\)) divided by a standard deviation (also in the units of \(X\)). That’s what lets us compare the imbalance of very different covariates on the same scale: a GPA difference and a difference in the proportion of first-year students, for example.
Q5 Sketch, on paper, a Love plot for these two covariates. Which covariate is more imbalanced?
Show answer
A Love plot has one row per covariate, and a dot at its SMD on a common horizontal axis, with a vertical line at 0 (perfect balance):

first_year is slightly more imbalanced (0.46 against 0.39). Both dots are to the right of 0, meaning the treated have a slightly higher GPA and slightly more first-year students than the controls.
Q6 The assignment was random, but the covariates are not perfectly balanced. Should we be worried that the randomization went wrong?
Show answer
Not necessarily. Randomization balances covariates on average, over many possible random assignments. In any single experiment, especially one with only 8 students, some imbalance is expected just by chance. To judge whether the imbalance is bigger than chance would produce, we could run a covariate balance test (next question).
Q7 Write down the null hypothesis and the test statistic of a covariate balance test for GPA. Do you hope to reject the null hypothesis?
Show answer
\[ H_0: \texttt{GPA} \mbox{ is independent of } D \qquad T = \bar{X}_{D=1} - \bar{X}_{D=0} \]
where \(X\) is GPA. Here the observed value is \(T = 0.1\). We hope not to reject \(H_0\): in a well-run randomized experiment, the covariates should be independent of the treatment, and failing to reject is consistent with that.
Q8 Suppose that, instead of flipping coins, the professor had accidentally sorted the students by GPA and assigned the top 4 to meditation. What would the SMD of GPA look like? How would that affect the estimate of the ATE?
Show answer
The treated would be the four students with the highest GPAs and the controls the four with the lowest, so the difference in mean GPA would be large and the SMD would be very large (far from 0). That’s exactly the kind of mistake a balance check is meant to catch.
It would also ruin the estimate of the ATE: students with higher GPAs probably score higher on the exam anyway, so the difference in average scores would mix the effect of meditation with the effect of GPA. GPA would be a confounder.
No data and no code. For each question, answer in a sentence or two.
Q1 For each observed association, name a plausible confounder and explain how it is associated with both the treatment and the outcome.
(a) Cities with more ice cream sales have more drownings. (b) Fires attended by more firefighters cause more damage. (c) Among elementary school children, those with bigger shoe sizes read better.
Show answer
- (a) Temperature (or season). On hot days people buy more ice cream (\(D\)) and more people go swimming, so there are more drownings (\(Y\)).
- (b) The size of the fire. Bigger fires get more firefighters (\(D\)) and cause more damage (\(Y\)).
- (c) Age. Older children have bigger feet (\(D\)) and read better (\(Y\)).
In each case, the treatment and the outcome are associated, but there’s no reason to think that changing the treatment alone (eating ice cream, sending firefighters, buying bigger shoes) would change the outcome.
Q2 Why can’t we just run randomized experiments for every causal question? Give one example of a question where an experiment would be unethical, and one where it would be impossible.
Show answer
Experiments can be unethical, infeasible, or too expensive. For example:
- Unethical: does smoking cause lung cancer? We can’t randomly assign people to smoke for 20 years.
- Impossible: does being the first-born child affect your income? We can’t randomly assign birth order.
For questions like these we have to rely on observational studies, where the researchers don’t control who gets the treatment.
Q3 In an observational study, we measured several covariates and argued that they include all the confounders. Can we use the data to prove that we haven’t missed any confounder?
Show answer
No. A confounder that we didn’t measure leaves no trace in our data, so no analysis of the data can show that it doesn’t exist. “We observed all the confounders” is a non-empirical claim: we have to argue for it using what we know about how the treatment was assigned, and other people have to be convinced by the argument.
Q4 When matching, why must we never match on a variable measured after the treatment, like a midterm score for a tutoring program that started at the beginning of the semester?
Show answer
A variable measured after the treatment may have been changed by the treatment: the tutoring may have raised the midterm score. If we match tutored and untutored students with the same midterm score, we’re comparing students whom the tutoring had already helped with students who reached that score without help, and we hide part of the very effect we’re trying to measure. Only variables determined before the treatment (valid covariates) should be used.
Q5 Explain in your own words why grouping by a confounder \(X\) “solves” confounding, if \(X\) is the only confounder.
Show answer
Confounding happens because \(X\) is tied to both the treatment and the potential outcomes, so the treated and the controls are different kinds of people. If we only compare people with the same value of \(X\), that source of difference is gone: inside each \(X\)-group, who got the treatment is unrelated to the potential outcomes, just like in a small randomized experiment. Then we can compare treated and controls within each group, and average those comparisons.
Q6 “Correlation does not imply causation.” When can a difference in group averages be interpreted causally?
Show answer
When the treatment was randomly assigned (a randomized experiment), the difference in sample means is an unbiased estimate of the ATE. Without randomization, we need extra work: identifying and measuring the confounders and comparing similar individuals (for example by matching), plus a convincing argument that no important confounder was left out.
This whole case study is meant for pen and paper. You can use a calculator, but no code.
A college offers a free tutoring program, and students choose whether to join it. This is an observational study. \(D\) = 1 if the student joined the tutoring program, \(Y\) is the final exam score in percentage points, and \(X\) is the student’s level before the course: “high” or “low”, based on previous grades.
Part A: exact matching
Here is a sample of 8 students:
| Name | \(X\) | \(D\) | \(Y\) (%) |
|---|---|---|---|
| Ivy | high | 1 | 90 |
| Jon | high | 1 | 85 |
| Kim | high | 1 | 88 |
| Leo | high | 0 | 84 |
| Mia | low | 1 | 70 |
| Nia | low | 0 | 60 |
| Oto | low | 0 | 62 |
| Pam | low | 0 | 58 |
Q1 Compute the naive estimate of the ATE, \(\bar{Y}_{D=1} - \bar{Y}_{D=0}\).
Show answer
\[ \bar{Y}_{D=1} - \bar{Y}_{D=0} = \frac{90 + 85 + 88 + 70}{4} - \frac{84 + 60 + 62 + 58}{4} = 83.25 - 66 = 17.25 \text{ percentage points} \]
Q2 Is \(X\) a confounder? Use the data to justify your answer.
Show answer
Yes, it looks like one, because it is associated with both the treatment and the outcome:
- With the treatment: 3 of the 4 “high” students joined the program, but only 1 of the 4 “low” students did.
- With the outcome: “high” students score much higher (84 to 90) than “low” students (58 to 70), whether they were tutored or not.
So the tutored group is mostly made of students who would score high anyway, which inflates the naive estimate.
Q3 Use exact matching on \(X\) to predict the missing potential outcome of each student. Then estimate the ATE.
Show answer
For each student, the missing potential outcome is the average outcome of the students with the same \(X\) and the opposite treatment:
| Name | \(X\) | \(D\) | \(\hat{Y}_t\) | \(\hat{Y}_c\) | \(\hat{Y}_t - \hat{Y}_c\) |
|---|---|---|---|---|---|
| Ivy | high | 1 | 90 | 84 (Leo) | 6 |
| Jon | high | 1 | 85 | 84 (Leo) | 1 |
| Kim | high | 1 | 88 | 84 (Leo) | 4 |
| Leo | high | 0 | \(\frac{90 + 85 + 88}{3} \approx 87.67\) | 84 | 3.67 |
| Mia | low | 1 | 70 | \(\frac{60 + 62 + 58}{3} = 60\) | 10 |
| Nia | low | 0 | 70 (Mia) | 60 | 10 |
| Oto | low | 0 | 70 (Mia) | 62 | 8 |
| Pam | low | 0 | 70 (Mia) | 58 | 12 |
\[ \widehat{\mbox{ATE}} = \frac{6 + 1 + 4 + 3.67 + 10 + 10 + 8 + 12}{8} = \frac{54.67}{8} \approx 6.83 \text{ percentage points} \]
Q4 Compare the two estimates. Which one do you trust more, and why?
Show answer
The naive estimate (17.25) is much larger than the matching estimate (6.83). The naive estimate compares a mostly “high” tutored group with a mostly “low” untutored group, so much of the difference comes from \(X\), not from the tutoring. Matching only compares students with the same \(X\), so it removes that confounding. We trust the matching estimate more, provided that \(X\) is the only confounder.
Q5 Name a plausible confounder that is not in the data. What would that mean for the matching estimate?
Show answer
For example, motivation: more motivated students may be more likely to join the program and to study more on their own, so they would score higher even without tutoring. Other examples: free time (students who work long hours may skip tutoring and also have less time to study), or how much they like the subject.
If such a confounder exists and we didn’t measure it, students with the same \(X\) can still differ in ways that affect both \(D\) and \(Y\), and the matching estimate can still be biased.
Part B: nearest-neighbor matching
Now consider a different, smaller sample, where the covariate is the student’s GPA before the course (a numerical variable):
| Name | GPA (\(X\)) | \(D\) | \(Y\) (%) |
|---|---|---|---|
| Quinn | 3.8 | 1 | 88 |
| Raj | 3.1 | 1 | 75 |
| Sam | 3.6 | 0 | 82 |
| Tara | 2.9 | 0 | 68 |
| Uma | 3.4 | 0 | 74 |
Q6 Why can’t we use exact matching here?
Show answer
Every student has a different GPA, so no student has an exact match (same \(X\), opposite \(D\)). With a numerical covariate, exact matches are very rare, so we look for the closest student instead.
Q7 There is only one covariate. Does it matter whether we scale it (divide it by its standard deviation) before computing distances?
Show answer
No. With a single covariate, dividing every value by the same number divides every distance by that same number, so the ranking of the distances doesn’t change, and neither does the nearest neighbor. Scaling only matters when we combine two or more covariates measured in different units (see Part C).
Q8 Use nearest-neighbor matching (one neighbor, matches can be reused) to predict each student’s missing potential outcome, and estimate the ATE. Then compare with the naive estimate.
Show answer
For each student, find the student in the opposite group with the closest GPA:
| Name | \(D\) | Nearest neighbor (GPA distance) | \(\hat{Y}_t\) | \(\hat{Y}_c\) | \(\hat{Y}_t - \hat{Y}_c\) |
|---|---|---|---|---|---|
| Quinn | 1 | Sam (0.2) | 88 | 82 | 6 |
| Raj | 1 | Tara (0.2) | 75 | 68 | 7 |
| Sam | 0 | Quinn (0.2) | 88 | 82 | 6 |
| Tara | 0 | Raj (0.2) | 75 | 68 | 7 |
| Uma | 0 | Raj (0.3) | 75 | 74 | 1 |
(For Raj, the distances to the controls are 0.5 to Sam, 0.2 to Tara, 0.3 to Uma. For Uma, the distances to the treated are 0.4 to Quinn and 0.3 to Raj.)
\[ \widehat{\mbox{ATE}} = \frac{6 + 7 + 6 + 7 + 1}{5} = \frac{27}{5} = 5.4 \text{ percentage points} \]
The naive estimate is \(\frac{88 + 75}{2} - \frac{82 + 68 + 74}{3} = 81.5 - 74.67 \approx 6.83\) percentage points. Notice that Raj is the nearest neighbor of both Tara and Uma, so his outcome is used twice: matches can be reused.
Part C: distances with two covariates
Now each student has two covariates: GPA (covariate 1, in GPA points) and hours of paid work per week (covariate 2, in hours). As in the notes, \(X_{ik}\) is the value of covariate \(k\) for observation \(i\): the first index is the observation number, the second is the covariate number. Suppose we already computed the standard deviations \(s(X_1) = 0.4\) GPA points and \(s(X_2) = 8\) hours.
| Observation \(i\) | GPA (\(X_{i1}\), GPA points) | Hours of work (\(X_{i2}\), hours) |
|---|---|---|
| 1 | 3.6 | 10 |
| 2 | 2.8 | 12 |
| 3 | 3.5 | 20 |
For example, \(X_{21} = 2.8\) GPA points is the GPA of observation 2, and \(X_{32} = 20\) hours is the hours of work of observation 3.
Q9 Without scaling, try to compute the Euclidean distances \(d_{12}\) (between observations 1 and 2) and \(d_{13}\) (between observations 1 and 3). What goes wrong with the units of measurement? Which observation is closer to observation 1?
Show answer
The Euclidean distance would be
\[ d_{12} = \sqrt{(X_{11} - X_{21})^2 + (X_{12} - X_{22})^2} = \sqrt{(0.8 \text{ GPA points})^2 + (-2 \text{ hours})^2} \]
and here we’re stuck: the first term is in (GPA points)² and the second in hours², and we can’t add GPA points² to hours², just like we can’t add kilograms to meters. Without scaling, the Euclidean distance doesn’t make sense.
Let’s still move ahead, just to see what happens. One way to get rid of the units is to divide each covariate by one unit of its own measurement (1 GPA point and 1 hour), which amounts to just using the bare numbers:
\[ d_{12} = \sqrt{(3.6 - 2.8)^2 + (10 - 12)^2} = \sqrt{0.64 + 4} \approx 2.15 \qquad d_{13} = \sqrt{(3.6 - 3.5)^2 + (10 - 20)^2} = \sqrt{0.01 + 100} \approx 10.0 \]
With this choice, observation 2 looks much closer to observation 1. But the choice of “one unit” is arbitrary: if hours were measured in minutes, the second term would be 3600 times bigger, and the answer could change completely.
Q10 Now compute the scaled Euclidean distances \(d_{12}\) and \(d_{13}\), dividing each covariate by its standard deviation first. Which observation is closer to observation 1 now? Why did the answer change?
Show answer
The scaled covariates are \(Z_{i1} = X_{i1} / 0.4\) and \(Z_{i2} = X_{i2} / 8\). Since each covariate is divided by its standard deviation, which has the same units, the \(Z\)s have no units, and now we can add them up:
| Observation \(i\) | \(Z_{i1}\) | \(Z_{i2}\) |
|---|---|---|
| 1 | 9 | 1.25 |
| 2 | 7 | 1.5 |
| 3 | 8.75 | 2.5 |
\[ d_{12} = \sqrt{(Z_{11} - Z_{21})^2 + (Z_{12} - Z_{22})^2} = \sqrt{(9 - 7)^2 + (1.25 - 1.5)^2} = \sqrt{4 + 0.0625} \approx 2.02 \]
\[ d_{13} = \sqrt{(Z_{11} - Z_{31})^2 + (Z_{12} - Z_{32})^2} = \sqrt{(9 - 8.75)^2 + (1.25 - 2.5)^2} = \sqrt{0.0625 + 1.5625} \approx 1.27 \]
Now observation 3 is closer. With the “one unit” choice of Q9, the hours of work dominate the distance just because they are measured in larger numbers: a difference of 10 hours “counts” far more than a difference of 0.8 GPA points. But 0.8 GPA points is a big difference (two standard deviations), while 10 hours is only a bit more than one standard deviation. Scaling puts both covariates on the same footing, in units of standard deviations.
No data and no code. For each question, answer in a sentence or two.
Knowable and unknowable
Q1 For each quantity, say whether it is (i) a population parameter we can never know, (ii) a population parameter that we could know if we had the whole population, or (iii) a statistic we can compute from a sample: \(E(Y_t)\), \(E(Y \mid D = 1)\), \(\bar{Y}_{D=1}\), \(\mbox{ATE}\), \(\bar{Y}_{D=1} - \bar{Y}_{D=0}\).
Show answer
- \(E(Y_t)\): (i). Even with the whole population, we never see \(Y_t\) for the people who didn’t take the treatment (“twice unknowable”).
- \(E(Y \mid D = 1)\): (ii). It’s the average observed outcome of the treated in the population: we’d know it if we had the whole population (“once unknowable”).
- \(\bar{Y}_{D=1}\): (iii). It’s computed from the treated in our sample.
- \(\mbox{ATE} = E(Y_t - Y_c)\): (i), for the same reason as \(E(Y_t)\).
- \(\bar{Y}_{D=1} - \bar{Y}_{D=0}\): (iii). It’s computed from the sample.
Q2 What are the units of measurement of the ATE?
Show answer
The same as the units of \(Y\), since it’s an average of differences of values of \(Y\): hours for the sleep app, percentage points for exam scores, dollars for salaries.
Q3 A study finds that the ATE of a new medicine is exactly 0. Does that mean the medicine has no effect on anyone?
Show answer
No. The ATE is an average: the medicine could help some people and harm others by the same amount, so that the effects cancel out on average. An ATE of 0 says nothing about individual effects.
Randomized experiments
Q4 An experiment randomly assigns 4 people to treatment and 4 to control. Is the difference in sample means a good estimator of the ATE?
Show answer
It is unbiased, because the assignment is random. But with only 8 people it is very imprecise: by bad luck, the two groups can easily end up quite different, so the estimate can be far from the true ATE. A confidence interval would be very wide.
Q5 A randomized experiment with 2000 participants finds an SMD of 0.8 for age between treatment and control. What would you suspect?
Show answer
With 2000 participants, random assignment should produce SMDs very close to 0, so a value of 0.8 is very unlikely to happen by chance. I would suspect that the randomization went wrong: for example, the assignment was accidentally based on something related to age (like signup order, or the spreadsheet being sorted).
Q6 In a randomized experiment, a researcher runs a balance test for each of 20 covariates. One of them has a p-value of 0.03. Should she conclude the randomization failed?
Show answer
Not necessarily. Even if the randomization worked perfectly, each test has a 5% chance of giving a p-value below 0.05. With 20 tests, we would expect about \(20 \times 0.05 = 1\) of them to do so, just by chance. One small p-value out of 20 is not, by itself, strong evidence of a problem.
Q7 In a randomized experiment, why do we bother measuring covariates at all, if randomization already takes care of confounding?
Show answer
As a sanity check: by checking covariate balance (with SMDs, a Love plot, or balance tests), we can catch mistakes in how the randomization was carried out. If the covariates are badly imbalanced, something probably went wrong.
Observational studies
Q8 Two researchers study the same observational data. One matches on 3 covariates, the other on 10. They get very different estimates of the ATE. What could explain this?
Show answer
Some of the 7 extra covariates may be confounders that the first researcher left out, so the first estimate is still confounded. (It’s also possible that some of the extra variables are not valid covariates, for example if they were measured after the treatment, which would bias the second estimate.) The data alone can’t settle which researcher is right: they have to argue about which variables are confounders and when they were measured.
Q9 Why is a well-run randomized experiment usually more convincing than an observational study with matching?
Show answer
Randomization balances all covariates on average, the ones we measured and the ones we didn’t. Matching can only balance the covariates we measured, and we can never prove that we measured all the confounders. An observational study always relies on that extra, non-empirical assumption.
Q10 Calculate, estimate, or predict? For each task, choose the right verb. (a) The ATE of a policy, given a table with both potential outcomes for every person in the population. (b) The ATE of a policy, from a randomized experiment on a sample. (c) The exam score of a student who hasn’t taken the exam yet.
Show answer
- (a) Calculate: we have the whole population and both potential outcomes, so the ATE is just a computation.
- (b) Estimate: the ATE is an unknown population parameter, and we only have a sample.
- (c) Predict: the score is an observable value that we haven’t seen yet.
This is the same data as in “Covariate balance by hand”, stored in a dataframe called students, with columns name, D, GPA, first_year, and Y. Use code to check your pen-and-paper answers.
All libraries and datasets have already been loaded for you.
Q1 Write a pipeline that computes the average exam score Y of the treated and of the controls. Use it to compute the estimate of the ATE.
Show answer
students |>
group_by(D) |>
summarize(mean_Y = mean(Y))# A tibble: 2 × 2
D mean_Y
<dbl> <dbl>
1 0 76.8
2 1 83.2
\(\widehat{\mbox{ATE}} = 83.25 - 76.75 = 6.5\) percentage points, as in the pen-and-paper exercise.
Q2 Visualize the exam scores of the two groups.
Hint: ggplot(students, aes(x = factor(D), y = Y)) + geom_jitter(width = 0.1, height = 0) puts the treated and the controls side by side.
Show answer
ggplot(students, aes(x = factor(D), y = Y)) +
geom_jitter(width = 0.1, height = 0) +
labs(x = "D (1 = meditated)", y = "Y (exam score, %)")
Q3 Write a pipeline that computes the mean and the variance of GPA and of first_year in each group. Use the output to compute the two SMDs with a calculator, and check them against your pen-and-paper answers.
Show answer
students |>
group_by(D) |>
summarize(
mean_GPA = mean(GPA),
var_GPA = var(GPA),
mean_first_year = mean(first_year),
var_first_year = var(first_year)
)# A tibble: 2 × 5
D mean_GPA var_GPA mean_first_year var_first_year
<dbl> <dbl> <dbl> <dbl> <dbl>
1 0 3.2 0.0667 0.25 0.25
2 1 3.3 0.0667 0.5 0.333
Plugging these numbers into the SMD formula gives about 0.39 for GPA and 0.46 for first_year, as in the pen-and-paper exercise.