Stata:8大中介效应检验命令大比拼_逐步系数检验+两步法+sobel检验+khb+sgmediation+medsem等
本文主要为大家介绍常见的8种中介效应检验方法汇总,分别为:
1、逐步检验回归系数方法 2、两步法 3、sobel检验sgmediation命令 4、基于bootstrap的sobel检验 5、结构方程中介效应检验,medsem命令 6、khb方法 7、sgmediation2命令 8、med4way中介效应检验方法
知识回顾
中介效应是指变量间的影响关系(X→Y)不是直接的因果链关系,而是通过一个或一个以上变量(M)的间接影响产生的,此时我们称M为中介变量,而X通过M对Y产生的的间接影响称为中介效应。中介效应是间接效应的一种,模型中在只有一个中介变量的情况下,中介效应等于间接效应;当中介变量不止一个的情况下,中介效应不等于间接效应,此时间接效应可以是部分中介效应和(或)所有中介效应的总和。自变量X对因变量Y的影响,如果X变量通过影响M变量来影响Y变量,则M为中介变量。通常将变量经过中心化转化后,得方程
方程1 :Y=cX+e1; 方程2 :M=aX+e2; 方程3 :Y= c′X+bM+e3。其中,c是X对Y的总效应,a、b是经过中介变量M的中介效应,c′是直接效应。当只有一个中介变量时,效应之间有c=c′+ab,中介效应的大小用c-c′=ab来衡量。中介效应检验过程
中介效应是间接效应,无论变量是否涉及潜变量,都可以用结构方程模型分析中介效应。步骤为:
第一步检验系统c,如果c不显著,Y与X相关不显著,停止中介效应分析,如果显著进行第二步; 第二步依次检验a,b,如果都显著,那么检验c′,c′显著,为部分中间效应模型,c′不显著,为完全中介效应模型; 如果a,b至少 有一个不显著,做Sobel检验,检验的统计量是Z = ^a^b / Sab,显著则中介效应显著,不显著则中介效应不显著。
案例应用
本例使用hsbdemo数据集,其中science作为DV, math作为IV, read作为中介变量。也就是说,模型说数学影响阅读,而阅读反过来又影响科学。这个模型可能有也可能没有太大的实际意义,但是它将允许我们演示运行一个中介效应测试的过程。我们将使用sgmediation command来完成这个任务,您可以使用findit sgmediation来下载这个命令。
该数据包括200个学生的选择的项目类型(prog, 三种类型 categorical variable), 他们的社会地位(ses 三种地位 categorical variable),写作分数(write, a continuous variable)。导入数据,然后进行查看数据
方法1、逐步检验回归系数方法
逐步检验回归系数方法分为三步:
reg science math //分析 x 和 y 之间的关系
reg read math //分析 x 和 m 之间的关系
reg science read math // 加入 m,看 x 和 y 之间的关系
操作结果为:
方法2、两步回归法 (two-step regression)
Zhao, Lynch et al. (2010)对传统的逐步检验回归系数方法提出再次思考,但其具体的步骤方法与逐步检验回归系数方法接近,只是取消了第一步中的检验自变量 x 和因变量 y 之间的关系, 代码为:
reg read math //分析 x 和 m 之间的关系
reg science read math // 加入 m,看 x 和 y 之间的关系
方法3、sobel检验--中介效应检验程序Sobel-Goodman mediation tests
语法格式为:
sgmediation depvar [if exp] [in range] , mv:(mediatorvar) iv(indvar) [ cv(covarlist) quietly ]
选项含义为:
depvar表示因变量 mv:(mediatorvar) 表示用于指定中介变量 iv(indvar) 表示用于指定自变量 cv(covarlist)表示用于指定控制变量
查看数据
edit
desc
数据如下:
. help sgmediation
. use "C:\Users\Metrics\Desktop\hsbdemo.dta", clear
(highschool and beyond (200 cases))
. desc
Contains data from C:\Users\Metrics\Desktop\hsbdemo.dta
obs: 200 highschool and beyond (200 cases)
vars: 13 30 Oct 2009 14:13
size: 10,000
--------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------
id float %9.0g
female float %9.0g fl
ses float %9.0g sl
schtyp float %9.0g scl type of school
prog float %9.0g sel type of program
read float %9.0g reading score
write float %9.0g writing score
math float %9.0g math score
science float %9.0g science score
socst float %9.0g social studies score
honors float %19.0g honlab honors english
awards float %9.0g
cid int %8.0g
--------------------------------------------------------------------------------------
Sorted by:
. set more off
进行操作为:
sgmediation science, mv(read) iv(math)
结果为:
. sgmediation science, mv(read) iv(math)
# 表示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)
# 形成路劲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 coefficient = .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 onscience) being mediated.
在这个例子中,read的中介效果在统计上是显著的,通过这个可以得到(Proportion of total effect that is mediated: .39734065)大约40%的总效果(数学对科学)是被中介的。
操作案例2 如果需要加入协变量,则为如下命令
sgmediation science, mv(read) iv(math) cv(write)
结果为:
sgmediation science, mv(read) iv(math) cv(write)
Model with dv regressed on iv (path c)
Source | SS df MS Number of obs = 200
-------------+---------------------------------- F(2, 197) = 80.84
Model | 8793.36552 2 4396.68276 Prob > F = 0.0000
Residual | 10714.1345 197 54.3864694 R-squared = 0.4508
-------------+---------------------------------- Adj R-squared = 0.4452
Total | 19507.5 199 98.0276382 Root MSE = 7.3747
------------------------------------------------------------------------------
science | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
math | .4757015 .07094 6.71 0.000 .3358022 .6156009
write | .3055482 .0701157 4.36 0.000 .1672745 .443822
_cons | 10.68138 3.293391 3.24 0.001 4.186557 17.17621
------------------------------------------------------------------------------
Model with mediator regressed on iv (path a)
Source | SS df MS Number of obs = 200
-------------+---------------------------------- F(2, 197) = 96.80
Model | 10368.63 2 5184.31501 Prob > F = 0.0000
Residual | 10550.79 197 53.5573096 R-squared = 0.4956
-------------+---------------------------------- Adj R-squared = 0.4905
Total | 20919.42 199 105.122714 Root MSE = 7.3183
------------------------------------------------------------------------------
read | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
math | .5196538 .0703972 7.38 0.000 .380825 .6584826
write | .3283984 .0695792 4.72 0.000 .1911828 .4656141
_cons | 7.541599 3.26819 2.31 0.022 1.096471 13.98673
------------------------------------------------------------------------------
Model with dv regressed on mediator and iv (paths b and c')
Source | SS df MS Number of obs = 200
-------------+---------------------------------- F(3, 196) = 65.32
Model | 9752.65806 3 3250.88602 Prob > F = 0.0000
Residual | 9754.84194 196 49.7696017 R-squared = 0.4999
-------------+---------------------------------- Adj R-squared = 0.4923
Total | 19507.5 199 98.0276382 Root MSE = 7.0548
------------------------------------------------------------------------------
science | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
read | .3015317 .0686815 4.39 0.000 .1660822 .4369813
math | .3190094 .0766753 4.16 0.000 .167795 .4702239
write | .2065257 .0707644 2.92 0.004 .0669683 .3460831
_cons | 8.407353 3.192799 2.63 0.009 2.110703 14.704
------------------------------------------------------------------------------
Sobel-Goodman Mediation Tests
Coef Std Err Z P>|Z|
Sobel .15669211 .04152593 3.773 .00016107
Goodman-1 (Aroian) .15669211 .04180646 3.748 .00017822
Goodman-2 .15669211 .0412435 3.799 .00014517
Coef Std Err Z P>|Z|
a coefficient = .519654 .070397 7.38174 1.6e-13
b coefficient = .301532 .068681 4.39029 .000011
Indirect effect = .156692 .041526 3.77336 .000161
Direct effect = .319009 .076675 4.16053 .000032
Total effect = .475702 .07094 6.70569 2.0e-11
Proportion of total effect that is mediated: .32939164
Ratio of indirect to direct effect: .49118333
Ratio of total to direct effect: 1.4911833
方法4:基于bootstrap的sobel检验方法
操作案例3 bootstrap with case resampling
bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation science, mv(read) iv(math)
estat bootstrap, percentile bc
结果为:
bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation science, mv(read) iv(math)
(running sgmediation on estimation sample)
Bootstrap replications (1000)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.................................................. 50
.................................................. 100
.................................................. 150
.................................................. 200
.................................................. 250
.................................................. 300
.................................................. 350
.................................................. 400
.................................................. 450
.................................................. 500
.................................................. 550
.................................................. 600
.................................................. 650
.................................................. 700
.................................................. 750
.................................................. 800
.................................................. 850
.................................................. 900
.................................................. 950
.................................................. 1000
Bootstrap results Number of obs = 200
Replications = 1,000
command: sgmediation science, mv(read) iv(math)
_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 .0548346 4.83 0.000 .1573855 .3723332
_bs_2 | .4017207 .0819454 4.90 0.000 .2411106 .5623307
------------------------------------------------------------------------------
.
. estat bootstrap, percentile bc
Bootstrap results Number of obs = 200
Replications = 1000
command: sgmediation science, mv(read) iv(math)
_bs_1: r(ind_eff)
_bs_2: r(dir_eff)
------------------------------------------------------------------------------
| Observed Bootstrap
| Coef. Bias Std. Err. [95% Conf. Interval]
-------------+----------------------------------------------------------------
_bs_1 | .26485934 -.0057812 .05483462 .1520132 .3652509 (P)
| .1712486 .3799049 (BC)
_bs_2 | .40172068 .0059509 .08194541 .2422861 .563365 (P)
| .2336006 .5417721 (BC)
------------------------------------------------------------------------------
(P) percentile confidence interval
(BC) bias-corrected confidence interval
方法5 、结构方程中介效应检验
在使用结构方程模型(sem)估计完中介效应之后,我们可以使用medsem命令进一步检验中介效应。
medsem基于使用Stata的-sem命令估计的模型(包括观察到的变量或潜在变量,以及观察到的变量和潜在变量的组合)进行中介分析。有medsem使用两种方法作为其过程的基础。第一种方法是众所周知的Baron and Kenny方法,由Iacobucci等人(2007)调整用于结构方程模型。第二种方法是Zhao等人(2010)的方法。
首先下载安装该命令:
ssc install medsem,replace
命令medsem是专门用于sem命令之后计算中介效应的。
语法格式为:
medsem - Mediation analysis using structural equation modelling
medsem, indep(varname) med(varname) dep(varname) [mcreps(number) stand zlc rit rid]
选项含义为:
indep(varname)代表解释变量(X);
med(varname)代表中介变量(M);
dep(varname)代表被解释变量(Y);
mereps(number)指定蒙特卡罗复制的数量,默认是样本的数量大小;
stand指定输出标准化的系数。当省略这一项时,默认输出非标准化系数;
zlc用于指定(Zhao et al..,2010)的中介效应估计方法,当省略这一选项时,默认是(Iacobucci et al. (2007))改进的BK方法。
选项rit用于指定输出中介效应与总效应之比,即rit, ratio of the indirect effect to the total effect
rid,即 rid用于指定输出中介效应与直接效应之比。
案例应用
. use http://www.ats.ucla.edu/stat/data/hsbdemo, clear
. qui sem (read <- math)(science <- read math)
. medsem, indep(math) med(read) dep(science) stand mcreps(5000) zlc rit rid
. use http://www.stata-press.com/data/r14/sem_sm2.dta, clear
. qui sem (Alien67->anomia67 pwless67)(Alien71->anomia71 pwless71)(SES->educ66 occstat66)(Alien67<-SES)(Alien71<-Alien67 SES)
. medsem, indep(SES) med(Alien67) dep(Alien71) stand mcreps(5000) zlc rit rid
. use http://www.stata-press.com/data/r14/sem_sm2.dta, clear
. qui sem (F1->educ66 occstat66)(F2->anomia66 pwless66)(F3->anomia67 pwless67)(F4->anomia71 pwless71)(F2 F3<-F1)(F4<-F1 F2 F3)
. medsem, indep(F1) med(F2) dep(F4)
. medsem, indep(F1) med(F3) dep(F4) zlc
. use http://www.stata-press.com/data/r14/sem_sm2.dta, clear
. qui sem (F1->educ66 occstat66)(F2->anomia66 pwless66)(F3->anomia67 pwless67)(F2<-F1)(F3<-F1 F2)
. medsem, indep(F1) med(F2) dep(F3) stand rit
1、先进行sem结构方程中介效应模型分析
. use http://www.ats.ucla.edu/stat/data/hsbdemo, clear
. qui sem (read <- math)(science <- read math)
. medsem, indep(math) med(read) dep(science) stand mcreps(5000) zlc rit rid
结果为:
. use "hsbdemo.dta"
(highschool and beyond (200 cases))
. ed
. desc
Contains data from hsbdemo.dta
Observations: 200 highschool and beyond (200 cases)
Variables: 13 30 Oct 2009 14:13
-----------------------------------------------------------------------------------------------------------------------------
Variable Storage Display Value
name type format label Variable label
-----------------------------------------------------------------------------------------------------------------------------
id float %9.0g
female float %9.0g fl
ses float %9.0g sl
schtyp float %9.0g scl type of school
prog float %9.0g sel type of program
read float %9.0g reading score
write float %9.0g writing score
math float %9.0g math score
science float %9.0g science score
socst float %9.0g social studies score
honors float %19.0g honlab honors english
awards float %9.0g
cid int %8.0g
-----------------------------------------------------------------------------------------------------------------------------
Sorted by:
. . qui sem (read <- math)(science <- read math)
. sem (read <- math)(science <- read math)
Endogenous variables
Observed: read science
Exogenous variables
Observed: math
Fitting target model:
Iteration 0: log likelihood = -2098.5822
Iteration 1: log likelihood = -2098.5822
Structural equation model Number of obs = 200
Estimation method: ml
Log likelihood = -2098.5822
-------------------------------------------------------------------------------
| OIM
| Coefficient std. err. z P>|z| [95% conf. interval]
--------------+----------------------------------------------------------------
Structural |
read |
math | .724807 .0579824 12.50 0.000 .6111636 .8384504
_cons | 14.07254 3.100201 4.54 0.000 7.996255 20.14882
------------+----------------------------------------------------------------
science |
read | .3654205 .0658305 5.55 0.000 .2363951 .4944459
math | .4017207 .0720457 5.58 0.000 .2605138 .5429276
_cons | 11.6155 3.031268 3.83 0.000 5.674324 17.55668
--------------+----------------------------------------------------------------
var(e.read)| 58.71925 5.871925 48.26811 71.43329
var(e.science)| 50.8938 5.08938 41.83548 61.91346
-------------------------------------------------------------------------------
LR test of model vs. saturated: chi2(0) = 0.00 Prob > chi2 = .
2、进行中介效应检验
medsem, indep(math) med(read) dep(science)
Significance testing of indirect effect (unstandardised)
+--------------------------------------------------------------------------+
Estimates | Delta | Sobel | Monte Carlo
|--------------------------------------------------------------------------|
Indirect effect | 0.265 | 0.265 | 0.264
Std. Err. | 0.052 | 0.052 | 0.052
z-value | 5.073 | 5.073 | 5.040
p-value | 0.000 | 0.000 | 0.000
Conf. Interval | 0.163 , 0.367 | 0.163 , 0.367 | 0.165 , 0.367
|--------------------------------------------------------------------------|
Baron and Kenny approach to testing mediation
STEP 1 - read:math (X -> M) with B=0.725 and p=0.000
STEP 2 - science:read (M -> Y) with B=0.365 and p=0.000
STEP 3 - science:math (X -> Y) with B=0.402 and p=0.000
As STEP 1, STEP 2 and STEP 3 as well as the Sobel's test above
are significant the mediation is partial!
+--------------------------------------------------------------------------+
Note: to read more about this package help medsem
也可以加入其他选项进一步分析:
. medsem, indep(math) med(read) dep(science) stand mcreps(5000) zlc rit rid
Significance testing of indirect effect (standardised)
+--------------------------------------------------------------------------+
Estimates | Delta | Sobel | Monte Carlo
|--------------------------------------------------------------------------|
Indirect effect | 0.251 | 0.251 | 0.250
Std. Err. | 0.046 | 0.046 | 0.046
z-value | 5.446 | 5.501 | 5.466
p-value | 0.000 | 0.000 | 0.000
Conf. Interval | 0.160 , 0.341 | 0.161 , 0.340 | 0.161 , 0.341
|--------------------------------------------------------------------------|
Baron and Kenny approach to testing mediation
STEP 1 - read:math (X -> M) with B=0.662 and p=0.000
STEP 2 - science:read (M -> Y) with B=0.378 and p=0.000
STEP 3 - science:math (X -> Y) with B=0.380 and p=0.000
As STEP 1, STEP 2 and STEP 3 as well as the Sobel's test above
are significant the mediation is partial!
Zhao, Lynch & Chen's approach to testing mediation
STEP 1 - science:math (X -> Y) with B=0.380 and p=0.000
As the Monte Carlo test above is significant, STEP 1 is
significant and their coefficients point in same direction,
you have complementary mediation (partial mediation)!
RIT = (Indirect effect / Total effect)
(0.251 / 0.631) = 0.397
Meaning that about 40 % of the effect of math
on science is mediated by read!
RID = (Indirect effect / Direct effect)
(0.251 / 0.380) = 0.659
That is, the mediated effect is about 0.7 times as
large as the direct effect of math on science!
+--------------------------------------------------------------------------+
Note: to read more about this package help medsem
方法6、khb检验方法
khb该方法是为二进制、logit和probit模型开发的,但该命令还包括其他非线性概率模型(有序和多项)和线性回归。
线性模型所描述的策略不能用于非线性概率模型,如logit和probit,因为这些模型的估计系数在不同模型之间是不可比较的。原因是这些模型的一个特性引起了模型的重新缩放:系数和误差方差没有单独识别。
khb方法解决了这个问题。它允许对GLM框架的许多模型(包括logit、probit、logit、oprobit和mlogit)的嵌套模型的效果进行比较。
khb方法主要用于logit和probit模型的各种变体。但是,它也可以用于线性回归,在这种情况下,它返回与标准技术相同的结果。因此,KHB只是一种使用单个命令进行分解的方便方法。
语法含义
khb model-type depvar key-vars || z-vars [if] [in] [weight] [ , options ]
模型类型可以是regression、logit、logit、probit、oprobit、cloglog、{help logit}、scobit、rologit、clogit、xtlogit、xtprobit和mlogit中的任何一种。其他模型也可能产生输出,但目前这种输出被认为是“实验性的”。
depvar是因变量的名称, key-vars是包含要分解的变量名称的变量列表, z-vars是包含感兴趣的控制变量名称的变量列表。 Factor variables允许使用因子变量。z变量的因子变量只允许在Stata 12或更高版本中使用。如果指定了option -xstandard-,则不允许key-vars使用因子变量。如果在指定的模型类型中允许,则允许使用aweights, fweights, iweights, and pweights Concomitant(varlist)指定控制变量不是中介变量,允许因子变量。 Disentangle请求一个表,该表显示每个控制变量提供的完整模型(总效应)和简化模型(直接效应)之间的差异有多大。 Summary请求所有自变量的分解情况。 默认情况下,khb报告完整模型和简化模型的效果、它们的差异以及它们的标准误。通过Summary选项,khb还提供了一个表,显示混淆比率(confounding ratios)、由于混杂而减少的百分比和缩放因子(rescale factor)。
操作应用
本例使用hsbdemo数据集,其中science作为DV, math作为IV, read作为中介变量。也就是说,模型说数学影响阅读,而阅读反过来又影响科学。这个模型可能有也可能没有太大的实际意义,但是它将允许我们演示运行一个中介效应测试的过程。我们将使用sgmediation command来完成这个任务,您可以使用findit sgmediation来下载这个命令。
该数据包括200个学生的选择的项目类型(prog, 三种类型 categorical variable), 他们的社会地位(ses 三种地位 categorical variable),写作分数(write, a continuous variable)。导入数据,然后进行查看数据据,
edit
desc
数据如下:
. use "C:\Users\Metrics\Desktop\hsbdemo.dta", clear
(highschool and beyond (200 cases))
. desc
Contains data from C:\Users\Metrics\Desktop\hsbdemo.dta
obs: 200 highschool and beyond (200 cases)
vars: 13 30 Oct 2009 14:13
size: 10,000
--------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------
id float %9.0g
female float %9.0g fl
ses float %9.0g sl
schtyp float %9.0g scl type of school
prog float %9.0g sel type of program
read float %9.0g reading score
write float %9.0g writing score
math float %9.0g math score
science float %9.0g science score
socst float %9.0g social studies score
honors float %19.0g honlab honors english
awards float %9.0g
cid int %8.0g
--------------------------------------------------------------------------------------
Sorted by:
. set more off
进行操作为:
khb regress science math || read
结果为:
khb regress science math || read
Decomposition using Linear Probability Models
Model-Type: regress Number of obs = 200
Variables of Interest: math R-squared = 0.48
Z-variable(s): read
------------------------------------------------------------------------------
science | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
math |
Reduced | .66658 .0543901 12.26 0.000 .5599773 .7731827
Full | .4017207 .0725922 5.53 0.000 .2594427 .5439987
Diff | .2648593 .0525382 5.04 0.000 .1618863 .3678324
------------------------------------------------------------------------------
.
加入选项,结果为:
khb regress science math || read,disentangle summary
Decomposition using Linear Probability Models
Model-Type: regress Number of obs = 200
Variables of Interest: math R-squared = 0.48
Z-variable(s): read
------------------------------------------------------------------------------
science | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
math |
Reduced | .66658 .0543901 12.26 0.000 .5599773 .7731827
Full | .4017207 .0725922 5.53 0.000 .2594427 .5439987
Diff | .2648593 .0525382 5.04 0.000 .1618863 .3678324
------------------------------------------------------------------------------
Summary of confounding
Variable | Conf_ratio Conf_Pct Resc_Fact
-------------+-------------------------------------
math | 1.6593122 39.73 1
---------------------------------------------------
Components of Difference
Z-Variable | Coef Std_Err P_Diff P_Reduced
-------------+---------------------------------------------
math |
read | .2648593 .0525382 100.00 39.73
-----------------------------------------------------------
.
执行上述命令后,输出三组结果。
最上边一组报告了总效应(Reduced)系数、直接效应(Full)系数和间接效应(Diff)系数。 中间一组报告了中介变量的中介比例 最下边一组则报告了中介变量的间接效应系数和中介的比例
综上,总效应(Reduced)系数为 .66658 、直接效应(Full)系数 .4017207和间接效应(Diff)系数 .2648593。
方法7、sgmediation2
语法格式为:
sgmediation2 depvar [if exp] [in range] , iv( focus_iv ) mv( mediator_var ) [options]
其中 depvar
表示因变量iv(focus_iv)
表示自变量mv( mediator_var )
表示中介变量
下载安装方法
net install sgmediation2, from("https://tdmize.github.io/data/sgmediation2")
help sgmediation2
操作案例为:
在这个界面可以详细的查看帮助文件手册以及案例
计算得到总效应,路径c
计算得到间接效应系数a
计算得到间接效应系数b,以及直接效应
sobel检验结果,其中间接效应为a*b
方法8、med4way
安装和数据下载命令如下:
. net install med4way, from("https://raw.githubusercontent.com/anddis/med4way/master/") replace
. help med4way
*-下载范例数据
. net get med4way, from("https://raw.githubusercontent.com/anddis/med4way/master/")
语法结构如下:
med4way depavr varlist [if] [in], a0(real) a1(real) m(real) yreg(string) mreg(string)
depvar
表示被解释变量;varlist
:依次为暴露因素、中介变量 、多个混杂因素(可有可无,视情况而定)
未完待续!