Announcement

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

  • average marginal effects after gologit 2

    Hi there,

    I have stata 13.1 and ran gologit2. After that I tried to estimate average marginal effects, first with margins, dyxy(*), but the output does not seem to be right (and I have heared that margins after gologit2 only works with stata 14?). margeff and mfx did not work either:
    Code:
    . margeff
    -margeff- does not work with gologit2; use -mfx- instead
    
    . mfx
    default predict() is unsuitable for marginal-effect calculation
    Furthermore, I tried to estimate predicted probabilities with margins. This worked fine using the following code:
    Code:
    . margins, predict(outcome(#1))
    
    . margins, predict(outcome(#2))
    
    . margins, predict(outcome(#3))
    But specifying the at() option there is an error after the second command:
    Code:
    . margins, at(deutsch_türkisch=1) predict(outcome(#1)) ///
    >  vsquish post
    
    . margins, at(deutsch_türkisch=1) predict(outcome(#2)) ///
    >  vsquish post
    
    option at() not allowed
    r(198);
    I am not sure where I made a mistake? Does anybody have a solution for the average marginal effects and the predicted probabilities with at() option?

    Thanks in advance!

  • #2
    One thing I see is you have only one equals sign, for that command you should have two.
    i.e.
    Code:
     
     at(deutsch_türkisch=1)
    should be
    Code:
      
     at(deutsch_türkisch==1)
    not sure if that's the only problem, but it's one thing I see.

    Comment


    • #3
      Thank you for your quick answer, but this does not seem to be the problem since the first command
      Code:
       
       . margins, at(deutsch_türkisch=1) predict(outcome(#1)) /// >  vsquish post
      works all the time (with one or two equals signs). But the error message occurs after the second command
      Code:
       
       . margins, at(deutsch_türkisch=1) predict(outcome(#2)) /// >  vsquish post
      Interestingly, I can run
      Code:
       
       . margins, at(deutsch_türkisch=1) predict(outcome(#2)) /// >  vsquish post
      directly after the gologit2 command and then the error message occurs after
      Code:
       
       . margins, at(deutsch_türkisch=1) predict(outcome(#3)) /// >  vsquish post
      It seems that there is a problem with predicting more than one margin after the gologit2 command?!

      Comment


      • #4
        [QUOTE=Annabell Zentarra;n1332845]Thank you for your quick answer, but this does not seem to be the problem since the first command
        Code:
        . margins, at(deutsch_türkisch=1) predict(outcome(#1)) /// > vsquish post
        works all the time (with one or two equals signs). But the error message occurs after the second command

        You're right, sorry I was thinking about if statements, kept running into that earlier.

        Comment


        • #5
          What version of gologit2 are you using? The latest version is at SSC:

          Code:
          . which gologit2
          c:\ado\personal\gologit2.ado
          *! version 3.1.0 12may2015  Richard Williams, [email protected]
          Also for margeff,

          Code:
          . which margeff
          c:\ado\plus\m\margeff.ado
          *! Obtain partial effects after estimation
          *! Version 2.2.0  (20 August 2009)    (Revision of Stata Journal submission)
          *! Author:        Tamas Bartus        (Corvinus University, Budapest)
          If you have the latest versions of these programs and problems persist let us know. But I am guessing at least some of the problems are due to outdated software.

          gologit2 does work better in Stata 14 because you don't have to give a separate predict command for each outcome. But it should work in 13.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          StataNow Version: 19.5 MP (2 processor)

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

          Comment


          • #6
            I also wonder if there is a problem with your continuation lines. I would suggest copying and pasting all the code.
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

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

            Comment


            • #7
              Oh, the -post- options are screwing you up. The post option causes the margins results to replace the gologit2 results. Drop the post option and my guess is you will be ok. But still make sure you have the latest versions of everything.
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              StataNow Version: 19.5 MP (2 processor)

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

              Comment


              • #8
                Incidentally, for multiple outcome commands like ologit, mlogit, and gologit2, I find spost13 commands like mtable much easier to use than margins. See appendix A of

                http://www3.nd.edu/~rwilliam/xsoc73994/Ologit01.pdf

                Use -findit spost13_ado- to get the programs. Also hilgy recommended is the Long and Freese book,

                http://www.stata.com/bookstore/regre...ent-variables/

                Here is an example:

                Code:
                . webuse nhanes2f, clear
                
                . quietly gologit2 health i.female i.black c.age, auto
                
                . mtable, at(black = (0 1))
                
                Expression: Pr(health), predict(outcome())
                
                           |    black      poor      fair   average      good  excellent
                 ----------+------------------------------------------------------------
                         1 |        0     0.063     0.152     0.281     0.258      0.246
                         2 |        1     0.137     0.241     0.312     0.189      0.121
                
                Specified values where .n indicates no values specified with at()
                
                           |  No at()
                 ----------+---------
                   Current |       .n
                Last edited by Richard Williams; 27 Mar 2016, 14:42.
                -------------------------------------------
                Richard Williams, Notre Dame Dept of Sociology
                StataNow Version: 19.5 MP (2 processor)

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

                Comment


                • #9
                  Hi,

                  concerning the versions:
                  Code:
                  . which gologit2
                  c:\ado\plus\g\gologit2.ado
                  *! version 3.1.0 12may2015  Richard Williams, [email protected]
                  Code:
                  . which margeff
                  c:\ado\plus\m\margeff.ado
                  *! Obtain partial effects after estimation
                  *! Version 2.2.0  (20 August 2009)    (Revision of Stata Journal submission)
                  *! Author:        Tamas Bartus        (Corvinus University, Budapest)
                  This seems not to be the problem, this time...

                  Here is the code with the gologit2 command, the output and the margins commands with the error message:

                  Code:
                  . gologit2 swtie i.räumlicheNähe i.Elternkennensich Ptürkisch Prussisch Psonstiger Phalbdeutsch twoinstars /
                  > //
                  > twooutstars transitiveTriaden i.Mutualität zyklischeTriaden if netznum!=alteri, cluster(zahlfd) autofit
                  
                  ------------------------------------------------------------------------------
                  Testing parallel lines assumption using the .05 level of significance...
                  
                  Step  1:  Constraints for parallel lines imposed for Phalbdeutsch (P Value = 0.9250)
                  Step  2:  Constraints for parallel lines imposed for 1.Elternkennensich (P Value = 0.7989)
                  Step  3:  Constraints for parallel lines imposed for Psonstiger (P Value = 0.6495)
                  Step  4:  Constraints for parallel lines imposed for Prussisch (P Value = 0.6182)
                  Step  5:  Constraints for parallel lines imposed for Ptürkisch (P Value = 0.3067)
                  Step  6:  Constraints for parallel lines imposed for 1.Mutualität (P Value = 0.1564)
                  Step  7:  Constraints for parallel lines are not imposed for
                            1.räumlicheNähe (P Value = 0.01057)
                            twoinstars (P Value = 0.02193)
                            twooutstars (P Value = 0.00000)
                            transitiveTriaden (P Value = 0.00000)
                            zyklischeTriaden (P Value = 0.00004)
                  
                  Wald test of parallel lines assumption for the final model:
                  
                   ( 1)  [no_tie]Phalbdeutsch - [weak_tie]Phalbdeutsch = 0
                   ( 2)  [no_tie]1.Elternkennensich - [weak_tie]1.Elternkennensich = 0
                   ( 3)  [no_tie]1.Mutualität - [weak_tie]1.Mutualität = 0
                   ( 4)  [no_tie]Psonstiger - [weak_tie]Psonstiger = 0
                   ( 5)  [no_tie]Prussisch - [weak_tie]Prussisch = 0
                   ( 6)  [no_tie]Ptürkisch - [weak_tie]Ptürkisch = 0
                  
                             chi2(  6) =    5.15
                           Prob > chi2 =    0.5243
                  
                  An insignificant test statistic indicates that the final model
                  does not violate the proportional odds/ parallel lines assumption
                  
                  If you re-estimate this exact same model with gologit2, instead
                  of autofit you can save time by using the parameter
                  
                  pl(Phalbdeutsch 0b.räumlicheNähe 0b.Elternkennensich 1.Elternkennensich 0b.Mutualität 1.Mutualität Psonstige
                  > r Prussisch Ptürkisch)
                  
                  ------------------------------------------------------------------------------
                  
                  Generalized Ordered Logit Estimates               Number of obs   =      20864
                                                                    Wald chi2(16)   =    3948.31
                                                                    Prob > chi2     =     0.0000
                  Log pseudolikelihood = -10481.671                 Pseudo R2       =     0.3956
                  
                   ( 1)  [no_tie]Phalbdeutsch - [weak_tie]Phalbdeutsch = 0
                   ( 2)  [no_tie]1.Elternkennensich - [weak_tie]1.Elternkennensich = 0
                   ( 3)  [no_tie]1.Mutualität - [weak_tie]1.Mutualität = 0
                   ( 4)  [no_tie]Psonstiger - [weak_tie]Psonstiger = 0
                   ( 5)  [no_tie]Prussisch - [weak_tie]Prussisch = 0
                   ( 6)  [no_tie]Ptürkisch - [weak_tie]Ptürkisch = 0
                                                       (Std. Err. adjusted for 98 clusters in zahlfd)
                  -----------------------------------------------------------------------------------
                                    |               Robust
                              swtie |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                  ------------------+----------------------------------------------------------------
                  no_tie            |
                      räumlicheNähe |
                                 1  |   .8832655   .0571376    15.46   0.000     .7712779    .9952531
                                    |
                   Elternkennensich |
                                 1  |   2.026708    .105098    19.28   0.000      1.82072    2.232697
                                    |
                          Ptürkisch |  -.3021531   .2002011    -1.51   0.131    -.6945402    .0902339
                          Prussisch |   .0377979   .2009181     0.19   0.851    -.3559944    .4315902
                         Psonstiger |    .140975   .1742588     0.81   0.419    -.2005659    .4825159
                       Phalbdeutsch |   .3722998    .217356     1.71   0.087    -.0537101    .7983098
                         twoinstars |  -.1724737   .0190201    -9.07   0.000    -.2097524   -.1351949
                        twooutstars |  -.1314562   .0200887    -6.54   0.000    -.1708292   -.0920831
                  transitiveTriaden |   .4622529   .0182134    25.38   0.000     .4265554    .4979505
                                    |
                         Mutualität |
                                 1  |   2.130596   .0782842    27.22   0.000     1.977161     2.28403
                                    |
                   zyklischeTriaden |  -.5682154   .0346932   -16.38   0.000    -.6362129   -.5002179
                              _cons |  -2.021005   .1155638   -17.49   0.000    -2.247505   -1.794504
                  ------------------+----------------------------------------------------------------
                  weak_tie          |
                      räumlicheNähe |
                                 1  |   .9868854   .0595233    16.58   0.000      .870222    1.103549
                                    |
                   Elternkennensich |
                                 1  |   2.026708    .105098    19.28   0.000      1.82072    2.232697
                                    |
                          Ptürkisch |  -.3021531   .2002011    -1.51   0.131    -.6945402    .0902339
                          Prussisch |   .0377979   .2009181     0.19   0.851    -.3559944    .4315902
                         Psonstiger |    .140975   .1742588     0.81   0.419    -.2005659    .4825159
                       Phalbdeutsch |   .3722998    .217356     1.71   0.087    -.0537101    .7983098
                         twoinstars |  -.1499184   .0174952    -8.57   0.000    -.1842084   -.1156285
                        twooutstars |  -.2602838   .0181929   -14.31   0.000    -.2959411   -.2246264
                  transitiveTriaden |    .331938   .0160658    20.66   0.000     .3004497    .3634264
                                    |
                         Mutualität |
                                 1  |   2.130596   .0782842    27.22   0.000     1.977161     2.28403
                                    |
                   zyklischeTriaden |  -.4745311    .028381   -16.72   0.000    -.5301568   -.4189053
                              _cons |  -2.285232    .120013   -19.04   0.000    -2.520453   -2.050011
                  -----------------------------------------------------------------------------------
                  
                  WARNING! 8 in-sample cases have an outcome with a predicted probability that is
                  less than 0. See the gologit2 help section on Warning Messages for more information.
                  
                  .
                  
                  .
                  . margins, predict(outcome(#1)) post
                  
                  Predictive margins                                Number of obs   =      20864
                  Model VCE    : Robust
                  
                  Expression   : Pr(swtie==0), predict(outcome(#1))
                  
                  ------------------------------------------------------------------------------
                               |            Delta-method
                               |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                  -------------+----------------------------------------------------------------
                         _cons |   .6873241   .0020797   330.49   0.000     .6832479    .6914002
                  ------------------------------------------------------------------------------
                  
                  . margins, predict(outcome(#2)) post
                  option predict() not allowed
                  r(198);
                  
                  end of do-file
                  Thanks for your help!

                  Comment


                  • #10
                    I am surprised margeff gave you an error as it works fine for me, so long as gologit2 does not use factor variables (in which case it gives a different error). In your example, I am 99.99% sure that the problem is the use of the -post- option in margins.
                    -------------------------------------------
                    Richard Williams, Notre Dame Dept of Sociology
                    StataNow Version: 19.5 MP (2 processor)

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

                    Comment


                    • #11
                      I do use factor variables, maybe this is the problem with margeff.
                      But you are right, it was the "post" option, which was the problem with the predictions. After deleting it, everything works fine! And thanks for the mtable hint. It works fine this way:

                      Code:
                      . mtable
                      
                      Expression: Pr(swtie), predict(outcome())
                      
                        no_tie  weak_tie  strong_tie
                      ------------------------------
                         0.688     0.129       0.183
                      
                      Specified values where .n indicates no values specified with at()
                      
                                 |  No at()
                       ----------+---------
                         Current |       .n
                      But I still have some trouble with the "at" option:

                      Code:
                      . mtable, at(deutsch_türkisch = (0 1))
                      invalid syntax
                      r(198);
                      Regarding AME´s, I guess the margins, dydx(*) worked after all. I was a bit puzzled since the effects were all in the opposite direction. But of course, gologit2 takes the last category as a "base", right!? Then, it would make sense.

                      Comment


                      • #12
                        This is a very strange thing. I used the "command" option to get the margin commands mtable uses:
                        Code:
                        . mtable, at(deutsch_türkisch=(0 1)) commands
                        
                        Command: margins, at(deutsch_türkisch=(0 1)) expression(predict(outcome(0)))
                        
                        Command: margins, at(deutsch_türkisch=(0 1)) expression(predict(outcome(1)))
                        
                        Command: margins, at(deutsch_türkisch=(0 1)) expression(predict(outcome(2)))
                        invalid syntax
                        r(198);
                        now, I take the margins commands and try the calculation:
                        Code:
                        . margins, at(deutsch_türkisch=(0 1)) expression(predict(outcome(0)))
                        
                        Predictive margins                                Number of obs   =      20864
                        Model VCE    : Robust
                        
                        Expression   : Pr(swtie==0), predict(outcome(0))
                        
                        1._at        : deutsch_türkisch=           0
                        
                        2._at        : deutsch_türkisch=           1
                        
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                                 _at |
                                  1  |   .6862044   .0028501   240.76   0.000     .6806183    .6917905
                                  2  |   .7214139   .0095285    75.71   0.000     .7027383    .7400894
                        ------------------------------------------------------------------------------
                        
                        . margins, at(deutsch_türkisch=(0 1)) expression(predict(outcome(1)))
                        
                        Predictive margins                                Number of obs   =      20864
                        Model VCE    : Robust
                        
                        Expression   : Pr(swtie==1), predict(outcome(1))
                        
                        1._at        : deutsch_türkisch=           0
                        
                        2._at        : deutsch_türkisch=           1
                        
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                                 _at |
                                  1  |   .1295872   .0029382    44.10   0.000     .1238285    .1353459
                                  2  |   .1240195   .0033671    36.83   0.000     .1174201     .130619
                        ------------------------------------------------------------------------------
                        
                        . margins, at(deutsch_türkisch=(0 1)) expression(predict(outcome(2)))
                        
                        Predictive margins                                Number of obs   =      20864
                        Model VCE    : Robust
                        
                        Expression   : Pr(swtie==2), predict(outcome(2))
                        
                        1._at        : deutsch_türkisch=           0
                        
                        2._at        : deutsch_türkisch=           1
                        
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                                 _at |
                                  1  |   .1842085   .0029326    62.81   0.000     .1784607    .1899562
                                  2  |   .1545666   .0077326    19.99   0.000      .139411    .1697223
                        ------------------------------------------------------------------------------
                        There must be a problem with the mtable command in my case.

                        Comment


                        • #13
                          mtable will be using zillions of other commands besides margins. If you specify -set more off- and -set trace on- before the mtable command you may be able to see what is causing the error.

                          I wonder if your varnames are causing problems, e.g. deutsch_türkisch. Maybe try renaming to x1, x2, etc., and see if that works.

                          Or, try just running an ologit model instead and see if mtable has the same problems. if not, maybe there is some problem with the interaction of gologit2 and mtable.

                          If you can't get it to work, if you are free to share your data and code with me I will take a look.
                          -------------------------------------------
                          Richard Williams, Notre Dame Dept of Sociology
                          StataNow Version: 19.5 MP (2 processor)

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

                          Comment


                          • #14
                            Regarding AME´s, I guess the margins, dydx(*) worked after all. I was a bit puzzled since the effects were all in the opposite direction. But of course, gologit2 takes the last category as a "base", right!? Then, it would make sense.
                            No, there isn't a base category. See the troubleshooting FAQ: http://www3.nd.edu/~rwilliam/gologit2/tsfaq.html . It says

                            How do I change the base category in gologit2? You can't (although you could reverse the coding of your dependent variable if you liked that better). Suppose your dependent variable has four categories. Although the gologit2 output looks a lot like mlogit output, it doesn't make any sense to think of there being a single "base" category. Rather, the gologit results are like a series of logistic regressions. In the first panel, it is like a logistic regression where category 1 = 0 and categories 2, 3, 4 = 1. In the 2nd panel, it is 1 & 2 = 0 and 3, 4 = 1. 3rd panel, 1, 2, 3 = 0, 4 = 1. There is no 4th panel because if there were it would be like 1, 2, 3, 4 = 0, nothing equals 1. If the assumptions of the ordered logit model are met, the coefficients should all be the same in each panel (except for the intercepts). For more, see section 3.1 of my Stata Journal article.


                            -------------------------------------------
                            Richard Williams, Notre Dame Dept of Sociology
                            StataNow Version: 19.5 MP (2 processor)

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

                            Comment


                            • #15
                              As for dydx, there have to be sign flips in a multiple outcome model. If something increases the likelihood of being in one category there have to be offsetting decreases in other categories. This isn't unique to gologit2; you'll see the same sort of things for ologit and mlogit. For example,


                              Code:
                              . webuse nhanes2f, clear
                              
                              . quietly gologit2 health i.female i.black weight, auto
                              
                              . mtable, dydx(black)
                              
                              Expression: Marginal effect of Pr(health), predict(outcome())
                              
                                  poor      fair   average      good  excellent
                              -------------------------------------------------
                                 0.060     0.087     0.027    -0.065     -0.108
                              
                              Specified values where .n indicates no values specified with at()
                              So, in the above example, blacks are more likely to be in poor, fair, or average health than are whites, and less likely to have good or excellent health. If I instead use mlogit,

                              Code:
                              . webuse nhanes2f, clear
                              
                              . quietly mlogit health i.female i.black weight
                              
                              . mtable, dydx(black)
                              
                              Expression: Marginal effect of Pr(health), predict(outcome())
                              
                                  poor      fair   average      good  excellent
                              -------------------------------------------------
                                 0.070     0.063     0.051    -0.077     -0.106
                              similar things happen.


                              -------------------------------------------
                              Richard Williams, Notre Dame Dept of Sociology
                              StataNow Version: 19.5 MP (2 processor)

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

                              Comment

                              Working...
                              X