Tutorials › Causal Inference › The 2-by-2 Regression and the DiD Interaction

Difference-in-Differences · Tutorial 586 of 972

The 2-by-2 Regression and the DiD Interaction

Learn how a saturated two-by-two regression encodes the DiD contrast and when its interaction coefficient can be interpreted causally.

Intermediate 9 min read

What You'll Learn

  • Specify the saturated regression for treated and control groups before and after an intervention.
  • Map each regression coefficient to a group-time cell mean.
  • Derive why the interaction coefficient equals the two-period DiD contrast.
  • Calculate the interaction coefficient from hypothetical outcome data.
  • Distinguish the regression’s algebraic identity from the assumptions needed for causal interpretation.

Introduction

The two-period difference-in-differences (DiD) estimator can be calculated from four group-time averages. The same contrast also appears as a single coefficient in a regression: the coefficient on the interaction between group status and the post-intervention indicator. This is more than a convenient way to calculate DiD. The regression makes clear which part of the model represents the baseline group difference, which part represents the control group’s time change, and which part captures the additional change for the treated group.

The equality between the regression coefficient and the DiD contrast is an algebraic result of a saturated two-by-two model. It does not, by itself, show that the contrast is causal. A causal interpretation still requires the identifying assumptions for DiD, especially parallel trends for the untreated potential outcomes.

The Saturated Two-by-Two Regression

Let \(D_i=1\) for an individual in the treated group and \(D_i=0\) for an individual in the control group. Let \(Post_t=1\) in the post-intervention period and \(Post_t=0\) in the pre-intervention period. For an outcome \(Y_{it}\), consider the linear regression

$$ Y_{it}=\beta_0+\beta_1D_i+\beta_2Post_t+\beta_3(D_i\times Post_t)+\varepsilon_{it}. $$

The product \(D_i\times Post_t\) is one only for observations in the treated group after the intervention. The model includes an intercept, a group indicator, a time indicator, and their interaction. Together, these terms allow a separate fitted mean for each of the four group-time cells.

Definition: In the two-by-two DiD regression, \(\beta_3\) is the coefficient on the product \(D_i\times Post_t\). With observations in all four cells and ordinary least squares, it equals the post-minus-pre change in the treated group minus the post-minus-pre change in the control group. Equivalently, it is the treated-versus-control difference after the intervention minus that difference before it.

To see the role of each coefficient, write the model’s fitted value for each cell. Denote the mean outcome in group \(d\) and period \(t\) by \(\bar{Y}_{d,t}\), where \(d=1\) is the treated group, \(d=0\) is the control group, \(t=1\) is post, and \(t=0\) is pre.

Group and periodFitted meanInterpretation
Control, pre: \(D_i=0,\ Post_t=0\)\(\beta_0\)Control-group pre-period mean
Treated, pre: \(D_i=1,\ Post_t=0\)\(\beta_0+\beta_1\)Treated-group pre-period mean
Control, post: \(D_i=0,\ Post_t=1\)\(\beta_0+\beta_2\)Control-group post-period mean
Treated, post: \(D_i=1,\ Post_t=1\)\(\beta_0+\beta_1+\beta_2+\beta_3\)Treated-group post-period mean

The coefficient \(\beta_1\) is the treated-control difference before the intervention. The coefficient \(\beta_2\) is the pre-to-post change for the control group. The interaction coefficient is what remains in the treated group’s post-period mean after accounting for those terms.

Why the Interaction Equals DiD

Because the model fits the four group-time means, the coefficients can be written directly in terms of those means. For example, \(\beta_0=\bar{Y}_{0,0}\), and \(\beta_1=\bar{Y}_{1,0}-\bar{Y}_{0,0}\). Likewise, \(\beta_2=\bar{Y}_{0,1}-\bar{Y}_{0,0}\). The treated post-period mean must then equal \(\bar{Y}_{1,1}\), so solving for \(\beta_3\) gives:

$$ \begin{aligned} \beta_3 &=\bar{Y}_{1,1}-\beta_0-\beta_1-\beta_2\\ &=\bar{Y}_{1,1}-\bar{Y}_{0,0} -(\bar{Y}_{1,0}-\bar{Y}_{0,0}) -(\bar{Y}_{0,1}-\bar{Y}_{0,0})\\ &=(\bar{Y}_{1,1}-\bar{Y}_{1,0}) -(\bar{Y}_{0,1}-\bar{Y}_{0,0}). \end{aligned} $$

This is the two-period DiD contrast: the treated group’s observed pre-to-post change minus the control group’s observed pre-to-post change. Rearranging the same expression shows the alternative form, the change in the treated-control gap from pre to post:

$$ \beta_3=(\bar{Y}_{1,1}-\bar{Y}_{0,1})-(\bar{Y}_{1,0}-\bar{Y}_{0,0}). $$

This derivation uses the saturated model’s four fitted cell means. To justify that ordinary least squares actually fits those means, note that the four combinations of \(D_i\) and \(Post_t\) correspond to four distinct model predictions. For any one cell, the sum of squared residuals is minimized when its fitted value equals that cell’s sample mean. Since the model can choose each of the four fitted values independently through its four coefficients, its least-squares fitted values are the four cell means. This remains true when cell sample sizes differ, provided all four cells are observed.

Worked Examples

Worked Example: Recovering DiD From the Regression Coefficients

Suppose a hypothetical study records weekly clinic visits per 100 eligible residents. The four observed cell means are 20 visits for the control group before the intervention, 24 for the treated group before, 22 for the control group after, and 30 for the treated group after. Calculate the regression coefficients and the DiD estimate.

The control pre-period mean is the intercept, so \(\beta_0=20\) visits per 100 residents. The treated-control gap before the intervention is \(24-20=4\), so \(\beta_1=4\) visits per 100 residents. The control group’s time change is \(22-20=2\), so \(\beta_2=2\) visits per 100 residents.

The fitted treated post-period mean must be 30. Therefore,

$$ \beta_3=30-20-4-2=4 $$

The direct DiD calculation gives the same result:

$$ (30-24)-(22-20)=6-2=4 $$

The interaction coefficient is 4 additional visits per 100 residents beyond the control group’s observed change. This is a descriptive regression contrast. Its causal interpretation depends on the DiD assumptions, not on the coefficient calculation alone.

Worked Example: Unequal Baseline Levels Are Represented by the Group Term

Consider hypothetical average exam scores. Before an intervention, the treated group averages 68 points and the control group averages 80 points. Afterward, their means are 75 and 83 points, respectively. Find the regression coefficients and explain the interaction.

The control pre-period mean is \(\beta_0=80\) points. The treated group starts 12 points lower, giving \(\beta_1=68-80=-12\) points. The control group rises by 3 points, giving \(\beta_2=83-80=3\) points. To match the treated post-period mean,

$$ \beta_3=75-(80-12+3)=4\text{ points}. $$

Equivalently, the treated group rises by \(75-68=7\) points, while the control group rises by \(83-80=3\) points. Thus the DiD contrast is \(7-3=4\) points. The pre-intervention outcome levels do not have to match for this algebraic identity to hold; the group term represents their initial 12-point difference.

If parallel trends holds for the untreated potential outcomes, and the intervention is the relevant difference between the groups in the post period, the 4-point contrast can be interpreted as an average treatment effect for the treated group in that period. The differing baseline means alone neither establish nor invalidate that causal interpretation.

Worked Example: Interpreting an Interaction for a Binary Outcome

Suppose a hypothetical program tracks whether a patient returns to an emergency department within 30 days. The outcome is coded 1 for a return and 0 otherwise, so each cell mean is a return proportion. The control-group proportions are 0.20 before and 0.18 after; the treated-group proportions are 0.25 before and 0.19 after. Calculate the interaction in a linear regression with group, post, and their interaction.

The control pre-period proportion is \(\beta_0=0.20\). The treated-control difference before is \(\beta_1=0.25-0.20=0.05\), or 5 percentage points. The control-group change is \(\beta_2=0.18-0.20=-0.02\), a decrease of 2 percentage points. The interaction is:

$$ \beta_3=(0.19-0.25)-(0.18-0.20) =-0.06-(-0.02)=-0.04. $$

The estimated DiD contrast is \(-0.04\), or a 4-percentage-point larger decrease in 30-day returns in the treated group than in the control group. This is a difference in proportions because the regression is linear and the outcome is coded 0 or 1. The arithmetic still does not establish a causal effect; the causal conditions must be assessed separately.

From an Algebraic Contrast to a Causal Effect

The regression coefficient always summarizes the specified four observed cell means, subject to the stated data and estimation setup. Causal interpretation requires more. In particular, parallel trends says that, without treatment, the average outcome change for the treated group would have equaled the average outcome change for the control group. Under that assumption, and with treatment applied to the treated group only in the post period, the observed difference in changes identifies the average treatment effect for the treated group in the post period.

The regression representation does not make parallel trends true, nor does it test the assumption simply by producing an interaction estimate. The coefficient is also tied to the outcome scale used in the regression: for an outcome measured in points it is measured in points; for a binary outcome in a linear regression it is a difference in proportions. The scale should be stated when reporting the result.

1
Define the cells and coding.
State which group has \(D_i=1\), which period has \(Post_t=1\), and the outcome’s units.
2
Fit the saturated specification.
Include the intercept, group indicator, post indicator, and their product.
3
Read the interaction as a contrast.
Compute treated change minus control change, or the post-period group gap minus the pre-period group gap.
4
Assess identification separately.
Explain whether parallel trends and the other relevant design conditions support a causal reading.

Common Mistakes

  • Calling the interaction causal by definition. The coefficient equals the observed DiD contrast by algebra. It identifies a causal effect only when the identifying assumptions are credible.
  • Confusing the group coefficient with the treatment effect. With this coding, \(\beta_1\) is the pre-period treated-control difference. The DiD contrast is \(\beta_3\).
  • Omitting the main effects while keeping the interaction. The stated saturated model includes both \(D_i\) and \(Post_t\), as well as their product. Without the main effects, the four cell means are not freely represented and the interaction need not equal the ordinary DiD contrast.
  • Assuming equal baseline means are required. The group coefficient accommodates a baseline difference. DiD does not require the treated and control groups to start at the same outcome level.
  • Reporting a unit-free effect when the outcome has units. State whether the interaction is in points, visits per 100 residents, percentage points, or another outcome unit.
Key takeaway: In a saturated two-by-two regression, the coefficient on \(D_i\times Post_t\) is exactly the two-period DiD contrast. This is an identity between a regression coefficient and four observed cell means; the causal meaning comes from the design assumptions, not from the regression notation.

Check Your Understanding

Use the coefficient mapping and DiD contrast to answer these questions.

  1. With \(D_i=1\) for treated and \(Post_t=1\) for post, what does \(\beta_1\) represent in the saturated regression?
  2. Suppose the treated group changes from 40 to 47 points and the control group changes from 44 to 48 points. Calculate the interaction coefficient and state its units.
  3. Why does the saturated model’s interaction equal the four-cell DiD contrast even when the cell sample sizes differ?
  4. Can a nonzero interaction coefficient alone establish that the intervention caused an outcome change? Explain.
  5. For a binary outcome coded 0 or 1 in a linear regression, what is the unit of the interaction coefficient?
Clinical Biostats