From a Difference-in-Differences Contrast to a Regression
A two-by-two difference-in-differences design compares the outcome change over time in a treated group with the outcome change over the same periods in a comparison group. The regression representation expresses this same contrast as one coefficient: the coefficient on the interaction between group membership and the post-treatment period. Seeing the algebra makes clear both what the coefficient measures and what it does not establish by itself.
Consider two groups, indexed by \(g\in\{0,1\}\), and two periods, indexed by \(p\in\{0,1\}\). Let \(g=1\) denote the group exposed to treatment in the post period, and let \(p=1\) denote the post-treatment period. Let \(Y_i\) be the outcome for observation \(i\), \(G_i\) indicate membership in the treated group, and \(P_i\) indicate the post period. The four group-period cells are control-pre, control-post, treated-pre, and treated-post.
“Saturated” means the regression has enough parameters to represent an unrestricted mean for each of the four cells. It does not impose that the treated group and control group have equal outcomes before treatment, or that their time trends are equal. Those are separate questions: in particular, parallel trends is a condition for a causal interpretation, not a restriction built into this regression.
Why the Interaction Is the Difference-in-Differences
Write \(\bar Y_{gp}\) for the sample mean outcome in group \(g\) and period \(p\). The regression’s fitted value for each cell follows by substituting that cell’s indicator values. The intercept is the control-pre fitted mean. The group coefficient is the treated-control difference in the pre period. The period coefficient is the post-pre change for the control group. The interaction adjusts the treated group’s post-period fitted mean beyond the sum of those three components.
In a saturated model, the fitted mean for each cell equals that cell’s observed sample mean. Solving the four equations therefore gives the interaction as the treated group’s change minus the control group’s change.
The first parenthesis is the treated group’s post-minus-pre change; the second is the control group’s post-minus-pre change. Thus the coefficient is exactly the two-by-two difference-in-differences estimate, with the sign determined by the coding just specified. Changing which group or period is coded as one can change the coefficient’s expression or sign, so the indicator definitions should always be stated.
Worked Regression With Unequal Cell Sizes
Worked Example: Reading All Four Coefficients
Suppose a hypothetical program evaluation records an outcome in units of points. The group-period cell means are: control-pre, 50; control-post, 54; treated-pre, 48; and treated-post, 59. The four cells contain 20, 15, 12, and 18 observations, respectively. These unequal cell sizes do not alter the saturated regression’s point-estimate identity.
The difference-in-differences estimate is $$ (59-48)-(54-50)=11-4=7\text{ points}. $$
The regression coefficients implied by the cell means are \(\hat\beta_0=50\), \(\hat\beta_1=48-50=-2\), \(\hat\beta_2=54-50=4\), and $$ \hat\beta_3=59-48-54+50=7. $$
Substitution checks the fitted values: control-pre is \(50\); treated-pre is \(50-2=48\); control-post is \(50+4=54\); and treated-post is \(50-2+4+7=59\). The interaction coefficient is therefore the treated group’s 11-point increase minus the control group’s 4-point increase, or 7 points.
The \(-2\) group coefficient describes the pre-period treated-control difference; the 4-point period coefficient describes the control group’s change. Neither coefficient alone is the difference-in-differences estimate. That contrast is the interaction.
Why Individual-Level OLS Produces the Cell Means
The result does not depend on each cell having the same number of observations. To see why, note that every observation in a given cell has the same fitted value under the model. For fixed fitted values, the sum of squared residuals in that cell is minimized when the fitted value equals the cell’s sample mean. Because the saturated model can choose each of the four fitted values independently, OLS sets each one to its corresponding sample mean.
where \(n_{gp}\) is the number of observations in cell \((g,p)\), and \(m\) is any proposed fitted value for that cell. The first term on the right does not depend on \(m\); the second is minimized at \(m=\bar Y_{gp}\). Since the four cell means can be represented freely by the four regression coefficients, this argument applies to every cell. The contrast of the fitted means is consequently the contrast of the observed cell means, regardless of unequal cell sizes.
The same point estimate results if the data are reduced to exactly four rows, one containing each cell mean, and the saturated regression is fit to those rows. With four parameters and four cell means, the model fits all four rows exactly. Weighting these rows by cell counts is not necessary to obtain the interaction coefficient: weighted and unweighted OLS both yield the same contrast of the four means. Weights can matter for standard errors or for a model that does not fit all four cell means freely; that is a different question from reproducing this saturated-model point estimate.
Worked Example: Four Cell Means From Unequal Samples
Consider another hypothetical outcome, measured in units of an index. The observations are control-pre \(10,12,14\); control-post \(13,15\); treated-pre \(9,11,13,15\); and treated-post \(17,19,21\). The cell sizes are therefore 3, 2, 4, and 3.
Calculate each mean: $$ \bar Y_{00}=\frac{10+12+14}{3}=12,\quad \bar Y_{01}=\frac{13+15}{2}=14, $$ $$ \bar Y_{10}=\frac{9+11+13+15}{4}=12,\quad \bar Y_{11}=\frac{17+19+21}{3}=19. $$
The control change is \(14-12=2\) index units, and the treated change is \(19-12=7\) index units. Thus $$ \hat\beta_3=(19-12)-(14-12)=7-2=5\text{ index units}. $$
For the four-row cell-mean regression, the coefficients are \(\hat\beta_0=12\), \(\hat\beta_1=12-12=0\), \(\hat\beta_2=14-12=2\), and \(\hat\beta_3=5\). Both weighted and unweighted OLS on these four rows fit the means \(12,12,14,19\) exactly, and hence give the same interaction, 5. The cell sizes differ, but weighting is not needed to recover this point estimate.
When the Interaction Has a Causal Interpretation
The regression identity is descriptive algebra. To interpret \(\hat\beta_3\) as an effect of treatment requires identifying assumptions. For a concise statement, let \(Y_{g,p}(0)\) denote the outcome that group \(g\) would have in period \(p\) without treatment, and let \(Y_{1,1}(1)\) denote the treated group’s post-period outcome under treatment. Treatment is absent in the pre period and in the comparison group, and is received by the treated group in the post period. Assume the observed outcomes correspond to the treatment status actually received, there is no interference between units, and the group-period means represent stable target populations.
The key identifying condition is parallel trends in untreated potential outcomes: without the program, the treated group’s mean outcome would have changed from pre to post by the same amount as the comparison group’s mean outcome. In expectation notation, this is
Under this condition, and the treatment-status and outcome-measurement conditions just stated, the observed treated-group change minus the observed comparison-group change identifies the average treatment effect for the treated group in the post period. The interaction estimates that contrast in the sample. Parallel trends concerns the missing treated-group post outcome without treatment; it cannot be verified merely by fitting the saturated regression.
Worked Example: Interpreting the Interaction Under Parallel Trends
Suppose a hypothetical evaluation measures weekly earnings in dollars. The treated group’s mean is $100 before the program and $114 afterward. The comparison group’s mean is $90 before and $98 afterward. Assume the groups represent the intended target populations, no one is treated before the post period, and the comparison group remains untreated.
The estimated interaction is $$ (114-100)-(98-90)=14-8=6\text{ dollars per week}. $$
Under parallel trends, the comparison group’s $8 increase estimates the change the treated group would have experienced without the program. The treated group’s estimated post-period outcome without treatment is therefore \(100+8=108\) dollars per week. Its observed mean is $114, a difference of \(114-108=6\) dollars per week. Under the stated assumptions, this is an estimate of the average effect for the treated group in the post period.
Without parallel trends, the same regression still reports a 6-dollar difference-in-differences contrast, but the contrast need not equal a treatment effect. For example, a separate shock that raises treated-group earnings by $3 per week relative to the comparison group would be included in the interaction and could not be distinguished from the program effect by this two-by-two regression alone.
Common Mistakes and Practical Checks
- Calling the interaction causal by definition. The coefficient is always the sample difference-in-differences contrast under the stated coding. A causal interpretation additionally requires assumptions such as parallel trends.
- Reversing the contrast. With \(G=1\) for treated and \(P=1\) for post, the interaction is treated change minus control change. Write both changes explicitly before interpreting its sign.
- Reading a main effect as the treatment effect. The group coefficient is the pre-period difference, and the period coefficient is the control-group change. The interaction is the extra treated-group change.
- Assuming unequal cell sizes change the saturated point estimate. They do not change the interaction’s cell-mean contrast. In a regression on one row per cell, weighted and unweighted OLS give the same interaction when the model fits all four cell means freely. Weighting may affect inference or a nonsaturated model, not this point-estimate identity.
- Ignoring an empty cell. The four-cell saturated model requires observations in all four cells to calculate the four sample means and their contrast. If a cell is absent, this setup does not identify the stated sample contrast.
Check Your Understanding
Use the coding \(G=1\) for the treated group and \(P=1\) for the post period.
- If the control mean changes from 30 to 35 and the treated mean changes from 32 to 40, calculate the interaction coefficient and state its units if the outcome is measured in points.
- In the saturated regression, what does \(\beta_1\) represent? What does \(\beta_2\) represent?
- Explain why OLS on four cell means produces the same interaction whether or not those four rows are weighted by cell sizes.
- Does the algebraic identity between the interaction and the cell-mean contrast require parallel trends? What does require parallel trends?
- Suppose the interaction is positive. Give one reason it might fail to represent a positive causal treatment effect.