Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unordered multinomial logit

    Dear all.

    I have unordered data and have estimated the multinomial logit model.
    This is the example of my dataset
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long(transp_mode age_cat female) float distance_km long weather int year
    2 1 1  4.979599 2 2018
    4 1 0 18.339369 2 2018
    1 2 1 .08924986 3 2018
    1 1 1  1.104875 3 2018
    4 2 0  81.17729 3 2018
    4 1 1  7.263874 3 2018
    1 4 1 .51526684 1 2018
    4 1 0  8.373368 2 2018
    2 2 0  16.95495 1 2018
    5 2 0  2.393716 2 2018
    4 2 0  6.160923 2 2018
    5 1 0  1.087017 3 2018
    2 2 0 16.391123 2 2018
    2 3 0  7.263874 3 2018
    4 4 0  1.380034 2 2018
    2 4 0 2.8397374 1 2018
    1 1 1 .08924986 1 2018
    3 2 0 22.721685 3 2018
    4 3 0  .4328967 3 2018
    5 1 1 1.0040315 3 2018
    3 2 0 14.635754 1 2018
    5 4 0  1.295433 1 2018
    4 1 1  95.39267 3 2018
    4 1 1  95.39267 3 2018
    5 1 0  .8791119 2 2018
    4 1 0  11.43512 2 2018
    4 1 0 12.354066 2 2018
    4 2 0  1.295433 3 2018
    2 2 0  2.393716 3 2018
    2 2 1  7.994223 1 2018
    4 1 1  4.661379 2 2018
    4 1 0 174.02007 2 2018
    4 1 1  9.885872 2 2018
    4 1 1 20.233477 2 2018
    2 2 0    5.2509 1 2018
    1 2 1  .4328967 2 2018
    4 1 0  4.420173 2 2018
    2 2 1 18.761187 2 2018
    2 2 0 23.143587 2 2018
    4 3 0 28.426075 2 2018
    4 3 0 19.425905 1 2018
    5 1 0 2.2534153 2 2018
    4 1 1  9.797473 2 2018
    4 1 1 17.886116 2 2018
    5 1 0 4.3756337 1 2018
    2 3 1  86.65344 2 2018
    2 3 1 19.038084 2 2018
    2 2 0  19.25578 2 2018
    3 1 1  6.160923 1 2018
    3 3 0  25.56547 1 2018
    3 3 1  66.38572 1 2018
    5 3 1  1.232677 1 2018
    4 2 0  2.096273 1 2018
    3 2 0   16.4633 1 2018
    2 3 0 17.351875 1 2018
    4 1 0 .08924986 1 2014
    5 1 0         0 1 2014
    5 2 1         0 1 2014
    1 4 1 .08924986 1 2014
    5 2 1         0 1 2014
    5 1 0 1.5548694 1 2014
    1 1 1 .08924986 1 2014
    . 1 1 .08924986 1 2014
    1 2 1         0 1 2014
    1 1 0         0 1 2014
    5 1 1 .51526684 1 2014
    5 1 1         0 1 2014
    1 2 1 .51526684 1 2014
    4 3 1 .08924986 1 2014
    1 3 1 .08924986 1 2014
    5 2 0 4.3756337 1 2014
    5 2 0 .08924986 1 2014
    5 2 0         0 1 2014
    5 1 0 .08924986 1 2014
    4 1 1         0 1 2014
    4 2 1 .08924986 1 2014
    1 1 1 .08924986 1 2014
    4 1 1         0 1 2014
    1 1 0         0 1 2014
    3 2 1 .08924986 1 2014
    3 1 0 .08924986 1 2014
    4 1 1         0 1 2014
    1 1 0 .51526684 1 2014
    3 2 0         0 1 2014
    5 2 0 .08924986 1 2014
    1 1 0 1.5548694 3 2014
    4 2 0 .08924986 3 2014
    5 1 0 .51526684 3 2014
    3 1 1 1.5548694 3 2014
    1 1 0 .08924986 3 2014
    4 1 0         0 3 2014
    1 1 0 .08924986 3 2014
    5 2 1         0 3 2014
    5 2 1 .08924986 3 2014
    1 1 0 .08924986 3 2014
    1 1 0         0 3 2014
    4 2 1         0 3 2014
    4 1 1 .08924986 1 2014
    1 2 1 .08924986 1 2014
    5 2 1 .08924986 1 2014
    end
    label values transp_mode transp_mode_lab
    label def transp_mode_lab 1 "Bike or moped", modify
    label def transp_mode_lab 2 "Car", modify
    label def transp_mode_lab 3 "Car + Public transport", modify
    label def transp_mode_lab 4 "Public transport", modify
    label def transp_mode_lab 5 "Walking", modify
    label values age_cat age_cat
    label def age_cat 1 "18-30", modify
    label def age_cat 2 "31-50", modify
    label def age_cat 3 "51-65", modify
    label def age_cat 4 "Over 65", modify
    label values female female
    label def female 0 "male", modify
    label def female 1 "female", modify
    label values weather weather
    label def weather 1 "Cloudy", modify
    label def weather 2 "Rainy", modify
    label def weather 3 "Sunny", modify
    I have run the command
    Code:
    mlogit transp_mode i.age_cat female i.weather distance_km i.year
    And now want to calculate the conditional marginal effects for certain type of weather on the probability of using a certain transp_mode. What would be the appropriate command and perhaps someone could add in the math formula for it?
    Thank you very much for your time

    Kindest regards

  • #2
    Code:
    margins , dydx(i.weather)
    should do it. The math formulas appear in the PDF manual for the `margins` command (see `help margins`, view the PDF manual, and look at "Methods and Formulas").

    Comment


    • #3
      Thank you for the answer!

      However, this command gives me the average marginal effects. Is there a way to get conditional marginal effects for observation with certain characteristics? E.g. male/certain year/distance_traveled etc

      Comment


      • #4
        Have a look at Richard Williams' slides at https://www3.nd.edu/~rwilliam/stats/Margins01.pdf or his Stata Journal article for different ways to calculate marginal effects.

        Comment


        • #5
          Thank you for the answer!

          However, both sources only look at the logit model. The model I have in an example is a multinomial logit of which if I understand correctly (please correct me if I am wrong), marginal effects are extracted in a different manner.

          Comment


          • #6
            I do not see why it matters. For mlogit, see

            Code:
            h mlogit postestimation
            There is an example:

            sysuse auto, clear
            . mlogit rep78 mpg displ

            Compute the predicted probability at the regressors' means for each outcome
            . margins, atmeans
            and therefore instead of computing the predicted probability at the means, you could specify your own values, e.g.,

            Code:
            sysuse auto, clear
            mlogit rep78 mpg displ
            sum mpg disp
            margins, at(mpg=12 displacement=425)
            Res.:

            Code:
            . margins, at(mpg=12 displacement=425)
            
            Adjusted predictions                            Number of obs     =         69
            Model VCE    : OIM
            
            1._predict   : Pr(rep78==1), predict(pr outcome(1))
            2._predict   : Pr(rep78==2), predict(pr outcome(2))
            3._predict   : Pr(rep78==3), predict(pr outcome(3))
            4._predict   : Pr(rep78==4), predict(pr outcome(4))
            5._predict   : Pr(rep78==5), predict(pr outcome(5))
            at           : mpg             =          12
                           displacement    =         425
            
            ------------------------------------------------------------------------------
                         |            Delta-method
                         |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                _predict |
                      1  |   .0146779   .0315152     0.47   0.641    -.0470908    .0764467
                      2  |   .2334596   .1568673     1.49   0.137    -.0739947     .540914
                      3  |   .6665109   .1630082     4.09   0.000     .3470207    .9860011
                      4  |   .0851745   .0698598     1.22   0.223    -.0517481    .2220972
                      5  |    .000177   .0005446     0.32   0.745    -.0008904    .0012444
            ------------------------------------------------------------------------------


            Comment


            • #7
              This handout may also be helpful, as it talks specifically about multiple-outcome commands like mlogit and ologit:

              https://www3.nd.edu/~rwilliam/xsoc73994/Margins05.pdf

              Incidentally, the spost13 commands (described in the handout) produce nicer-looking output than margins does.

              Also, if you are condemned to using an older version of Stata (e.g. Stata 13) the necessary margins commands are a bit more tedious but still doable. This is discussed in the appendix of the handout.

              "Is there a way to get conditional marginal effects for observation with certain characteristics? E.g. male/certain year/distance_traveled etc"

              The spost13 command mtable (discussed in the handout) provides an easy way to do this, although you could also just use the margins command.
              Last edited by Richard Williams; 07 Dec 2022, 05:38.
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              Stata Version: 17.0 MP (2 processor)

              EMAIL: [email protected]
              WWW: https://www3.nd.edu/~rwilliam

              Comment

              Working...
              X