Page: Moderation in OLS Regression
Moderation occurs when the effect of X1 on Y is differs based on the value of X2. For example, the effect of educational attainment (X1) on income (Y) may differ depending on respondents' gender (X2). Put simply, male respondents may be seeing a larger return to their educational attainment than other genders. We wouldn't be able to detect this more complex dynamic without including an interaction term between educational attainment and gender.
It's generally much easier to interpret/graph an interaction effect when one of the variables is categorical.
It can be very difficult to interpret regression results once an interaction term is included. This post Links to an external site. can offer some guidance. Still, I highly recommend graphing any observed interaction effects, as this makes it easier to interpret and communicate those findings. This can be done either by using the margins/marginsplot commands or the user-written predxcon command.
There are two ways in Stata to include an interaction term. 1) You can put ## between the two variables. This will result in both predicts and their interaction term being included in the model. Note: you have to put c. prefix in front of a continuous variable and i. prefix in front of the categorical variable. 2) You can write out the individual predictors and include the interaction term with just a single #. Both approaches are illustrated below.
. regress dv c.intvar##i.catvar
Equivalent to:
. regress dv intvar i.catvar c.intvar#i.catvar
Once you've run your regression, the focus is on the significance level of the interaction term (don't worry if the significance of the individual predictors). Regardless, it's recommended that you graph the interaction. The following sequence of commands, carried out immediately after your regression (as they draw on the most recent regression results in Stata's memory), will produce a graph of the interaction.
. margins catvar, at(intvar = (lowvalue(increment)highvalue)) atmeans
. marginsplot
. marginsplot, noci [if you don't want the confidence intervals to show]
If you have two categorical variables you want to interact:
. regress dv intvar i.catvar1##i.catvar2
. margins catvar1#catvar2
. marginsplot, xdim(catvar1 catvar2) recast(bar)
OR you can use the user-written predxcon command. Note: if you want to include a polychotomous control variable (cv), you will need to generate dummies and include all but the reference group in the adjust portion of the command, as predxcon does not permit the use of the i. prefix.
. predxcon dv, xvar(intvar) from(lowvalue) to(highvalue) inc(increment) adjust(cv1 cv2) graph
If you have to categorical IVs you'd like to interact, you can use the predxcat command.
. predxcat dv, xvar(catvar1 catvar2) adjust(cv1 cv2) graph bar