社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Git

Stata学习:如何构建多元Logit模型?

Stata与R学习 • 2 年前 • 221 次点击  

文献来源

  1. Ma, W., et al. (2022). Rural income growth, ethnic differences, and household cooking fuel choice: Evidence from China
    1. Appendix B. Supplementary data【数据+Stata】

示例代码

  • 注:参数b(1)表示Base = Quintile 1
use "C:\Download\1-s2.0-S014098832200038X-mmc1\data.dta"
keep if utype == 1
mlogit energy q_2 q_3 q_4 q_5 f_minzudummy minzuq_2 minzuq_3 minzuq_4 minzuq_5 hhage hhgender hhedustage hhsize f_dependencyratio percept_air asset_car distance_county east middle, b(1)
margins, dydx(*)

得到结果




    
Iteration 0:   log likelihood = -6949.9061  
Iteration 1:   log likelihood = -6146.9848  
Iteration 2:   log likelihood = -6121.4034  
Iteration 3:   log likelihood = -6121.2541  
Iteration 4:   log likelihood =  -6121.254  

Multinomial logistic regression                        Number of obs =   6,461
                                                       LR chi2(38)   = 1657.30
                                                       Prob > chi2   =  0.0000
Log likelihood = -6121.254                             Pseudo R2     =  0.1192

-----------------------------------------------------------------------------------
           energy | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
------------------+----------------------------------------------------------------
dirtyonly         |
              q_2 |  -.2599817   .1017211    -2.56   0.011    -.4593513   -.0606121
              q_3 |  -.6241438   .1221168    -5.11   0.000    -.8634883   -.3847993
              q_4 |  -.6980468   .1179335    -5.92   0.000    -.9291921   -.4669014
              q_5 |  -.8656507   .1424867    -6.08   0.000    -1.144919   -.5863819
     f_minzudummy |  -.2634868    .156156    -1.69   0.092    -.5695469    .0425733
         minzuq_2 |   .0828505   .2134944     0.39   0.698    -.3355907    .5012918
         minzuq_3 |    .082414   .2871114     0.29   0.774    -.4803139    .6451419
         minzuq_4 |   .5413588   .2844655     1.90   0.057    -.0161834    1.098901
         minzuq_5 |  -.2096055   .4112672    -0.51   0.610    -1.015674    .5964634
            hhage |  -.0084841   .0032031    -2.65   0.008     -.014762   -.0022061
         hhgender |   .0976351   .1244575     0.78   0.433    -.1462971    .3415674
       hhedustage |  -.1447357   .0378025    -3.83   0.000    -.2188273   -.0706441
           hhsize |  -.1098006   .0175959    -6.24   0.000     -.144288   -.0753132
f_dependencyratio |  -.0382551   .0672515    -0.57   0.569    -.1700655    .0935554
      percept_air |  -.2147999   .0474945    -4.52   0.000    -.3078875   -.1217123
        asset_car |   .0424943   .1234936     0.34   0.731    -.1995487    .2845373
  distance_county |   .0020541   .0014479     1.42   0.156    -.0007838     .004892
             east |  -.6488415   .0928188    -6.99   0.000     -.830763   -.4669199
           middle |   .1468132   .0846518     1.73   0.083    -.0191013    .3127277
            _cons |   1.671943    .277405     6.03   0.000     1.128239    2.215647
------------------+----------------------------------------------------------------
mixenergy         |  (base outcome)
------------------+----------------------------------------------------------------
cleanonly         |
              q_2 |   .1581553    .108178     1.46   0.144    -.0538697    .3701802
              q_3 |   .2829591   .1165275     2.43   0.015     .0545695    .5113488
              q_4 |   .5501665   .1085406     5.07   0.000     .3374309    .7629021
              q_5 |   .8178368   .1166754     7.01   0.000     .5891573    1.046516
     f_minzudummy |   -.427302   .2147871    -1.99   0.047     -.848277    -.006327
         minzuq_2 |    .092752   .2753566     0.34   0.736     -.446937     .632441
         minzuq_3 |   .0519216   .3217973     0.16   0.872    -.5787895    .6826328
         minzuq_4 |   .5251888   .3011482     1.74   0.081    -.0650508    1.115428
         minzuq_5 |   .6556076   .3163719     2.07   0.038       .03553    1.275685
            hhage |  -.0286874   .0029337    -9.78   0.000    -.0344372   -.0229375
         hhgender |  -.1810994   .1099555    -1.65   0.100    -.3966083    .0344095
       hhedustage |   .0940326   .0294905     3.19   0.001     .0362322    .1518329
           hhsize |  -.0229626   .0159914    -1.44   0.151    -.0543052      .00838
f_dependencyratio |  -.1988339   .0676357    -2.94   0.003    -.3313975   -.0662703
      percept_air |   .2727867   .0381119     7.16   0.000     .1980887    .3474846
        asset_car |   .6609623   .0888324     7.44   0.000     .4868539    .8350706
  distance_county |   -.010092   .0015752    -6.41   0.000    -.0131794   -.0070047
             east |   .5834746   .0800175     7.29   0.000     .4266431    .7403061
           middle |   .1971282   .0878649     2.24   0.025     .0249162    .3693402
            _cons |   .7269859   .2544304     2.86   0.004     .2283114     1.22566
-----------------------------------------------------------------------------------

. margins,  dydx(*)

Average marginal effects                                 Number of obs = 6,461
Model VCE: OIM

dy/dx wrt: q_2 q_3 q_4 q_5 f_minzudummy minzuq_2 minzuq_3 minzuq_4 minzuq_5 hhage hhgender
           hhedustage hhsize f_dependencyratio percept_air asset_car distance_county east
           middle

1._predict: Pr(energy==dirtyonly), predict(pr outcome(0))
2._predict: Pr(energy==mixenergy), predict(pr outcome(1))
3._predict: Pr(energy==cleanonly), predict(pr outcome(2))

-----------------------------------------------------------------------------------
                  |            Delta-method
                  |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
------------------+----------------------------------------------------------------
q_2               |
         _predict |
               1  |   -.051856   .0147885    -3.51   0.000    -.0808408   -.0228711
               2  |   .0038011   .0193489     0.20   0.844    -.0341221    .0417244
               3  |   .0480548   .0192442     2.50   0.013     .0103369    .0857728
------------------+----------------------------------------------------------------
q_3               |
         _predict |
               1  |   -.118007   .0176868    -6.67   0.000    -.1526725   -.0833416
               2  |   .0213712   .0215149     0.99   0.321    -.0207972    .0635397
               3  |   .0966358    .020669     4.68   0.000     .0561252    .1371463
------------------+----------------------------------------------------------------
q_4               |
         _predict |
               1  |  -.1476476   .0168663    -8.75   0.000    -.1807049   -.1145902
               2  |  -.0056852   .0202585    -0.28   0.779    -.0453911    .0340208
               3  |   .1533327   .0189478     8.09   0.000     .1161957    .1904697
------------------+----------------------------------------------------------------
q_5               |
         _predict |
               1  |  -.1921873   .0203257    -9.46   0.000    -.2320249   -.1523496
               2  |  -.0242138   .0228152    -1.06   0.289    -.0689309    .0205032
               3  |   .2164011   .0200938    10.77   0.000     .1770179    .2557843
------------------+----------------------------------------------------------------
f_minzudummy      |
         _predict |
               1  |  -.0131625   .0241929    -0.54   0.586    -.0605797    .0342546
               2  |   .0782415   .0346283     2.26   0.024     .0103713    .1461117
               3  |   -.065079   .0393869    -1.65   0.098     -.142276     .012118
------------------+----------------------------------------------------------------
minzuq_2          |
         _predict |
               1  |   .0069283   .0326446     0.21   0.832     -.057054    .0709106
               2  |  -.0193345   .0453767    -0.43   0.670    -.1082712    .0696021
               3  |   .0124062   .0503209     0.25   0.805    -.0862209    .1110334
------------------+----------------------------------------------------------------
minzuq_3          |
         _predict |
               1  |   .0095963   .0436439     0.22   0.826    -.0759441    .0951368
               2  |  -.0141254   .0551897    -0.26   0.798    -.1222953    .0940445
               3  |   .0045291   .0589683     0.08   0.939    -.1110466    .1201047
------------------+----------------------------------------------------------------
minzuq_4          |
         _predict |
               1  |    .050692   .0414248     1.22   0.221    -.0304992    .1318831
               2  |  -.1160971   .0540506    -2.15   0.032    -.2220344   -.0101597
               3  |   .0654051   .0536277     1.22   0.223    -.0397033    .1705135
------------------+----------------------------------------------------------------
minzuq_5          |
         _predict |
               1  |  -.0772121   .0613803    -1.26   0.208    -.1975152    .0430911
               2  |  -.0637928   .0635908    -1.00   0.316    -.1884285    .0608428
               3  |   .1410049   .0579733     2.43   0.015     .0273794    .2546304
------------------+----------------------------------------------------------------
hhage             |
         _predict |
               1  |    .000577   .0004654     1.24   0.215    -.0003351    .0014891
               2  |   .0044093   .0005419     8.14   0.000     .0033471    .0054714
               3  |  -.0049863   .0005124    -9.73   0.000    -.0059906   -.0039819
------------------+----------------------------------------------------------------
hhgender          |
         _predict |
               1  |   .0276335   .0182285     1.52   0.130    -.0080937    .0633607
               2  |   .0139804   .0210965     0.66   0.508     -.027368    .0553288
               3  |  -.0416139   .0196439    -2.12   0.034    -.0801153   -.0031125
------------------+----------------------------------------------------------------
hhedustage        |
         _predict |
               1  |  -.0292702   .0055637    -5.26   0.000     -.040175   -.0183655
               2  |   .0013584   .0059056     0.23   0.818    -.0102163    .0129331
               3  |   .0279118    .005311     5.26   0.000     .0175025    .0383211
------------------+----------------------------------------------------------------
hhsize            |
         _predict |
               1  |  -.0158834   .0026075    -6.09   0.000    -.0209941   -.0107727
               2  |   .0129688   .0029514     4.39   0.000     .0071842    .0187533
               3  |   .0029146   .0029104     1.00   0.317    -.0027897     .008619
------------------+----------------------------------------------------------------
f_dependencyratio |
         _predict |
               1  |   .0072598   .0100843     0.72   0.472     -.012505    .0270247
               2  |    .028678    .012095     2.37   0.018     .0049723    .0523837
               3  |  -.0359378   .0123069    -2.92   0.003    -.0600589   -.0118167
------------------+----------------------------------------------------------------
percept_air       |
         _predict |
               1  |  -.0523716   .0068692    -7.62   0.000    -.0658349   -.0389084
               2  |  -.0148515   .0075147    -1.98   0.048      -.02958   -.0001231
               3  |   .0672232   .0066579    10.10   0.000     .0541739    .0802724
------------------+----------------------------------------------------------------
asset_car         |
         _predict |
               1  |  -.0375687   .0177926    -2.11   0.035    -.0724416   -.0026957
               2  |  -.0875721   .0188577    -4.64   0.000    -.1245326   -.0506117
               3  |   .1251408   .0153141     8.17   0.000     .0951256     .155156
------------------+----------------------------------------------------------------
distance_county   |
         _predict |
               1  |   .0010025   .0002128     4.71   0.000     .0005855    .0014195
               2  |   .0010894   .0002746     3.97   0.000     .0005512    .0016277
               3  |  -.0020919   .0002802    -7.47   0.000    -.0026411   -.0015428
------------------+----------------------------------------------------------------
east              |
         _predict |
               1  |  -.1420728   .0132295   -10.74   0.000    -.1680022   -.1161435
               2  |   -.014411    .015209    -0.95   0.343    -.0442201    .0153982
               3  |   .1564838   .0137883    11.35   0.000     .1294592    .1835083
------------------+----------------------------------------------------------------
middle            |
         _predict |
               1  |   .0100802   .0122624     0.82   0.411    -.0139536     .034114
               2  |  -.0384099   .0159192    -2.41   0.016    -.0696109   -.0072088
               3  |   .0283297    .015573     1.82   0.069    -.0021928    .0588521
-----------------------------------------------------------------------------------

(完)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/159358