估算边际效应时出错

时间:2018-01-22 20:13:55

标签: statistics stata logistic-regression mlogit

我在Stata 15中检索拟合逻辑回归模型的边际效应时遇到问题。结果变量mathtsbv是二元的,性别变量sex也是虚拟和记录的种族{{1} }变量是分类的,其值范围为0到5.所有缺失值都已被排除。

以下是我的文件摘录:

eth

这是我在Stata的日志中遇到的错误:

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

我花了一个多小时谷歌搜索和试验:从模型中删除. margins, dydx(sex eth sex##i.eth) atmeans invalid dydx() option; variable sex may not be present in model as factor and continuous predictor 并仅保留sex,并将连续变量添加到预测变量列表中。不幸的是,这些都没有解决问题。

1 个答案:

答案 0 :(得分:1)

你可以计算平均边际效应的对比,它可以得到你想要的东西:当你改变一个变量时,当第二个变量发生变化时,成功概率的变化是如何变化的。

这是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
-----------------------------------------------------------------------------------------

例如,与白人相比,吸烟对体重较轻的孩子的概率低22个百分点。这种差异并不显着。

这些结果与完全饱和的OLS模型相同,您可以直接解释相互作用系数:

. 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
-------------------------------------------------------------------------------