I am using -gsem- to estimate a mediation model where the outcome variable is ordinal; let's use the auto data as an example and there are two
mediators; let's say that the direct effect is the variable "foreign" and the two mediators are price and mpg (note that there is no implication
here that this makes substantive sense); while I can get basic results in a comparative table for several models (say, a model with no mediator
and two models each with one mediator and a final model with both mediators), I cannot figure out how to (1) show the indirect and total effects in my
table (calculated using -nlcom- as shown in the documentation) and (2) I would like to suppress the showing of the 4 cutpoints (or possibly just
move them; the issue here is that if the model with no mediation is shown first, the cutpoints will be automatically shown above the mediators
in the table that has comparative results); (3) for the models with rep78 as the outcome, showing the exponentiated coefficients would be preferred
if possible (results of -estat eform-)
following is the do file and below that is that output from running the do file
output from above:
mediators; let's say that the direct effect is the variable "foreign" and the two mediators are price and mpg (note that there is no implication
here that this makes substantive sense); while I can get basic results in a comparative table for several models (say, a model with no mediator
and two models each with one mediator and a final model with both mediators), I cannot figure out how to (1) show the indirect and total effects in my
table (calculated using -nlcom- as shown in the documentation) and (2) I would like to suppress the showing of the 4 cutpoints (or possibly just
move them; the issue here is that if the model with no mediation is shown first, the cutpoints will be automatically shown above the mediators
in the table that has comparative results); (3) for the models with rep78 as the outcome, showing the exponentiated coefficients would be preferred
if possible (results of -estat eform-)
following is the do file and below that is that output from running the do file
Code:
sysuse auto, clear collect clear collect create Models1 qui collect _r_b _r_p,name(Models1) tag(model[foreign]): gsem (i.foreign -> rep78, family(ordinal) link(logit)), nocapslatent qui collect AIC=r(S)[1,5] BIC=r(S)[1,6], name(Models1) tag(model[foreign]): estat ic qui collect _r_b _r_p,name(Models1) tag(model[foreignp]): gsem (i.foreign -> price, ) /// (i.foreign -> rep78 , family(ordinal) link(logit)) /// (price -> rep78 , family(ordinal) link(logit)), nocapslatent qui collect AIC=r(S)[1,5] BIC=r(S)[1,6], name(Models1) tag(model[foreignp]): estat ic qui collect _r_b _r_p, name(Models1) tag(model[foreignm]): gsem (i.foreign -> mpg, ) /// (i.foreign -> rep78 , family(ordinal) link(logit)) /// (mpg -> rep78, family(ordinal) link(logit)), nocapslatent qui collect AIC=r(S)[1,5] BIC=r(S)[1,6], name(Models1) tag(model[foreignm]): estat ic qui collect _r_b, name(Models1) tag(model[foreignmp]): gsem (i.foreign -> mpg, ) /// (i.foreign -> price, ) (i.foreign -> rep78, family(ordinal) link(logit)) /// (mpg -> rep78, family(ordinal) link(logit)) /// (price -> rep78, family(ordinal) link(logit)), nocapslatent qui collect AIC=r(S)[1,5] BIC=r(S)[1,6], name(Models1) tag(model[foreignmp]): estat ic collect style showbase off collect style cell, nformat(%5.3f) collect style header result, level(hide) collect style row stack, nobinder collect style header result[N AIC BIC], level(label) collect label levels result N "N", modify *collect label levels result r2_p "Pseudo R2", modify collect style cell result[N], warn margin(top, width(72) ) *noi collect label list result noi collect layout (colname#result result[N AIC BIC]) (model) *example code for indirect and total effects noi di "indirect effect for price: " noi nlcom _b[rep78:price]*_b[price:1.foreign], eform noi di "indirect effect for mpg: " noi nlcom _b[rep78:mpg]*_b[mpg:1.foreign], eform noi di "Total effect: " noi nlcom _b[rep78:1.foreign]+(_b[rep78:price]*_b[price:1.foreign]) /// + (_b[rep78:mpg]*_b[mpg:1.foreign]), eform
Code:
Collection: Models1 Rows: colname#result result[N AIC BIC] Columns: model Table 1: 18 x 4 --------------------------------------------------- | foreign foreignp foreignm foreignmp --------------+------------------------------------ Car origin | Foreign | 2.982 | 0.000 cut1 | -3.158 -3.080 -1.885 -0.712 cut2 | -1.363 -1.283 -0.092 1.091 cut3 | 1.232 1.313 2.525 3.719 cut4 | 3.246 3.327 4.581 5.801 Price | 0.000 0.000 | 0.871 0.312 var(e.price) | 8.6e+06 8.6e+06 Mileage (mpg) | 0.067 0.098 | 0.174 0.095 var(e.mpg) | 27.910 27.910 Intercept | 6072.423 19.827 | 0.000 0.000 N | 69.000 74.000 74.000 74.000 AIC | 168.058 1567.282 630.525 2028.731 BIC | 179.229 1588.018 651.262 2058.684 --------------------------------------------------- r; t=0.15 9:54:22 . . *example code for indirect and total effects . noi di "indirect effect for price: " indirect effect for price: r; t=0.00 9:54:22 . noi nlcom _b[rep78:price]*_b[price:1.foreign], eform _nl_1: _b[rep78:price]*_b[price:1.foreign] ------------------------------------------------------------------------------ | exp(b) Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- _nl_1 | 1.029483 .0771883 0.39 0.698 .8887874 1.19245 ------------------------------------------------------------------------------ r; t=0.15 9:54:22 . noi di "indirect effect for mpg: " indirect effect for mpg: r; t=0.00 9:54:22 . noi nlcom _b[rep78:mpg]*_b[mpg:1.foreign], eform _nl_1: _b[rep78:mpg]*_b[mpg:1.foreign] ------------------------------------------------------------------------------ | exp(b) Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- _nl_1 | 1.626355 .5196207 1.52 0.128 .8694737 3.042107 ------------------------------------------------------------------------------ r; t=0.09 9:54:22 . noi di "Total effect: " Total effect: r; t=0.00 9:54:22 . noi nlcom _b[rep78:1.foreign]+(_b[rep78:price]*_b[price:1.foreign]) /// > + (_b[rep78:mpg]*_b[mpg:1.foreign]), eform _nl_1: _b[rep78:1.foreign]+(_b[rep78:price]*_b[price:1.foreign]) + (_b[r > ep78:mpg]*_b[mpg:1.foreign]) ------------------------------------------------------------------------------ | exp(b) Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- _nl_1 | 19.51854 12.52709 4.63 0.000 5.548072 68.66772
Comment