How can I do moderated mediation with a categorical moderator in Stata? | Stata FAQ

This page is just an extension of How can I do moderated mediation
in Stata? to include a categorical moderator variable.
We will call that page modmed. If
you are unfamiliar with moderated mediation you should review the modmed
FAQ page before continuing on with this page.

We will to use the same data and the same abbreviated variable names as were used on the
modmed page.

Next, we use the nlcom command to compute the conditional indirect effects
for each of the
levels of the moderator variable. For level one multiply each of the interaction terms,
wx2 and wx3 by zero. For level 2, multiply wx2
by one and wx3 by zero. For level 3, just reverse the zeros and ones.
Here is the code:

From these results we see that the indirect effect is strongest when w
= 2 (that is, for the academic program) followed by w = 3 (vocational program) and finally
w = 1 (general program). It is also possible to test whether the indirect
effects for the three levels differ from one another. We will demonstrate this by looking at
the difference between w = 2 and w = 1 (the biggest
difference). We do this by subtracting the two nlcom terms.

In this case the difference in the conditional indirect effects is not statistically significant.

In general, nlcom does a reasonably good job of estimating standard
errors and confidence intervals using the delta method. However, the delta method has
some fairly strong normality assumptions that may not hold for products of coefficients.
Many researchers prefer using the bootstrap to obtain confidence intervals.

Bootstrap confidence intervals

To obtain bootstrap confidence intervals for the conditional indirect effects we begin
by writing a program, which we have called bootmmcat and saving it as
an ado file called bootmmcat.ado. Here is the program: