0

I have a problem in retrieving marginal effects for a fitted logistic regression model in Stata 15. The outcome variable mathtsbv is binary, a gender variable sex is also dummy and recorded ethnicity eth variable is categorical with values ranging from 0 to 5. All missing values have been excluded.

Here is an excerpt from my do-file:

logit mathtsbv sex eth sex##i.eth if (mathtsbv>=0&mathtsbv<.)&(sex>=0&sex<.)&(eth>=0&eth<.)
margins, dydx(sex eth sex##i.eth) atmeans

This is the error I get in Stata's logs:

. margins, dydx(sex eth sex##i.eth) atmeans
    invalid dydx() option;
    variable sex may not be present in model as factor and continuous predictor

I spent more than an hour Googling and experimenting: removing sex from the model and keeping only eth, and adding a continuous variable to the list of predictors. Unfortunately none of those brought a problem resolution.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
Ruslan Seletskiy
  • 309
  • 3
  • 14
  • After rechecking details online, I have found that TATA can not produce marginal effects for interaction terms: the value of interaction terms depends on values of its components and thus this is not possible to estimate a "separate" effect for it. However, I am still not sure. Anyway, hope this may help community members in the future. – Ruslan Seletskiy Jan 22 '18 at 20:54
  • You might find [this post useful](https://stats.stackexchange.com/questions/89810/understanding-standard-errors-in-logistic-regression/89980#89980). – dimitriy Jan 22 '18 at 21:22

1 Answers1

1

You can calculate contrasts of average marginal effects that will get you something similar to what you want: how does the change in probability of success when you alter one variable vary when a second variable changes.

Here's a replicable example in Stata:

. webuse lbw, clear
(Hosmer & Lemeshow data)

. qui logit low i.smoke##i.race

. margins r.smoke#r.race

Contrasts of adjusted predictions
Model VCE    : OIM

Expression   : Pr(low), predict()

---------------------------------------------------------------------------
                                        |         df        chi2     P>chi2
----------------------------------------+----------------------------------
                             smoke#race |
(smoker vs nonsmoker) (black vs white)  |          1        0.00     0.9504
(smoker vs nonsmoker) (other vs white)  |          1        1.59     0.2070
                                 Joint  |          2        1.67     0.4332
---------------------------------------------------------------------------

-----------------------------------------------------------------------------------------
                                        |            Delta-method
                                        |   Contrast   Std. Err.     [95% Conf. Interval]
----------------------------------------+------------------------------------------------
                             smoke#race |
(smoker vs nonsmoker) (black vs white)  |   .0130245   .2092014     -.3970027    .4230517
(smoker vs nonsmoker) (other vs white)  |  -.2214452   .1754978     -.5654146    .1225242
-----------------------------------------------------------------------------------------

For example, the effect of smoking on the probability of having a low weight child is 22 percentage points lower for other compared to white. This difference is not significant.

These results are identical to what you would get with a fully saturated OLS model where you can interpret the interaction coefficients directly:

. reg low i.smoke##i.race, robust

Linear regression                               Number of obs     =        189
                                                F(5, 183)         =       5.09
                                                Prob > F          =     0.0002
                                                R-squared         =     0.0839
                                                Root MSE          =     .45072

-------------------------------------------------------------------------------
              |               Robust
          low |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
        smoke |
      smoker  |   .2744755   .0809029     3.39   0.001     .1148531    .4340979
              |
         race |
       black  |   .2215909   .1257293     1.76   0.080    -.0264745    .4696563
       other  |   .2727273   .0792791     3.44   0.001     .1163086    .4291459
              |
   smoke#race |
smoker#black  |   .0130245   .2126033     0.06   0.951    -.4064443    .4324933
smoker#other  |  -.2214452   .1783516    -1.24   0.216    -.5733351    .1304447
              |
        _cons |   .0909091    .044044     2.06   0.040     .0040098    .1778083
-------------------------------------------------------------------------------
dimitriy
  • 9,077
  • 2
  • 25
  • 50