### Stata FAQ How to perform Sobel-Goodman mediation tests in Stata?

The purpose of the Sobel-Goodman tests is to test whether a mediator carries the influence of an IV to a DV.

A variable may be considered a mediator to the extent to which it carries the influence of a given independent variable (IV) to a given dependent variable (DV). Generally speaking, mediation can be said to occur when (1) the IV significantly affects the mediator, (2) the IV significantly affects the DV in the absence of the mediator, (3) the mediator has a significant unique effect on the DV, and (4) the effect of the IV on the DV shrinks upon the addition of the mediator to the model.

Example:

This example uses the hsbdemo dataset with science as the DV, math as the IV and read as the mediator variable. That is, the model says that math influences read, which in turn influences science. This model may or may not make much substantive sense but it will allow us to to demonstrate the process of running a Sobel-Goodman test. We will do this using the sgmediation command, you can download this command using findit sgmediation.
use http://www.ats.ucla.edu/stat/data/hsbdemo, clear

Model with dv regressed on iv (path c)

Source |       SS       df       MS              Number of obs =     200
-------------+------------------------------           F(  1,   198) =  130.81
Model |  7760.55791     1  7760.55791           Prob > F      =  0.0000
Residual |  11746.9421   198  59.3279904           R-squared     =  0.3978
Total |     19507.5   199  98.0276382           Root MSE      =  7.7025

------------------------------------------------------------------------------
science |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
math |     .66658   .0582822    11.44   0.000     .5516466    .7815135
_cons |   16.75789   3.116229     5.38   0.000     10.61264    22.90315
------------------------------------------------------------------------------

Model with mediator regressed on iv (path a)

Source |       SS       df       MS              Number of obs =     200
-------------+------------------------------           F(  1,   198) =  154.70
Model |  9175.57065     1  9175.57065           Prob > F      =  0.0000
Residual |  11743.8493   198  59.3123704           R-squared     =  0.4386
Total |    20919.42   199  105.122714           Root MSE      =  7.7015

------------------------------------------------------------------------------
read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
math |    .724807   .0582745    12.44   0.000     .6098887    .8397253
_cons |   14.07254   3.115819     4.52   0.000     7.928087    20.21699
------------------------------------------------------------------------------

Model with dv regressed on mediator and iv (paths b and c')

Source |       SS       df       MS              Number of obs =     200
-------------+------------------------------           F(  2,   197) =   90.27
Model |  9328.73944     2  4664.36972           Prob > F      =  0.0000
Residual |  10178.7606   197  51.6688353           R-squared     =  0.4782
Total |     19507.5   199  98.0276382           Root MSE      =  7.1881

------------------------------------------------------------------------------
science |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
read |   .3654205   .0663299     5.51   0.000     .2346128    .4962283
math |   .4017207   .0725922     5.53   0.000     .2585632    .5448782
_cons |    11.6155   3.054262     3.80   0.000     5.592255    17.63875
------------------------------------------------------------------------------

Sobel-Goodman Mediation Tests

Coef         Std Err     Z           P>|Z|
Sobel               .26485934    .05258136   5.037      4.726e-07
Goodman-1 (Aroian)  .26485934    .05272324   5.024      5.072e-07
Goodman-2           .26485934    .05243909   5.051      4.400e-07

Coef      Std Err    Z          P>|Z|
a coefficient   =  .724807   .058274   12.4378          0
b coeffocoent   =  .365421    .06633   5.50914    3.6e-08
Indirect effect =  .264859   .052581   5.03713    4.7e-07
Direct effect =  .401721   .072592   5.53394    3.1e-08
Total effect =   .66658   .058282   11.4371          0

Proportion of total effect that is mediated:  .39734065
Ratio of indirect to direct effect:           .65931219
Ratio of total to direct effect:              1.6593122
In this example the mediation effect of read was statistically significant with approximately 40% of the total effect (of math on science) being mediated.

#### Bootstrap with case resampling

If you have concerns about the standard error for the indirect effect, you may want to bootstrap sgmediation.
bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation science, iv(math) mv(read)

Bootstrap replications (1000)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
[output omitted]
..................................................  1000

Bootstrap results                               Number of obs      =       200
Replications       =      1000

_bs_1:  r(ind_eff)
_bs_2:  r(dir_eff)

------------------------------------------------------------------------------
|   Observed   Bootstrap                         Normal-based
|      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
_bs_1 |   .2648593   .0539163     4.91   0.000     .1591853    .3705334
_bs_2 |   .4017207    .085701     4.69   0.000     .2337499    .5696915
------------------------------------------------------------------------------

estat bootstrap, percentile bc

Bootstrap results                               Number of obs      =       200
Replications       =      1000

_bs_1:  r(ind_eff)
_bs_2:  r(dir_eff)

------------------------------------------------------------------------------
|    Observed               Bootstrap
|       Coef.       Bias    Std. Err.  [95% Conf. Interval]
-------------+----------------------------------------------------------------
_bs_1 |   .26485934  -.0018226   .05391633    .1513887   .3672891   (P)
|                                       .1495302   .3653122  (BC)
_bs_2 |   .40172068   .0011065   .08570095    .2436569    .575866   (P)
|                                       .2474115   .5803441  (BC)
------------------------------------------------------------------------------
(P)    percentile confidence interval
(BC)   bias-corrected confidence interval

#### Bootstrap with residual resampling

If you prefer to do a residual resampling bootstrap rather than case resampling bootstrap, you can use the resboot-mediation command (findit resboot_mediation).
resboot_mediation, dv(science) mv(read) iv(math) reps(1000)

obs was 200, now 1000

Source |       SS       df       MS              Number of obs =     200
-------------+------------------------------           F(  1,   198) =  154.70
Model |  9175.57065     1  9175.57065           Prob > F      =  0.0000
Residual |  11743.8493   198  59.3123704           R-squared     =  0.4386
Total |    20919.42   199  105.122714           Root MSE      =  7.7015

------------------------------------------------------------------------------
read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
math |    .724807   .0582745    12.44   0.000     .6098887    .8397253
_cons |   14.07254   3.115819     4.52   0.000     7.928087    20.21699
------------------------------------------------------------------------------

Source |       SS       df       MS              Number of obs =     200
-------------+------------------------------           F(  2,   197) =   90.27
Model |  9328.73944     2  4664.36972           Prob > F      =  0.0000
Residual |  10178.7606   197  51.6688353           R-squared     =  0.4782
Total |     19507.5   199  98.0276382           Root MSE      =  7.1881

------------------------------------------------------------------------------
science |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
read |   .3654205   .0663299     5.51   0.000     .2346128    .4962283
math |   .4017207   .0725922     5.53   0.000     .2585632    .5448782
_cons |    11.6155   3.054262     3.80   0.000     5.592255    17.63875
------------------------------------------------------------------------------

Nonparametric resampled residual bootstrap of mediation with 1000 replications

Bootstrap
Coef         Bias      Std Err    [95% Conf Interval]
ind eff  .264859     -.006671   .125424    .033054     .51854 (P)
.054796    .556361 (BC)
dir eff  .401721      .012071   .175588    .065645     .75491 (P)
.029874     .72355 (BC)
tot eff   .66658      .005399    .14155    .401588    .968667 (P)
.401588    .968667 (BC)
(P)   percentile confidence interval
(BC)  bias-corrected confidence interval
References

Aroian, L.A. (1944). The probability function of the product of two normally distributed variables. Annals of Mathematical Statistics, 18, 265-271.
Baron, R.M. & Kenny, D.A. (1986), Moderator-Mediator Variables Distinction in Social Psychological Research: Conceptual, Strategic, and Statistical Considerations. Journal of Personality and Social Psychology, 51 (6), 1173–82.
Goodman, L.A. (1960) On the exact variance of products. Journal of the American Statistical Association, 55, 708-713.
MacKinnon, D. P. & Dwyer, J. H. (1993). Estimating mediated effects in prevention studies. Evaluation Review, 17, 144-158.
MacKinnon, D. P., Warsi, G., & Dwyer, J. H. (1995). A simulation study of mediated effect measures. Multivariate Behavioral Research, 30(1), 41-62.
Preacher, K. J. & Hayes, A. F. (2004). SPSS and SAS procedures for estimating indirect effects in simple mediation models. Behavior Research Methods, Instruments, & Computers, 36(4), 717-731.
Sobel, M.E. (1982) Asymptotic confidence intervals for indirect effects in structural equation models. Sociological Methodology, 13, 290-312.
Sobel, M.E. (1986) Some new results on indirect effects and their standard errors in covariance structure models. Sociological Methodology, 16, 159-186.

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.