A2.5 Nonlinear interaction effects
- Estimating a nonlinear interactive model in Stata is easy:
regress occprest c.age##c.age##i.woman i.college- The key is to use the “##” operators in Stata along with the appropriate c. or i. prefix. If you do that, Stata takes care of the rest to estimate the appropriate model (see output below)
- Both polynomial terms and product (interaction) terms are just variables multiplied together—so the ## operator works for both
- Note (below) Stata correctly includes coefficients for age, age2, woman, woman*age, and woman*age2
- All five coefficients are necessary to properly estimate the nonlinear interaction effect
use "https://tdmize.github.io/data/data/cda_gss", clear(cda_gss.dta | GSS 1972-2021 CDA - Categorical Data Analysis | date created 202
> 3)
regress occprest c.age##c.age##i.woman i.college Source | SS df MS Number of obs = 58,304
-------------+---------------------------------- F(6, 58297) = 3180.18
Model | 2807908.65 6 467984.775 Prob > F = 0.0000
Residual | 8578800.25 58,297 147.156805 R-squared = 0.2466
-------------+---------------------------------- Adj R-squared = 0.2465
Total | 11386708.9 58,303 195.302281 Root MSE = 12.131
-------------------------------------------------------------------------------
occprest | Coefficient Std. err. t P>|t| [95% conf. interval]
--------------+----------------------------------------------------------------
age | 0.328 0.025 13.187 0.000 0.279 0.377
|
c.age#c.age | -0.003 0.000 -10.458 0.000 -0.003 -0.002
|
woman |
Women | 3.116 0.774 4.027 0.000 1.600 4.633
|
woman#c.age |
Women | -0.095 0.033 -2.831 0.005 -0.160 -0.029
|
woman#c.age#|
c.age |
Women | 0.000 0.000 1.359 0.174 -0.000 0.001
|
college |
College De.. | 16.216 0.121 134.015 0.000 15.979 16.453
_cons | 29.749 0.568 52.352 0.000 28.635 30.862
-------------------------------------------------------------------------------
Plotting nonlinear interaction effects
Fortunately, the code to plot this model is the exact same as it was when the model was linear and/or additive (i.e. non-multiplicative—no product term):
qui margins, at(age=(20(5)80) woman=(0 1))
marginsplot, ///
recastci(rline) ciopts(lpat(dash) col(gs14)) ylab(38(2)46) ///
title("Predicted Occupational Prestige Based on Person's Age and Gender") ///
subtitle("Interactive and Nonlinear Effect") ///
ytitle("Occupational Prestige")Interpreting nonlinear interaction effects with MEs
It is best to provide examples and interpretations that best answer your research question. Let’s say we are writing an article on the transition into early adulthood, thus we are mainly interested in the effect of age for those in their twenties (because the effect of age is different for men and women I’m also specifying the calculations be made for men specifically with woman=0 in the at( ) statement)
mchange age, at(age=20 woman=0)regress: Changes in xb | Number of obs = 58304
Expression: Linear prediction, predict()
| Change p-value
-------------+---------------------
age |
+1 | 0.221 0.000
+SD | 3.074 0.000
Marginal | 0.224 0.000
Average prediction
38.926
Base values of regressors
| age woman
-------------+---------------------
at | 20 0
Now, mchange reports marginal effects for men starting at age 20 (from 20 to 21, from 20 to 20 + SD, and the instantaneous rate of change at age 20)
If we want a non-standard unit of change, e.g. a 10 year increase in age, we can ask for it via the “delta” option with mchange:
mchange age, at(age=20 woman=0) delta(10)regress: Changes in xb | Number of obs = 58304
Expression: Linear prediction, predict()
| Change p-value
-------------+---------------------
age |
+1 | 0.221 0.000
+delta | 1.978 0.000
Marginal | 0.224 0.000
Average prediction
38.926
Base values of regressors
| age woman
-------------+---------------------
at | 20 0
1: Delta equals 10.
A 10 year increase in age for 20 year old men leads to about 2 points higher job prestige on average
OR
On average, 30 year old men are predicted to hold jobs that are about 2 points higher in job prestige than those held by 20 year old men
Visualizing significant group differences
Fortunately, there are fairly straightforward ways to calculate and visualize significance information for group differences
*Plot marginal effect of gender over the range of age:
qui margins, dydx(woman) at(age=(20(5)80))NOTE: The option dydx() calculates the marginal effect (0 vs. 1) for a binary variable. So this command gives us the marginal effect of gender across the range of age (which we have specified in the at( ) statement)
marginsplot, ///
recastci(rline) ciopts(lpat(dash) col(gs14)) yline(0) ///
title("Marginal Effect of Gender across Range of Age") ///
subtitle("Effects above zero: women have higher job prestige") ///
ytitle("Effect of Gender: Women vs. Men")NOTE: It is almost always useful to make sure your y-axis includes zero on plots of marginal effects (via the ylab( ) option). The option yline(0) plots a horizontal line at zero. This is helpful to interpret the plot as a marginal effect of zero indicates no difference between men and women