I am currently in the process of figuring out the predictnl command. I am trying to present the results of a logistic regression in AME format in my regression table, and because my regression includes an interaction term, I will need the predictnl command to be able to calculate an AME "coefficient" and standard error for the interaction term in the table. In trying to do so, I have run into an issue regarding different ways of specifying interactions leading to different AMEs, however.
To illustrate my question/dilemma, I have created the following example. As you can see, all variables in question are dummy variables. I am using StataSE version 16.1.
As far as I can tell, in order to use predictnl, I need to create a new variable for my interaction:
Doing so does not change the logistic regression output when I compare models run with this "interaction" variable to models run specifying the interaction with # or ##. However, and this is where I am very confused at this point, I have noticed that different ways of specifying the interaction lead to different AMEs being predicted (I have added the value Stata predicts after each margins command below):
In class, I was taught that all of these ways of specifying the interaction should lead to the same results and they do when it comes to the log-odds predictions, but as you can see, the AMEs are different when I use the "interaction" variable (specifications 1 and 2), and also change depending on whether I add "i." in front of the dummy variables when using the interaction variable. I am inclined to trust the results of specifications 3 and 4 most, as this is how I have usually seen interactions be specified here, and because they yield the same results, but this presents me with the issue that I have to use specification 1 to be able to use predictnl in the way I want:
(Code taken from page 272 of Karaca-Mandic, P., Norton, E. C. and Dowd, B. (2012). Interaction terms in nonlinear models. Health Services Research, 47, 255–274.)
My questions are therefore (i) why do the margin command results differ when using these different interaction specifications, (ii) which AMEs should I "trust" out of the ones yielded from the 4 specifications above, and (ii) how can I use predictnl while still getting accurate results or, alternatively, how can I calculate an AME "coefficient" and standard error for the interaction term in a different way?
Any help would be much appreciated, thank you!
To illustrate my question/dilemma, I have created the following example. As you can see, all variables in question are dummy variables. I am using StataSE version 16.1.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(outcome dummy1 dummy2) 0 0 0 . 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 1 . 0 0 1 0 0 0 . . 1 0 0 0 . . 0 1 . 1 . . 0 . 1 0 0 0 1 0 1 1 0 0 . 0 0 . 0 1 0 0 0 1 1 1 0 1 1 . 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 1 0 . 0 . . 0 0 . 1 . 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 . 0 0 0 0 0 1 . . 1 1 1 1 . 0 0 0 0 1 0 0 1 0 0 1 1 . 1 0 1 0 0 . 1 . . . . . 0 1 0 0 0 0 0 0 0 0 0 0 1 . 0 1 0 . 0 0 1 0 1 0 0 0 0 1 0 0 . 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 . 1 . . . 0 0 0 0 0 0 0 . 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 . 0 1 0 0 0 1 . . 1 0 1 . . 0 1 1 0 0 1 1 . 1 0 0 . . 1 0 0 1 0 1 0 end label values outcome _statalist label values dummy1 _statalist label values dummy2 _statalist label def _statalist 0 "0", modify label def _statalist 1 "1", modify
Code:
gen interaction = dummy1*dummy2
Code:
//SPECIFICATION 1 - using "interaction" variable WITHOUT "i" in front of dummies logit outcome dummy1 dummy2 interaction margins, dydx(dummy1) at (dummy2=1) // .1562664 //SPECIFICATION 2 - using "interaction" variable WITH "i" in front of dummies logit outcome i.dummy1 i.dummy2 interaction margins, dydx(dummy1) at (dummy2=1) //.195811 //SPECIFICATION 3 - using ## logit outcome i.dummy1##i.dummy2 margins, dydx(dummy1) at (dummy2=1) //.2918876 //SPECIFICATION 4 - using # logit outcome i.dummy1 i.dummy2 i.dummy1#i.dummy2 margins, dydx(dummy1) at (dummy2=1) //.2918876
Code:
logit outcome dummy1 dummy2 interaction predictnl phat = (_b[dummy1] + _b[interaction]) * /// (1/(1+exp(- (_b[_cons] + _b[dummy1]* dummy1 + _b[dummy2] + _b[interaction]*dummy1))))* /// (1 - (1/(1+exp(-(_b[_cons]+_b[dummy1]*dummy1 + _b[dummy2] + _b[interaction]*dummy1))))) /// - _b[dummy1]*(1/(1+exp(-(_b[_cons]+_b[dummy1]*dummy1))))* /// (1-(1/(1+exp(-(_b[_cons]+_b[dummy1]*dummy1))))), se(phat_se) sum phat*
My questions are therefore (i) why do the margin command results differ when using these different interaction specifications, (ii) which AMEs should I "trust" out of the ones yielded from the 4 specifications above, and (ii) how can I use predictnl while still getting accurate results or, alternatively, how can I calculate an AME "coefficient" and standard error for the interaction term in a different way?
Any help would be much appreciated, thank you!
Comment