Announcement

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

  • mfx and margins yield different results?

    I recently started using margins (slow upgrade to the post-stata 10 world), and tried to re-write some of the old .do files. It turns out that I had trouble getting the same results by using mfx and margins.
    I ran a relatively simple logit regression using the old "mfx" command first, and the commands and results look like:

    commands:
    logistic compaper insider oncestock later i.occucode, robust
    mfx

    results:

    logistic compaper insider oncestock later i.occucode, robust
    i.occucode _Ioccucode_1-9 (naturally coded; _Ioccucode_5 omitted)

    Logistic regression Number of obs = 2908
    Wald chi2(7) = 653.70
    Prob > chi2 = 0.0000
    Log pseudolikelihood = -1443.3277 Pseudo R2 = 0.2347


    Robust
    compaper Odds Ratio Std. Err. z P>z [95% Conf. Interval]

    insider 1.338362 .2074708 1.88 0.060 .9876923 1.813533
    oncestock 1.253733 .1549868 1.83 0.067 .9839642 1.597463
    later 3.360304 .4007488 10.16 0.000 2.659895 4.245146
    _Ioccucode_1 .1455745 .0373587 -7.51 0.000 .0880323 .2407291
    _Ioccucode_2 .6183545 .0827797 -3.59 0.000 .4756488 .8038752
    _Ioccucode_8 8.142382 1.246059 13.70 0.000 6.032384 10.99041
    _Ioccucode_9 .1708144 .0351556 -8.59 0.000 .1141136 .2556887
    _cons .2302005 .0236327 -14.31 0.000 .1882437 .2815087


    . mfx

    Marginal effects after logistic
    y = Pr(compaper) (predict)
    = .32067289

    variable dy/dx Std. Err. z P>z [ 95% C.I. ] X

    insider* .0659358 .03623 1.82 0.069 -.005075 .136947 .096974
    oncest~k* .0502987 .02797 1.80 0.072 -.004522 .105119 .223177
    later* .2475381 .02154 11.49 0.000 .205318 .289758 .605571
    _Ioccu~1* -.2819143 .02058 -13.70 0.000 -.322246 -.241582 .083219
    _Ioccu~2* -.0979491 .02522 -3.88 0.000 -.147373 -.048525 .158528
    _Ioccu~8* .4806974 .03001 16.02 0.000 .421881 .539514 .168845
    _Ioccu~9* -.2778684 .01988 -13.98 0.000 -.316836 -.238901 .120014

    (*) dy/dx is for discrete change of dummy variable from 0 to 1


    Then I tried the margins:
    commands:
    logistic compaper i.insider i.oncestock i.later ib5.occucode, robust
    margins, dydx(insider oncestock later occucode)


    Results:
    Logistic regression Number of obs = 2908
    Wald chi2(7) = 653.70
    Prob > chi2 = 0.0000
    Log pseudolikelihood = -1443.3277 Pseudo R2 = 0.2347


    Robust
    compaper Odds Ratio Std. Err. z P>z [95% Conf. Interval]

    1.insider 1.338362 .2074708 1.88 0.060 .9876923 1.813533
    1.oncestock 1.253733 .1549868 1.83 0.067 .9839642 1.597463
    1.later 3.360304 .4007488 10.16 0.000 2.659895 4.245146

    occucode
    1 .1455745 .0373587 -7.51 0.000 .0880323 .2407291
    2 .6183545 .0827797 -3.59 0.000 .4756488 .8038752
    8 8.142382 1.246059 13.70 0.000 6.032384 10.99041
    9 .1708144 .0351556 -8.59 0.000 .1141136 .2556887

    _cons .2302005 .0236327 -14.31 0.000 .1882437 .2815087


    . margins, dydx(insider oncestock later occucode)

    Average marginal effects Number of obs = 2908
    Model VCE : Robust

    Expression : Pr(compaper), predict()
    dy/dx w.r.t. : 1.insider 1.oncestock 1.later 1.occucode 2.occucode 8.occucode
    9.occucode


    Delta-method
    dy/dx Std. Err. z P>z [95% Conf. Interval]

    1.insider .0485594 .0264908 1.83 0.067 -.0033615 .1004803
    1.oncestock .0370138 .0203009 1.82 0.068 -.0027752 .0768028
    1.later .2052595 .0198058 10.36 0.000 .1664409 .2440782

    occucode
    1 -.2745338 .0233213 -11.77 0.000 -.3202427 -.2288248
    2 -.0955908 .0255189 -3.75 0.000 -.145607 -.0455747
    8 .439998 .0285118 15.43 0.000 .384116 .49588
    9 -.2623443 .0221572 -11.84 0.000 -.3057715 -.2189171

    Note: dy/dx for factor levels is the discrete change from the base level.

    I have a hard time understanding why these two methods gave pretty different results. I'm pretty sure I made a mistake somewhere in the syntax for margins, but have a hard time figuring it out. Thanks for your time in advance!





  • #2
    First off, this would be much easier to read if you used code tags instead of just changing the font. See pt. 12 of the FAQ.

    Second, I suspect you are not showing us exactly what you typed, as the first set of output looks like you used xi:

    Finally, for an explanation of why margins is superior to older commands like mfx (and can give different results) see

    http://www3.nd.edu/~rwilliam/stats3/Margins01.pdf

    One difference is that mfx will give marginal effects at the means while margins (by default) will give average marginal effects.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

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

    Comment


    • #3
      I have used margins and mfx ofcourse as discussed the results are different. I am facing two problems with my oprobit model.
      1. Which one is better margins or mfx. I am unable to find why I should be using margins and why not mfx.
      2. if Margins how should I predict outcome of only highest category. (My dependent variable has 5 categories).
      Additionally, I am using eststo for storring my marginal effects but when I esttab the results to an excel file, I found that b-coefficient from oprobit model and not the marginal effects are stored.

      It will be great if this could be solved.

      Thanks & Regards,

      Comment


      • #4
        #1 is already addressed by Richard's reply in #2.

        2. if Margins how should I predict outcome of only highest category. (My dependent variable has 5 categories).
        Additionally, I am using eststo for storring my marginal effects but when I esttab the results to an excel file, I found that b-coefficient from oprobit model and not the marginal effects are stored.
        You need to include the -post- option of margins to post the results to e(b) and e(V). Then estout (SSC) can pick them up from there. Assuming that the highest category is coded 5:

        Code:
        margins, dydx(*) predict(outcome(5)) post

        Comment


        • #5
          Andrew Musau thank you so much this worked.

          Comment

          Working...
          X