Announcement

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

  • Marginal effects Tobit (mfx vs margins)

    Hello
    I'm trying to calculate the marginal effects of a Tobit model using the margins command instead of mfx, because margins is faster and mfx is a discontinued command.

    Tobit models have 3 marginal effects, the marginal effect on probability at the truncated point, the conditional marginal effect and the unconditional marginal effect. For each one I used mfx with the following options

    Code:
    mfx            compute, predict (p(0,.))
    mfx            compute, predict (e(0,.))
    mfx            compute, predict (ys(0,.))
    I am trying to replicate the results using margins, following the same order of marginal effects my syntax is as follows:

    Code:
    margins            , dydx(*) predict(p(0,.))
    margins            , dydx(*) predict(e(0,.))
    margins            , dydx(*) predict(ystar(0,.))
    The marginal effects I get with margins are similar to those I get with mfx, but not the same. I'm not sure if I'm using the wrong option.
    Any help is welcome, thank you

  • #2
    Ricardo: The default for mfx is to evaluate the derivative or change at the means of the rhs variables, whereas margins, dydx(*) computes the average (perhaps weighted) of each observation's derivative or change. Since Tobit is nonlinear in covariates and parameters these two quantities will not generally coincide. You can force margins to mimic mfx and evaluate at the rhs variables' means if you wish, so as a general matter margins is a far more versatile tool than is mfx.

    Comment


    • #3
      You can probably just add the atmeans option to margins. But I like AMEs, the default for margins, better than MEMs better anyway.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

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

      Comment


      • #4
        Hi
        Thank to both, I run the ME using margins with the atmeans options and now the results between mfx and margins are very similar

        Code:
        . mfx                     compute, predict (e(0,.))
        
        Marginal effects after tobit
              y  = E(whrs|whrs>0) (predict, e(0,.))
                 =   22.03211
        ------------------------------------------------------------------------------
        variable |      dy/dx    Std. Err.     z    P>|z|  [    95% C.I.   ]      X
        ---------+--------------------------------------------------------------------
          female*|  -2.016846      .10421  -19.35   0.000   -2.2211 -1.81259   .479272
             age |    2.01746       .0477   42.30   0.000   1.92397  2.11095   13.4481
           atth2*|  -2.069747      .11371  -18.20   0.000  -2.29262 -1.84687   .349267
           atth3*|  -2.885447      .15056  -19.16   0.000  -3.18054 -2.59035   .140103
           atth4*|  -3.957135      .15855  -24.96   0.000  -4.26789 -3.64638   .164843
           atth5*|  -3.512118      .24471  -14.35   0.000  -3.99174 -3.03249    .05109
         femaleh*|   1.584907      .17967    8.82   0.000   1.23276  1.93705   .083554
           rural*|   2.928137      .12399   23.62   0.000   2.68513  3.17115   .619443
         region2*|   .5115345      .13746    3.72   0.000   .242117  .780952     .3111
         region3*|   2.096724      .17684   11.86   0.000   1.75013  2.44332   .135436
         region4*|   1.308741      .19347    6.76   0.000   .929551  1.68793   .106233
         region5*|   3.347361       .2086   16.05   0.000   2.93851  3.75621   .091318
        ------------------------------------------------------------------------------
        (*) dy/dx is for discrete change of dummy variable from 0 to 1
        
        . margins                 , dydx(*) predict(e(0,.)) atmeans
        
        Conditional marginal effects                    Number of obs     =     73,282
        Model VCE    : OIM
        
        Expression   : E(whrs|whrs>0), predict(e(0,.))
        dy/dx w.r.t. : female age atth2 atth3 atth4 atth5 femaleh rural region2 region3 region4 region5
        at           : female          =    .4792719 (mean)
                       age             =    13.44808 (mean)
                       atth2           =    .3492672 (mean)
                       atth3           =    .1401026 (mean)
                       atth4           =    .1648427 (mean)
                       atth5           =    .0510903 (mean)
                       femaleh         =    .0835539 (mean)
                       rural           =    .6194427 (mean)
                       region2         =    .3110996 (mean)
                       region3         =    .1354357 (mean)
                       region4         =    .1062335 (mean)
                       region5         =    .0913185 (mean)
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              female |  -2.020797   .1044982   -19.34   0.000     -2.22561   -1.815985
                 age |    2.01746   .0476995    42.30   0.000     1.923971    2.110949
               atth2 |  -2.116487   .1187094   -17.83   0.000    -2.349154   -1.883821
               atth3 |  -3.125435   .1761991   -17.74   0.000    -3.470778   -2.780091
               atth4 |  -4.383372    .193414   -22.66   0.000    -4.762457   -4.004288
               atth5 |  -3.984787   .3149294   -12.65   0.000    -4.602037   -3.367537
             femaleh |   1.511317   .1634628     9.25   0.000     1.190936    1.831699
               rural |   2.999152   .1296384    23.13   0.000     2.745065    3.253238
             region2 |   .5078703   .1354926     3.75   0.000     .2423097    .7734308
             region3 |   1.984387   .1585183    12.52   0.000     1.673697    2.295077
             region4 |   1.260701   .1795685     7.02   0.000     .9087532    1.612649
             region5 |   3.041735   .1728207    17.60   0.000     2.703012    3.380457
        ------------------------------------------------------------------------------
        
        .


        I guess that the small difference is because each command evaluates the ME a differenent point (ie mfx evaluates female at .479272 and margins at .4792719)

        Comment


        • #5
          You don't show the original estimation command. My guess is you did not use factor variable notation. mfx assumes 0/1 variables like female are dichotomies. margins would treat them as continuous unless you used factor variable notation. The calculations are slightly different if you treat 0/1 dummies as continuous.

          Here is the bigger problem though: Based on the variable names I am guessing that you created dummies and maybe interaction terms yourself. That is a big mistake if you want to use margins. Margins won't know how the variables are inter-related if you compute the variable yourself.

          For a discussion of why what I think you are doing is very problematic, see at least the first 20 slides of

          https://www3.nd.edu/~rwilliam/stats3/Margins01.pdf
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          StataNow Version: 19.5 MP (2 processor)

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

          Comment


          • #6
            Thank you very much for your reply Richard (and for the link to the presentation)
            Your guess was right.
            Since the mfx command is an old command and does not accept factor variables, I ran the model with manual dummy variables first and used that estimate for margins as well.
            Now I have been able to replicate the results for the continuous and dichotomous variables, however, the categorical variables still have different marginal effects at the means.
            This is my syntax:

            Code:
            . *Open database
            . use                     "$dir\cw3203.dta" , clear
            
            . drop            atth1 atth2 atth3 atth4 atth5  region1 region2 region3 region4 region5
            
            . qui                     tab                     atth , gen(atth)
            
            . qui                     tab                     region , gen(region)
            
            .
            .
            .
            . global          var2 i.female age ib0.atth i.femaleh i.rural ib1.region
            
            . global          var female age atth2 atth3 atth4 atth5 femaleh rural region2 region3 region4 region5
            
            .
            .
            . *MEMs  MFX
            . qui                     tobit           whrs $var  , ll(0)
            
            . mfx                     compute, predict (e(0,.))
            
            Marginal effects after tobit
                  y  = E(whrs|whrs>0) (predict, e(0,.))
                     =   22.03211
            ------------------------------------------------------------------------------
            variable |      dy/dx    Std. Err.     z    P>|z|  [    95% C.I.   ]      X
            ---------+--------------------------------------------------------------------
              female*|  -2.016846      .10421  -19.35   0.000   -2.2211 -1.81259   .479272
                 age |    2.01746       .0477   42.30   0.000   1.92397  2.11095   13.4481
               atth2*|  -2.069747      .11371  -18.20   0.000  -2.29262 -1.84687   .349267
               atth3*|  -2.885447      .15056  -19.16   0.000  -3.18054 -2.59035   .140103
               atth4*|  -3.957135      .15855  -24.96   0.000  -4.26789 -3.64638   .164843
               atth5*|  -3.512118      .24471  -14.35   0.000  -3.99174 -3.03249    .05109
             femaleh*|   1.584907      .17967    8.82   0.000   1.23276  1.93705   .083554
               rural*|   2.928137      .12399   23.62   0.000   2.68513  3.17115   .619443
             region2*|   .5115345      .13746    3.72   0.000   .242117  .780952     .3111
             region3*|   2.096724      .17684   11.86   0.000   1.75013  2.44332   .135436
             region4*|   1.308741      .19347    6.76   0.000   .929551  1.68793   .106233
             region5*|   3.347361       .2086   16.05   0.000   2.93851  3.75621   .091318
            ------------------------------------------------------------------------------
            (*) dy/dx is for discrete change of dummy variable from 0 to 1
            
            .
            . *MEMs  MARGINS
            . qui                     tobit           whrs $var2  , ll(0)
            
            . margins                 , dydx(*) predict(e(0,.)) atmeans
            
            Conditional marginal effects                    Number of obs     =     73,282
            Model VCE    : OIM
            
            Expression   : E(whrs|whrs>0), predict(e(0,.))
            dy/dx w.r.t. : 1.female age 1.atth 2.atth 3.atth 4.atth 1.femaleh 1.rural 2.region 3.region 4.region 5.region
            at           : 0.female        =    .5207281 (mean)
                           1.female        =    .4792719 (mean)
                           age             =    13.44808 (mean)
                           0.atth          =    .2946972 (mean)
                           1.atth          =    .3492672 (mean)
                           2.atth          =    .1401026 (mean)
                           3.atth          =    .1648427 (mean)
                           4.atth          =    .0510903 (mean)
                           0.femaleh       =    .9164461 (mean)
                           1.femaleh       =    .0835539 (mean)
                           0.rural         =    .3805573 (mean)
                           1.rural         =    .6194427 (mean)
                           1.region        =    .3559128 (mean)
                           2.region        =    .3110996 (mean)
                           3.region        =    .1354357 (mean)
                           4.region        =    .1062335 (mean)
                           5.region        =    .0913185 (mean)
            
            ------------------------------------------------------------------------------
                         |            Delta-method
                         |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                1.female |  -2.016846   .1042119   -19.35   0.000    -2.221098   -1.812594
                     age |    2.01746   .0476995    42.30   0.000     1.923971    2.110949
                         |
                    atth |
                      1  |  -2.291412   .1293488   -17.71   0.000    -2.544931   -2.037894
                      2  |  -3.262817   .1756636   -18.57   0.000    -3.607111   -2.918522
                      3  |  -4.378265   .1819837   -24.06   0.000    -4.734947   -4.021584
                      4  |  -4.035686   .2850731   -14.16   0.000    -4.594419   -3.476953
                         |
               1.femaleh |   1.584907   .1796678     8.82   0.000     1.232765    1.937049
                 1.rural |   2.928137   .1239875    23.62   0.000     2.685126    3.171148
                         |
                  region |
                      2  |   .4864769   .1299027     3.74   0.000     .2318724    .7410815
                      3  |   2.009387   .1650895    12.17   0.000     1.685818    2.332956
                      4  |   1.241991   .1810493     6.86   0.000     .8871408    1.596841
                      5  |   3.208903   .1931675    16.61   0.000     2.830301    3.587504
            ------------------------------------------------------------------------------
            Note: dy/dx for factor levels is the discrete change from the base level.
            As I mentioned, mfx does not accept variable factors, so I make two different estimates for each command.
            According to what I understand, the difference is due to the fact that in mfx the categorical variables are evaluated independently of each other.
            For example, for the ME of rural2 using mfx the calculation is the difference of 2 models that estimate the probability of enrolment, in the first model one all the observations are in rural2 and in the second all the observations are in rural1, but in both models the coefficients of rural3-rural5 are used and multiplied by their respective beta.
            In margins the ME of rural2 is the same difference but do not take into account the coefficients and means of rural3-rural5. Is that right?

            Anyway, now it is quite clear to me that evaluating Average Marginal Effects is easier to explain intuitively and I think they are the ones I will use from now on.





            Comment


            • #7
              Hi Ricardo. I think the main lesson is to quit fooling around with mfx and to instead use margins. mfx is outdated and does various things wrong. mfx doesn't understand how all the dummies are interrelated and margins does, at least if you are using factor variable notation correctly. I like AMEs better but even if I liked MEMs better I would use margins rather than mfx. Unless you are condemned to using some really ancient version of Stata that doesn't have the margins command, I can't think of any good reason you would use mfx.
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              StataNow Version: 19.5 MP (2 processor)

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

              Comment


              • #8
                Yes, margins is much more accurate. Thank you very much for all your help. I hope that the syntax and the discussion helps others who are looking at the issue of marginal effects.

                Comment


                • #9
                  It did help! Thank you all.

                  Comment

                  Working...
                  X