17  Interaction Terms

When One Variable’s Effect Depends on Another

Interaction Terms
Marginal Effects
Multiple Regression
Author

Jake Anderson

Published

March 21, 2026

Modified

March 26, 2026

Abstract

Without interaction terms, the effect of education on wages is the same for everyone. An interaction term lets the effect of one variable depend on the level of another. This chapter covers dummy-continuous and continuous-continuous interactions, derives marginal effects from each, and explains how to test and visualize interaction effects.

17.1 Motivation: Does the Return to Education Differ by Gender?

A model with an intercept indicator for gender produces two parallel lines: men and women earn different base wages, but each extra year of education adds the same dollar amount for both groups. This may be unrealistic. If the labor market rewards men’s education more steeply than women’s, we need a model that allows different slopes, not just different intercepts.

Parallel lines = no interaction. Different slopes = interaction present. The data tell you which is appropriate; the \(t\)-test on \(\beta_4\) decides.

17.2 Dummy \(\times\) Continuous Interactions

Add an interaction between the indicator and the continuous variable:

Definition 17.1 (Interaction Model (Dummy \(\times\) Continuous)) \[ \text{wage}_i = \beta_1 + \beta_2 \text{educ}_i + \beta_3 \text{female}_i + \beta_4 (\text{female}_i \times \text{educ}_i) + e_i \tag{17.1}\]

For men (\(\text{female} = 0\)): \(E(\text{wage}) = \beta_1 + \beta_2 \text{educ}\). For women (\(\text{female} = 1\)): \(E(\text{wage}) = (\beta_1 + \beta_3) + (\beta_2 + \beta_4) \text{educ}\). Each group now has its own intercept and its own slope.

The coefficient \(\beta_4\) measures how much the return to education differs for women relative to men. \(\beta_2\) is the return to education for the reference group (men) alone, not for the population as a whole.

Coefficient Meaning
\(\beta_1\) Intercept for the reference group (men)
\(\beta_2\) Return to education for men
\(\beta_3\) Intercept shift for women (wage gap at \(\text{educ} = 0\))
\(\beta_4\) Slope shift: how much the return to education differs for women
Quantity Formula
Women’s return to education \(\beta_2 + \beta_4\)
Women’s intercept \(\beta_1 + \beta_3\)
Gender wage gap at education \(e\) \(\beta_3 + \beta_4 \cdot e\)
Are slopes different? Test \(H_0: \beta_4 = 0\)
Are regressions identical? Test \(H_0: \beta_3 = 0\) and \(\beta_4 = 0\) jointly

Do not report \(\beta_2\) as “the effect of education” when an interaction is present; it is the effect for the reference group only. Do not interpret \(\beta_3\) in isolation; it is the gender wage gap at \(\text{educ} = 0\), which is rarely meaningful. And never include an interaction term while dropping one of its constituent terms: if the model has \(\text{female} \times \text{educ}\), it should also include both \(\text{female}\) and \(\text{educ}\) separately.

17.3 Continuous \(\times\) Continuous Interactions

Interactions are not limited to dummy variables. Consider:

\[ \text{wage}_i = \beta_1 + \beta_2 \text{educ}_i + \beta_3 \text{exper}_i + \beta_4 (\text{educ}_i \times \text{exper}_i) + e_i \]

Both marginal effects now vary:

\[ \frac{\partial\, E(\text{wage})}{\partial\, \text{exper}} = \beta_3 + \beta_4 \text{educ} \qquad \frac{\partial\, E(\text{wage})}{\partial\, \text{educ}} = \beta_2 + \beta_4 \text{exper} \]

Complements vs. substitutes: \(\beta_4 > 0\) means education and experience amplify each other (complements). \(\beta_4 < 0\) means they partially substitute.

If \(\beta_4 > 0\), education and experience are complements: more education amplifies the return to experience. If \(\beta_4 < 0\), they are substitutes. Using CPS data, the textbook finds \(\hat{\beta}_4 = -0.003\): workers with more education get a slightly lower return to each additional year of experience.

flowchart LR
    A["No interaction<br/>β₄ = 0"] --> D["Parallel lines<br/>Same slope for all groups"]
    B["Positive interaction<br/>β₄ > 0"] --> E["Lines fan out<br/>Effect amplified"]
    C["Negative interaction<br/>β₄ < 0"] --> F["Lines converge<br/>Effect dampened"]

    style A fill:#888,color:#fff
    style B fill:#2E8B57,color:#fff
    style C fill:#C41E3A,color:#fff
Figure 17.1: Interaction terms determine whether lines are parallel (no interaction), fan out (positive interaction), or converge (negative interaction).

17.4 Computing Marginal Effects

For any interaction model \(y = \beta_1 + \beta_2 x_2 + \beta_3 x_3 + \beta_4 (x_2 \times x_3) + e\), the recipe is:

  1. Take the partial derivative with respect to the variable of interest: \(\partial E(y) / \partial x_2 = \beta_2 + \beta_4 x_3\).
  2. Plug in a specific value of the other variable.
  3. Compute the numerical marginal effect.

Always ask: “The effect of \(x_2\) at what level of \(x_3\)?” Common choices include the sample mean, substantively meaningful values (such as 8 vs. 16 years of education), or the 25th and 75th percentiles.

Interactive: Interaction Visualizer

Toggle the interaction term on or off to see how it changes the regression lines. With no interaction, the lines are parallel (same slope, different intercepts). With an interaction, each group has its own slope. Adjust the interaction coefficient \(\gamma\) to see the lines fan out or converge.

Show code
viewof addInteraction = Inputs.toggle({label: "Add interaction term", value: false})
viewof gamma_interact = Inputs.range([-1.5, 1.5], {value: -0.4, step: 0.05, label: "Interaction coefficient (γ)"})

interaction_plot = {
  const b1 = 5.0, b2 = 1.8, b3 = -3.2;
  const gamma = addInteraction ? gamma_interact : 0;

  // Generate lines for men and women
  const educRange = d3.range(6, 21, 0.5);

  const menLine = educRange.map(e => ({educ: e, wage: b1 + b2 * e, group: "Men"}));
  const womenLine = educRange.map(e => ({
    educ: e,
    wage: (b1 + b3) + (b2 + gamma) * e,
    group: "Women"
  }));

  // Generate some scattered data
  const rng = d3.randomLcg(33);
  const rnorm = d3.randomNormal.source(rng)(0, 3);
  const N = 100;
  const data = Array.from({length: N}, () => {
    const female = rng() > 0.5 ? 1 : 0;
    const educ = 8 + rng() * 12;
    const wage = b1 + b2 * educ + b3 * female + gamma * female * educ + rnorm();
    return {educ, wage, group: female ? "Women" : "Men"};
  });

  const slopeMen = b2;
  const slopeWomen = b2 + gamma;

  return {menLine, womenLine, data, slopeMen, slopeWomen, gamma};
}

Plot.plot({
  width: 650, height: 380,
  marginLeft: 50,
  x: {label: "Education (years)", domain: [6, 21]},
  y: {label: "Wage ($/hr)"},
  color: {domain: ["Men", "Women"], range: ["#1E5A96", "#C41E3A"], legend: true},
  marks: [
    Plot.dot(interaction_plot.data, {x: "educ", y: "wage", fill: "group", r: 2.5, fillOpacity: 0.3}),
    Plot.line(interaction_plot.menLine, {x: "educ", y: "wage", stroke: "#1E5A96", strokeWidth: 2.5}),
    Plot.line(interaction_plot.womenLine, {x: "educ", y: "wage", stroke: "#C41E3A", strokeWidth: 2.5, strokeDasharray: addInteraction ? "" : "6,4"})
  ]
})
Show code
html`<div style="margin-top:0.5em">
  <strong>Men's slope:</strong> ${interaction_plot.slopeMen.toFixed(2)} &nbsp;|&nbsp;
  <strong>Women's slope:</strong> ${interaction_plot.slopeWomen.toFixed(2)} &nbsp;|&nbsp;
  <strong>γ:</strong> ${interaction_plot.gamma.toFixed(2)}
  ${addInteraction ? "" : html`<br/><em>Lines are parallel (no interaction). Toggle to allow different slopes.</em>`}
</div>`
(a)
(b)
(c)
(d)
(e)
Figure 17.2: Interaction visualizer. Without interaction, lines are parallel. With interaction, slopes differ by group. Adjust γ to control the slope difference.

Try setting \(\gamma = 0\) with the interaction toggled on. The lines become parallel again: the interaction coefficient controls the slope difference.

17.5 Plotting and Testing Interactions

To visualize an interaction, fix the “other” variable at representative values and plot predicted outcomes against the variable of interest. Parallel lines indicate no interaction (\(\beta_4 \approx 0\)). Lines that fan out indicate a positive interaction. Lines that converge indicate a negative interaction.

To test whether the interaction is needed, test \(H_0: \beta_4 = 0\) with a standard \(t\)-test: \(t = b_4 / \text{se}(b_4) \sim t_{(N-K)}\). If we reject, the marginal effect of one variable genuinely depends on the other. If we fail to reject, the parallel-lines (or constant-marginal-effect) model may be adequate.

17.6 Comparing Models: Adjusted \(R^2\)

Recall from Chapter 13 that \(R^2\) cannot decrease when a regressor is added, so it cannot tell you whether the interaction term genuinely improves the model. Use the adjusted \(R^2\) instead. It rises only when a new variable reduces \(SSE\) enough to offset the lost degree of freedom. Compare models with and without the interaction using \(\bar{R}^2\); if it rises, the interaction contributes to fit beyond what you would expect from chance.

CautionAdjusted \(R^2\) is one tool, not the only tool

A rising \(\bar{R}^2\) supports including the interaction, but the \(t\)-test on \(\beta_4\) is the formal test. Both should point in the same direction. If theory strongly supports the interaction but \(\bar{R}^2\) barely changes, the effect may be real but small.

17.7 Practice

A researcher estimates \(\text{wage}_i = 5.0 + 1.80\,\text{educ}_i - 3.20\,\text{female}_i - 0.40\,(\text{female}_i \times \text{educ}_i)\). What is the return to education for women? What is the gender wage gap for a worker with 16 years of education?

The return to education for women is \(\beta_2 + \beta_4 = 1.80 + (-0.40) = 1.40\) dollars per hour per year. The gender wage gap at \(\text{educ} = 16\) is \(\beta_3 + \beta_4 \times 16 = -3.20 + (-0.40)(16) = -3.20 - 6.40 = -9.60\). Women with 16 years of education earn $9.60/hour less than comparable men. Notice the gap is not just \(\beta_3 = -3.20\); that number applies only at \(\text{educ} = 0\).

Slides