Announcement

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

  • Testing for difference in marginal effects at two values of same continuous independent variable

    Hi all, and thanks in advance for any responses.

    I'm estimating the following model: mlogit enroll_method ses_index2 i.race2 physical2 emotion2 i.enroll_site enroll_age i.period, vce(robust), where enroll_method is one of six contraceptive methods selected at enrollment in a study and ses_index2 is a composite index with continuous values.

    For each enroll_method, I have run the margins command to get the predicted probability at the 10th and 90th percentile values of the ses_index2:
    margins, at(ses_index2=(1 6)) predict(outcome(2))

    For this example I get the following results:

    Predictive margins Number of obs = 12,316
    Model VCE : Robust

    Expression : Pr(enroll_method==2), predict(outcome(2))

    1._at : ses_index2 = 1

    2._at : ses_index2 = 6

    ------------------------------------------------------------------------------
    | Delta-method
    | Margin Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    _at |
    1 | .1607696 .004946 32.50 0.000 .1510756 .1704636
    2 | .114489 .0061308 18.67 0.000 .102473 .1265051
    ------------------------------------------------------------------------------


    I now want to test whether .1607696 is significantly different than .114489, but am having trouble finding sufficient documentation to do this on (1) a continuous independent variable and (2) for different values of the same independent variable.

    Any and all advice would be deeply appreciated!
    Best,
    Kelsey

  • #2
    I recommend to use - margins - plus - contrast - for that matter. Use the categorical variable such as "r.var" for that matter.
    Best regards,

    Marcos

    Comment


    • #3
      You can accomplish this in at least two ways:

      Code:
      cls
      webuse sysdsn1
      mlogit insure age male nonwhite i.site
      
      /* one-step contrasts of margins method, but has confusing syntax */
      margins, at(age = (20 40)) predict(outcome(2)) contrast(atcontrast(r._at) wald)
      // or use contrast(atcontrast(a._at) wald) to flip the sign
      
      /* two-step method: post margins results to make them behave like estimation results and then test */
      margins, at(age = (20 40)) predict(outcome(2)) post
      test _b[1._at] == _b[2._at]

      Comment


      • #4
        Hi Dimitriy. If I follow, your code in #3 is generates a test contrasting two predicted probabilities. Is there a way to include xb somewhere to get a contrast of the log-odds?

        Thanks,
        Bruce
        --
        Bruce Weaver
        Email: [email protected]
        Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
        Version: Stata/MP 18.0 (Windows)

        Comment


        • #5
          Bruce Weaver, I think changing the predict() option should do it:

          Code:
          margins, at(age = (20 40)) predict(xb outcome(2)) contrast(atcontrast(r._at) wald)
          -pr- is the default, so I omitted it above.
          Last edited by Dimitriy V. Masterov; 14 Jun 2019, 15:44.

          Comment


          • #6
            Hi Dimitriy. That's more or less what I was trying without success. Tacking that line on to the end of your code in #3 is generating an error:

            Code:
            . margins, at(age = (20 40)) predict(outcome(2) xb) contrast(atcontrast(r._at) wald)
            option at() not allowed
            r(198);
            Code:
            search for r(198)                                                        (manual:  [R] search)
            ----------------------------------------------------------------------------------------------
            
            Search of official help files, FAQs, Examples, SJs, and STBs
            
            [P]     error . . . . . . . . . . . . . . . . . . . . . . . .  Return code 198
                    invalid syntax
                    option __________ incorrectly specified
                    option __________ not allowed
                    __________ invalid
                    range invalid
                    __________ invalid obs no
                    invalid filename
                    __________ invalid varname
                    __________ invalid name
                    multiple by's not allowed
                    __________ found where number expected
                    on or off required
                    All items in this list indicate invalid syntax.  These errors
                    are often, but not always, due to typographical errors.  Stata
                    attempts to provide you with as much information as it can.
                    Review the syntax diagram for the designated command.
                     
                    In giving the message "invalid syntax", Stata is not helpful.
                    Errors in specifying expressions often result in this message.
            
            (end of search)

            --
            Bruce Weaver
            Email: [email protected]
            Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
            Version: Stata/MP 18.0 (Windows)

            Comment


            • #7
              That's happening because I posted the margins, which overwrites the original mlogit estimation results, which breaks the at() option. The error is not very helpful here.

              If you just re-run the mlogit it should work fine:

              Code:
              . webuse sysdsn1
              (Health insurance data)
              
              . mlogit insure age male nonwhite i.site
              
              Iteration 0:   log likelihood = -555.85446  
              Iteration 1:   log likelihood = -534.67443  
              Iteration 2:   log likelihood = -534.36284  
              Iteration 3:   log likelihood = -534.36165  
              Iteration 4:   log likelihood = -534.36165  
              
              Multinomial logistic regression                 Number of obs     =        615
                                                              LR chi2(10)       =      42.99
                                                              Prob > chi2       =     0.0000
              Log likelihood = -534.36165                     Pseudo R2         =     0.0387
              
              ------------------------------------------------------------------------------
                    insure |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
              Indemnity    |  (base outcome)
              -------------+----------------------------------------------------------------
              Prepaid      |
                       age |   -.011745   .0061946    -1.90   0.058    -.0238862    .0003962
                      male |   .5616934   .2027465     2.77   0.006     .1643175    .9590693
                  nonwhite |   .9747768   .2363213     4.12   0.000     .5115955    1.437958
                           |
                      site |
                        2  |   .1130359   .2101903     0.54   0.591    -.2989296    .5250013
                        3  |  -.5879879   .2279351    -2.58   0.010    -1.034733   -.1412433
                           |
                     _cons |   .2697127   .3284422     0.82   0.412    -.3740222    .9134476
              -------------+----------------------------------------------------------------
              Uninsure     |
                       age |  -.0077961   .0114418    -0.68   0.496    -.0302217    .0146294
                      male |   .4518496   .3674867     1.23   0.219     -.268411     1.17211
                  nonwhite |   .2170589   .4256361     0.51   0.610    -.6171725     1.05129
                           |
                      site |
                        2  |  -1.211563   .4705127    -2.57   0.010    -2.133751   -.2893747
                        3  |  -.2078123   .3662926    -0.57   0.570    -.9257327     .510108
                           |
                     _cons |  -1.286943   .5923219    -2.17   0.030    -2.447872   -.1260134
              ------------------------------------------------------------------------------
              
              . margins, at(age = (20 40)) predict(xb outcome(2)) contrast(atcontrast(r._at) wald)
              
              Contrasts of predictive margins
              Model VCE    : OIM
              
              Expression   : Linear prediction, insure==Prepaid, predict(xb outcome(2))
              
              1._at        : age             =          20
              
              2._at        : age             =          40
              
              ------------------------------------------------
                           |         df        chi2     P>chi2
              -------------+----------------------------------
                       _at |          1        3.59     0.0580
              ------------------------------------------------
              
              --------------------------------------------------------------
                           |            Delta-method
                           |   Contrast   Std. Err.     [95% Conf. Interval]
              -------------+------------------------------------------------
                       _at |
                 (2 vs 1)  |  -.2348998   .1238921     -.4777238    .0079243
              --------------------------------------------------------------
              Last edited by Dimitriy V. Masterov; 14 Jun 2019, 16:00.

              Comment


              • #8
                Ah, yes. Of course. (I'd insert a palm-to-forehead emoticon if there was one.) Thanks for that, Dimitriy.

                And if Kelsey wants the log-odds for each value of her variable, she could add another -margins- command without the contrast option.

                Code:
                clear *
                webuse sysdsn1
                mlogit insure age male nonwhite i.site
                margins, at(age = (20 40)) predict(xb outcome(2))
                margins, at(age = (20 40)) predict(xb outcome(2)) contrast(atcontrast(r._at) wald)
                margins, at(age = (20 40)) predict(xb outcome(2)) contrast(atcontrast(a._at) wald)
                --
                Bruce Weaver
                Email: [email protected]
                Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
                Version: Stata/MP 18.0 (Windows)

                Comment

                Working...
                X