For this example, we want to see if grade point average (z) mediates the association between exposure to bullying (x) and educational level (y).
| Dataset |
| StataData1.dta |
| Variable name | educ |
| Variable label | Educational level (Age 40, Year 2010) |
| Value labels | 1=Compulsory 2=Upper secondary 3=University |
| Variable name | gpa |
| Variable label | Grade point average (Age 15, Year 1985) |
| Value labels | N/A |
| Variable name | bullied |
| Variable label | Exposure to bullying (Age 15, Year 1985) |
| Value labels | 0=No 1=Yes |
Define the analytical sample
We start by defining the analytical sample:
gen pop_mediate2=1 if educ!=. & gpa!=. & bullied!=. |
Let us have a quick look at the variables:
sum educ gpa bullied if pop_mediate2==1 |

Regression models
Now, we can run the regression model with the khb command.
khb ologit educ bullied || gpa if pop_mediate2==1, summary disentangle or |

The model without any z-variables (the “reduced” model) shows that there is a negative (OR=0.67) and statistically significant association (95 % CI=0.58 to 0.77) between bullied and educ. This means that individuals who were exposed to bullying at age 15 have lower odds of attaining a high level of education as adults, in comparison to those who were not exposed to bullying. In the model where the z-variable gpa is included (the “full” model), the association is still negative but very weak and stastistically non-significant (OR=0.95, 95% CI=0.83 to 1.10).
In the table called Summary of confounding, we can see that the amount of the association explained by the z-variables (in this case, we only included gpa), is 88%. This is also shown specified further in the table called Components of Difference.