How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?

How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?

Moderated mediation analysis is a statistical technique that examines the relationship between a predictor variable, a mediator variable, and an outcome variable, while also taking into account the impact of a moderator variable. This approach allows for a better understanding of the indirect effects of the predictor and mediator variables on the outcome variable, while considering the influence of the moderator variable.

In order to perform moderated mediation analysis using the structural equation modeling (SEM) approach, the researcher must first specify a theoretical model that outlines the relationships between the variables of interest. This model is then tested using SEM techniques, which involve estimating the direct and indirect effects of the predictor and mediator variables on the outcome variable, while also examining the moderating effect of the moderator variable.

The moderator variable in this approach is categorical, meaning it has distinct categories or levels. This allows for the examination of how the relationship between the predictor and mediator variables changes across different levels of the moderator variable.

Overall, performing moderated mediation analysis using the SEM approach requires careful consideration of the theoretical model and appropriate statistical techniques to test the relationships between variables and explore the moderating effect of the categorical moderator variable.

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

This page is just an extension of How can I do moderated mediation
in Stata? to include a categorical moderator variables.
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. The model is not of substantive interest, it is merely
used to show the steps involved in the analysis.

use https://stats.idre.ucla.edu/stat/data/hsbdemo, clear
rename science y  /* dependent variable   */
rename math x     /* independent variable */
rename read m     /* mediator variable    */
rename female w   /* moderator variable with 2 levels */
rename socst cv   /* continuous covariate */

The modmed page presented five different models for moderated mediation.
This page will cover models 5, 2 and 3, to illustrate the use of categorical moderators.
The diagram for model 5 looks like this:

Model 5
Image model5s

First pass using sem

The trick to using sem for moderated mediation with a categorical moderator
is to do a multiple group
analysis using the group option. Please note, there are no explicit
interactions in the model. The interactions are implicit in the multiple group analysis
itself. Here is our first try.

sem (m 

Endogenous variables

Observed:  m y

Exogenous variables

Observed:  x cv

Fitting target model:

Iteration 0:   log likelihood = -2792.7769  
Iteration 1:   log likelihood = -2792.7769  

Structural equation model                       Number of obs      =       200
Grouping variable  = w                          Number of groups   =         2
Estimation method  = ml
Log likelihood     = -2792.7769

------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m  chi2 =      .

This isn’t too bad. We are getting separate male and female coefficients for both
x and m. However, we are also getting separate
coefficients for cv and separate residual variances in each equations.
In a traditional moderated mediation model these values are not part of the interaction.
So, we will need to constrain the coefficients for cv and residual variances to
be equal in both equations. Here is how to do that.

Model 5 constraining the covariate to be equal across groups

Equations that begin with 0: refer to the male group and equations that begin with 1: refer
to the female group. To constrain values use a ‘@’ and a name. Terms with the same name
will be constrained to be equal. For example, the term cv@c1 will be
constrained to be equal in both equations.

sem (0: m 

Endogenous variables

Observed:  m y

Exogenous variables

Observed:  x cv

Fitting target model:

Iteration 0:   log likelihood = -2795.5195  
Iteration 1:   log likelihood = -2794.6484  
Iteration 2:   log likelihood = -2794.6438  
Iteration 3:   log likelihood = -2794.6438  

Structural equation model                       Number of obs      =       200
Grouping variable  = w                          Number of groups   =         2
Estimation method  = ml
Log likelihood     = -2794.6438

 ( 1)  [m]0bn.w#c.cv - [m]1.w#c.cv = 0
 ( 2)  [y]0bn.w#c.cv - [y]1.w#c.cv = 0
 ( 3)  [var(e.m)]0bn.w - [var(e.m)]1.w = 0
 ( 4)  [var(e.y)]0bn.w - [var(e.y)]1.w = 0
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m  chi2 = 0.4432

Now we can use the estat teffects to calculate the indirect
effects for both males and females.

estat teffects


Direct effects
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m |z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m |z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m 

The indirect effect of x on y for males is .2042854 while
for females it is .1142354.

Next we will look at Model 2.

Model 2

Here is the diagram for Model 2.

Image model2s-1

For this model there is an interaction between w and x
only in the mediator equation so we have to constrain the coefficient for the mediator
to be equal in both equations in addition to the covariate and residuals.

sem (0: m 

Endogenous variables

Observed:  m y

Exogenous variables

Observed:  x cv

Fitting target model:

Iteration 0:   log likelihood = -2880.2553  
Iteration 1:   log likelihood = -2814.5984  
Iteration 2:   log likelihood =  -2797.118  
Iteration 3:   log likelihood = -2796.3599  
Iteration 4:   log likelihood = -2796.3547  
Iteration 5:   log likelihood = -2796.3547  

Structural equation model                       Number of obs      =       200
Grouping variable  = w                          Number of groups   =         2
Estimation method  = ml
Log likelihood     = -2796.3547

 ( 1)  [y]0bn.w#c.m - [y]1.w#c.m = 0
 ( 2)  [m]0bn.w#c.cv - [m]1.w#c.cv = 0
 ( 3)  [y]0bn.w#c.cv - [y]1.w#c.cv = 0
 ( 4)  [var(e.m)]0bn.w - [var(e.m)]1.w = 0
 ( 5)  [var(e.y)]0bn.w - [var(e.y)]1.w = 0
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m  chi2 = 0.2093

estat teffects

Direct effects
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m |z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m |z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m 

This time the indirect effect of x on y for males is .1531604 while
for females it is .1839601.

Next up is Model 3.

Model 3

Here is the diagram for Model 3.

Image model3s-1

For Model 3 the interaction term is only in the equation for the dependent variable, y.
To compute the indirect effect we will need to constrain the coefficient for x in
both equations along with cv and the residuals. In addition we will need to
constrain the constant, _cons to be equal in both groups for the first equation.

sem (0: m 

Endogenous variables

Observed:  m y

Exogenous variables

Observed:  x cv

Fitting target model:

Iteration 0:   log likelihood = -2809.2798  
Iteration 1:   log likelihood =  -2797.463  
Iteration 2:   log likelihood = -2796.0327  
Iteration 3:   log likelihood = -2796.0196  
Iteration 4:   log likelihood = -2796.0196  

Structural equation model                       Number of obs      =       200
Grouping variable  = w                          Number of groups   =         2
Estimation method  = ml
Log likelihood     = -2796.0196

 ( 1)  [m]0bn.w#c.x - [m]1.w#c.x = 0
 ( 2)  [m]0bn.w#c.cv - [m]1.w#c.cv = 0
 ( 3)  [y]0bn.w#c.x - [y]1.w#c.x = 0
 ( 4)  [y]0bn.w#c.cv - [y]1.w#c.cv = 0
 ( 5)  [var(e.m)]0bn.w - [var(e.m)]1.w = 0
 ( 6)  [var(e.y)]0bn.w - [var(e.y)]1.w = 0
 ( 7)  [m]0bn.w - [m]1.w = 0
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m  chi2 = 0.4843

estat teffects

Direct effects
------------------------------------------------------------------------------
             |                 OIM
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m |z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m |z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
Structural   |
  m 

This time the indirect effect of x on y for males is .2143505 while
for females it is .1231748.

Cite this article

stats writer (2024). How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-perform-moderated-mediation-analysis-with-a-categorical-moderator-using-the-structural-equation-modeling-sem-approach/

stats writer. "How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-perform-moderated-mediation-analysis-with-a-categorical-moderator-using-the-structural-equation-modeling-sem-approach/.

stats writer. "How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-perform-moderated-mediation-analysis-with-a-categorical-moderator-using-the-structural-equation-modeling-sem-approach/.

stats writer (2024) 'How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-perform-moderated-mediation-analysis-with-a-categorical-moderator-using-the-structural-equation-modeling-sem-approach/.

[1] stats writer, "How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How can I perform moderated mediation analysis with a categorical moderator using the structural equation modeling (SEM) approach?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top