For this example, we will use Approach B to conduct an interaction analysis based on logistic regression. We want to see if educational level (z) moderates the association between marital status (x) and early retirement (y).
| Dataset |
| StataData1.dta |
| Variable name | earlyret |
| Variable label | Early retirement (Age 50, Year 2020) |
| Value labels | 0=No 1=Yes |
| Variable name | marstat40 |
| Variable label | Marital status (Age 40, Year 2010) |
| Value labels | 1=Married 2=Unmarried 3=Divorced 4=Widowed |
| Variable name | educ |
| Variable label | Educational level (Age 40, Year 2010) |
| Value labels | 1=Compulsory 2=Upper secondary 3=University |
Define the analytical sample
We start by defining the analytical sample:
gen pop_interact3=1 if earlyret!=. & marstat40!=. & educ!=. |
Let us have a quick look at the variables:
sum earlyret marstat40 educ if pop_interact3==1 |

Simple regression models
First, we will run the simple models, one for marstat40 and earlyret, and one for educ and earlyret.
logistic earlyret i.marstat40 if pop_interact3==1 |

logistic earlyret i.educ if pop_interact3==1 |

We see from the output in the tables above that there are quite clear (and statistically significant) associations between marital status and early retirement on the one hand, and educational level and early retirement on the other hand.
Multiple regression model
Next, we run a model with both independent variables included:
logistic earlyret i.marstat40 i.educ if pop_interact3==1 |

The ORs for marstat40 have decreased a bit, whereas the ORs for educ are actually slightly larger.
Now, we need to save the estimates from this model:
estimates store model1 |
Multiple regression model with interaction effect
In this step, we will include the interaction term using Approach 2 (two hashtags mean that we specify the main effects and the interaction effect at the same time):
logistic earlyret i.marstat40##i.educ if pop_interact3==1 |

Similar to the previous model, we have to save the estimates from this one:
estimates store model2 |
Next, we compare the fit of the two models:
lrtest model1 model2, stats |

| Note We called our saved models “model1” and “model2”, but you can choose any name you like. |
In the table above, we can see that the p-value for the likelihood ratio test is above 0.05 (0.7435), which suggests that model that contains that interaction term (model2) does not fit the data better than the model without the interaction term (model1). This is also confirmed by the values for AIC and BIC, which are lower for model1. We can thereby conclude that there is no statistically significant interaction between marital status and educational level in the effect on early retirement.
| Summary Educational attainment does not seem to moderate the association between marital status and early retirement. |