I am running a mixed effect model in Stata 15.1 using melogit, with weights. I need to calculate the predicted values of my outcome variable (inpov) for all combinations of an interaction (i.wavediag#i.ecact_tp). I initially used 'predict' as margins was taking too long. However, I then realised that I could speed up margins by using the 'nose' option, so tried this as well - only to find that the two methods produced different results. I have tried looking for answers in the stata manual and on statalist but couldn't find anything that would explain this.
Data extract:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float inpov_hhld_100821 byte sex float(agegroup4 wavediag ecact_tp psnenub_xw) long pidp 0 2 3 1 2 1.233141 68006807 0 2 3 1 2 1.2297792 68006807 0 2 3 0 2 1.2514563 68006807 0 2 3 0 2 1.2499105 68006807 0 2 3 0 2 1.2401446 68006807 1 2 3 0 2 1.1806821 68006807 0 2 3 1 2 1.2099682 68006807 0 2 4 0 2 1.2412595 68006807 0 2 3 0 2 1.280226 68025847 0 2 3 0 2 1.3032144 68025847 0 2 3 1 2 1.3751597 68025847 0 2 3 0 2 1.3711437 68025847 0 2 3 1 2 1.3834875 68025847 0 2 3 0 2 1.449717 68025847 1 2 4 1 2 1.5623387 68025847 . . 4 . . 0 68025847 0 2 3 0 2 1.3397578 68034007 . . 2 . . 0 68034685 . . 2 . . 0 68034685 1 1 2 0 3 1.34906 68044891 1 1 2 0 2 1.3920894 68044891 1 1 2 0 2 1.4348925 68044891 0 1 3 0 2 1.2324398 68048287 0 1 3 0 2 1.204421 68048287 0 1 3 0 2 1.1730369 68048287 0 1 3 0 2 1.143072 68048287 0 1 3 0 2 1.1191028 68048287 0 1 3 0 2 1.1526397 68048287 0 1 3 0 2 1.2140963 68048287 0 1 3 1 2 1.2723308 68048287 0 2 3 1 2 1.0702629 68048291 1 1 4 0 2 1.6511854 68061887 0 1 4 1 2 1.6350224 68061887 0 1 4 0 2 1.7039766 68061887 0 1 4 0 2 1.7254713 68061887 . . 4 . . 0 68061887 1 1 2 0 3 1.4639114 68075487 0 1 2 1 6 1.4259746 68075487 0 2 4 1 2 1.9287426 68084325 . . 4 . . 0 68084325 0 1 3 1 2 1.8997667 68084329 . . 4 . . 0 68084329 0 1 3 0 2 1.5559765 68087047 0 1 3 0 2 1.628278 68087047 0 1 3 0 2 1.6643783 68087047 0 1 3 0 2 1.6401013 68087047 0 1 3 0 2 1.6441808 68087047 . . 3 . . 0 68087047 1 1 3 0 2 0 68087047 . . 3 . . 0 68087047 0 . 2 . . 0 68095885 . . 2 . . 0 68095887 0 2 4 0 2 2.0301576 68095889 0 2 3 1 2 1.3050812 68119687 0 2 3 1 2 1.2597277 68119687 0 2 3 1 2 1.286113 68119687 0 2 3 0 2 1.2665005 68119687 . . 3 . . 0 68119687 0 2 3 0 2 0 68119687 0 1 3 0 1 1.4379786 68121731 . . 3 . . 0 68121731 0 1 3 0 1 0 68121731 0 1 3 0 1 0 68121731 0 1 3 1 . 0 68121731 0 2 3 0 1 1.261492 68129891 0 2 3 0 1 1.2690908 68129891 0 2 3 0 1 1.267468 68129891 0 1 3 0 1 1.8294746 68136005 0 1 3 1 3 1.8803334 68136005 0 1 2 0 1 1.4095695 68140771 0 1 2 0 1 1.494244 68140771 0 1 2 0 1 1.5510554 68140771 1 1 2 0 3 1.5632282 68140771 0 1 4 1 2 1.3321185 68159805 0 1 4 0 2 1.2865818 68159805 0 1 4 0 2 1.279343 68159805 . . 4 . . 0 68159805 . . 4 . . 0 68159805 0 2 3 0 2 1.2972198 68159809 0 2 4 0 2 1.252876 68159809 0 2 4 0 2 1.245827 68159809 . . 4 . . 0 68159809 . . 4 . . 0 68159809 0 2 3 1 2 1.3675338 68161167 0 2 4 1 2 2.0855067 68189727 0 2 4 0 2 2.1276193 68189727 0 2 4 0 2 2.2348053 68189727 0 1 4 0 2 1.3550208 68190407 0 1 4 1 2 1.33746 68190407 0 1 4 0 2 1.3262198 68190407 0 2 4 0 2 1.435873 68190411 0 1 3 0 1 1.373054 68190415 0 1 3 0 1 1.4167392 68190415 0 1 3 0 1 1.4048327 68190415 1 1 3 0 3 1.38148 68190415 1 1 3 0 6 1.375532 68190415 1 1 3 0 6 1.3322715 68190415 1 1 3 0 2 1.317959 68190415 . . 3 . . 0 68190415 . . 3 . . 0 68257727 end label values sex a_sex label def a_sex 1 "male", modify label def a_sex 2 "female", modify label values agegroup4 agegroup4 label def agegroup4 2 "45-64", modify label def agegroup4 3 "65-79", modify label def agegroup4 4 "80+", modify label values ecact_tp ecact_tp label def ecact_tp 1 "In employment", modify label def ecact_tp 2 "Retired", modify label def ecact_tp 3 "Long-term sick/disabled", modify label def ecact_tp 6 "Leave LM - other", modify
Code and output
Code:
.
. melogit inpov i.sex i.agegroup4 i.wavediag##i.ecact_tp [pw=psnenub_xw] || pidp:, or
Fitting fixed-effects model:
Iteration 0: log likelihood = -4520.8039
Iteration 1: log likelihood = -4473.3109
Iteration 2: log likelihood = -4473.226
Iteration 3: log likelihood = -4473.226
Refining starting values:
Grid node 0: log likelihood = -3871.2333
Fitting full model:
Iteration 0: log pseudolikelihood = -3871.2333
Iteration 1: log pseudolikelihood = -3599.9014
Iteration 2: log pseudolikelihood = -3532.8597
Iteration 3: log pseudolikelihood = -3516.7109
Iteration 4: log pseudolikelihood = -3516.461
Iteration 5: log pseudolikelihood = -3516.5389
Iteration 6: log pseudolikelihood = -3516.549
Iteration 7: log pseudolikelihood = -3516.5504
Iteration 8: log pseudolikelihood = -3516.5506
Mixed-effects logistic regression Number of obs = 10,480
Group variable: pidp Number of groups = 2,714
Obs per group:
min = 1
avg = 3.9
max = 8
Integration method: mvaghermite Integration pts. = 7
Wald chi2(11) = 266.56
Log pseudolikelihood = -3516.5506 Prob > chi2 = 0.0000
(Std. Err. adjusted for 2,714 clusters in pidp)
--------------------------------------------------------------------------------------------
| Robust
inpov_hhld_100821 | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
---------------------------+----------------------------------------------------------------
sex |
female | 1.789139 .2355164 4.42 0.000 1.382275 2.315759
|
agegroup4 |
45-64 | 1.13456 .4149997 0.35 0.730 .553955 2.323701
65-79 | .0547238 .0219234 -7.25 0.000 .0249556 .1200008
80+ | .0520999 .0215093 -7.16 0.000 .0231964 .117018
|
1.wavediag | 1.677719 .9282099 0.94 0.350 .567265 4.961951
|
ecact_tp |
Retired | 9.572008 3.65793 5.91 0.000 4.526031 20.24364
Long-term sick/disabled | 18.79543 7.264343 7.59 0.000 8.811851 40.09014
Leave LM - other | 17.04585 8.68947 5.56 0.000 6.276266 46.2952
|
wavediag#ecact_tp |
1#Retired | .6518776 .3725532 -0.75 0.454 .2126658 1.99818
1#Long-term sick/disabled | .7497409 .4485356 -0.48 0.630 .2321006 2.421843
1#Leave LM - other | 1.234002 .9800569 0.26 0.791 .2601856 5.852598
|
_cons | .0239765 .0097814 -9.14 0.000 .0107779 .0533383
---------------------------+----------------------------------------------------------------
pidp |
var(_cons)| 8.88989 .9592592 7.195284 10.9836
--------------------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline odds (conditional on zero random effects).
.
. predict x1, mu marginal
(using 7 quadrature points)
(2666 missing values generated)
.
. table ecact_tp wavediag , c(mean x1)
--------------------------------------------
| wavediag
ecact_tp | 0 1
------------------------+-------------------
In employment | .1080621 .1253796
Retired | .1192547 .1264946
Long-term sick/disabled | .3188922 .368326
Leave LM - other | .3452236 .4367662
--------------------------------------------
.
. margins wavediag#ecact_tp, nose
Predictive margins Number of obs = 10,480
Expression : Marginal predicted mean, predict()
--------------------------------------------------------------------------------------------
| Margin
---------------------------+----------------------------------------------------------------
wavediag#ecact_tp |
0#In employment | .0499191
0#Retired | .1477018
0#Long-term sick/disabled | .1976355
0#Leave LM - other | .1899102
1#In employment | .0647358
1#Retired | .1538063
1#Long-term sick/disabled | .2162485
1#Leave LM - other | .2498774
--------------------------------------------------------------------------------------------
.Thanks,
Juliet.
0 Response to Predict and margins after melogit with interactions
Post a Comment