use http://www.ats.ucla.edu/stat/data/hsbdemo, clear
sgmediation science, mv(read) iv(math)
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
-------------+------------------------------ Adj R-squared = 0.3948
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
-------------+------------------------------ Adj R-squared = 0.4358
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
-------------+------------------------------ Adj R-squared = 0.4729
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 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
command: sgmediation science, iv(math) mv(read)
_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
command: sgmediation science, iv(math) mv(read)
_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
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
-------------+------------------------------ Adj R-squared = 0.4358
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
-------------+------------------------------ Adj R-squared = 0.4729
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.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.