Search
   >> Home >> Resources & support >> FAQs >> Marginal effects and the travelvl option
Note: This FAQ is for Stata 10 and older versions of Stata. In Stata 11, the margins command replaced mfx.

Running mfx on my dataset takes a long time, and I am worried it may have stopped. How can I tell if it is still running?

Title   Marginal effects and the travelvl option
Author May Boggess, StataCorp
Date April 2004; minor revisions September 2005

The tracelvl(1) option is very useful for watching mfx at work. Let’s look at an example:

 . sysuse auto, clear
 (1978 Automobile Data)
 
 . mlogit rep78 length displacement turn gear_ratio, nolog 
 
 Multinomial logistic regression                   Number of obs   =         69
                                                   LR chi2(16)     =      50.40
                                                   Prob > chi2     =     0.0000
 Log likelihood = -68.492767                       Pseudo R2       =     0.2690
 
 ------------------------------------------------------------------------------
        rep78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
 -------------+----------------------------------------------------------------
 1            |
       length |  -.0077791   .0857701    -0.09   0.928    -.1758855    .1603272
 displacement |  -.0203556   .0217033    -0.94   0.348    -.0628933    .0221822
         turn |   .2606348   .4279448     0.61   0.542    -.5781215    1.099391
   gear_ratio |   -1.84238   3.056085    -0.60   0.547    -7.832197    4.147436
        _cons |  -2.307812   16.15227    -0.14   0.886    -33.96567    29.35005
 -------------+----------------------------------------------------------------
 2            |
       length |  -.0257227   .0503671    -0.51   0.610    -.1244405    .0729951
 displacement |  -.0227271   .0139469    -1.63   0.103    -.0500626    .0046083
         turn |   .5413776   .2719147     1.99   0.046     .0084346    1.074321
   gear_ratio |  -3.959613   2.582289    -1.53   0.125    -9.020805     1.10158
        _cons |  -2.896173    9.00731    -0.32   0.748    -20.55018    14.75783
 -------------+----------------------------------------------------------------
 4            |
       length |   .0485892   .0351597     1.38   0.167    -.0203226     .117501
 displacement |  -.0006782    .009394    -0.07   0.942    -.0190901    .0177337
         turn |  -.2454005   .1682703    -1.46   0.145    -.5752041    .0844032
   gear_ratio |   1.615741   1.430829     1.13   0.259    -1.188633    4.420116
        _cons |  -4.694191   7.392889    -0.63   0.525    -19.18399    9.795606
 -------------+----------------------------------------------------------------
 5            |
       length |   .2154726   .0826013     2.61   0.009      .053577    .3773682
 displacement |  -.1231205   .0456459    -2.70   0.007    -.2125848   -.0336562
         turn |   -.561081   .2635563    -2.13   0.033    -1.077642   -.0445202
   gear_ratio |  -4.795507   2.475835    -1.94   0.053    -9.648054    .0570406
        _cons |    14.0879   11.59243     1.22   0.224    -8.632844    36.80864
 ------------------------------------------------------------------------------
 (rep78==3 is the base outcome)
 
 . mfx, predict(p outcome(2)) tracelvl(1)
 
 calculating dydx (nonlinear method)
 
 -------------------------
 variable |      dy/dx
 ---------+---------------
   length |      -.00184
 displa~t |      -.00094
     turn |       .02686
 gear_r~o |      -.19349
 -------------------------
  
  
 calculating standard errors (nonlinear method)
 
 length ... continuous
  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 
 length: Std. Err. = .00272748
 
 displacement ... continuous
  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 
 displacement: Std. Err. = .00066346
 
 turn ... continuous
  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 
 turn: Std. Err. = .01852245
 
 gear_ratio ... continuous
  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 
 gear_ratio: Std. Err. = .11812354
 
 Marginal effects after mlogit
       y  = Pr(rep78==2) (predict, p outcome(2))
          =  .04557427
 ------------------------------------------------------------------------------
 variable |      dy/dx    Std. Err.     z    P>|z|  [    95% C.I.   ]      X
 ---------+--------------------------------------------------------------------
   length |  -.0018412      .00273   -0.68   0.500  -.007187  .003505    188.29
 displa~t |  -.0009443      .00066   -1.42   0.155  -.002245  .000356       198
     turn |   .0268613      .01852    1.45   0.147  -.009442  .063165   39.7971
 gear_r~o |  -.1934947      .11812   -1.64   0.101  -.425013  .038023   2.99928
  ------------------------------------------------------------------------------

I’ve chosen mlogit as an example because it is a multiple-equation estimation with many coefficients, so mfx can take quite some time to complete its calculations.

Let’s go through the extra output that tracelvl(1) has created and see what it means. The first part of the output is

 calculating dydx (nonlinear method)
  
 -------------------------
 variable |      dy/dx
 ---------+---------------
   length |      -.00184
 displa~t |      -.00094
     turn |       .02686
 gear_r~o |      -.19349
 -------------------------

First mfx tells us that it is calculating the marginal effects and that it is using the nonlinear method (see the FAQ stata.com/support/faqs/statistics/marginal-effects-methods for an explanation of what nonlinear means). We see this output appear very quickly indeed. Let’s look at the next piece of output:

 calculating standard errors (nonlinear method)
  
 length ... continuous
  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 
 length: Std. Err. = .00272748

mfx begins by letting us know it is doing the standard errors, again using the nonlinear method. Then, for each independent variable in the estimation, we have numbers counting across the screen in front of us. It is comforting to see them because at least we know mfx is still at work, but what do they mean?

To compute the standard error of each marginal effect, we need to compute a number corresponding to each coefficient in the estimation (see the FAQ stata.com/support/faqs/statistics/marginal-effects-methods for a full description of exactly what they are). So, the list of numbers tells you which variable it is up to in the computation. We can use tracelvl(2) if we want to see each of those numbers as mfx computes it:

 . webuse fish, clear
 
 . zip count persons, inf(child camper) vuong nolog
 
 Zero-inflated Poisson regression                  Number of obs   =        250
                                                   Nonzero obs     =        108
                                                   Zero obs        =        142
 
 Inflation model = logit                           LR chi2(1)      =     417.56
 Log likelihood  = -895.1643                       Prob > chi2     =     0.0000
 
 ------------------------------------------------------------------------------
        count |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
 -------------+----------------------------------------------------------------
 count        |
      persons |   .8061845   .0460454    17.51   0.000     .7159371    .8964318
        _cons |  -.5040989   .1658804    -3.04   0.002    -.8292184   -.1789793
 -------------+----------------------------------------------------------------
 inflate      |
        child |   1.513283   .2652983     5.70   0.000     .9933076    2.033258
       camper |  -1.007936   .3499951    -2.88   0.004    -1.693914   -.3219581
        _cons |  -.3299887   .2913634    -1.13   0.257    -.9010505    .2410732
 ------------------------------------------------------------------------------
 Vuong test of zip vs. standard Poisson:            z =     3.94  Pr>z = 0.0000
 
 . mfx, predict(n) nonlinear tracelvl(1)
 
 calculating dydx (nonlinear method)
 
 -------------------------
 variable |      dy/dx
 ---------+---------------
  persons |       1.7639
    child |      -1.7485
   camper |       1.1334
 -------------------------
 
 
 calculating standard errors (nonlinear method)
 
 persons ... continuous
  1  2  3  4  5 
 persons: Std. Err. = .17607926
  
 child ... continuous
  1  2  3  4  5 
 child: Std. Err. = .2973726
 
 camper ... discrete
  1  2  3  4  5 
 camper: Std. Err. = .37428072
 
 Marginal effects after zip
       y  = predicted number of events (predict, n)
          =  2.1880131
 ------------------------------------------------------------------------------
 variable |      dy/dx    Std. Err.     z    P>|z|  [    95% C.I.   ]      X
 ---------+--------------------------------------------------------------------
  persons |   1.763942      .17608   10.02   0.000   1.41883  2.10905     2.528
    child |   -1.74851      .29737   -5.88   0.000  -2.33135 -1.16567      .684
   camper*|    1.13338      .37428    3.03   0.002   .399803  1.86696      .588
 ------------------------------------------------------------------------------
 (*) dy/dx is for discrete change of dummy variable from 0 to 1
 
 . mfx, predict(n) nonlinear tracelvl(2)
 
 calculating dydx (nonlinear method)
 
 -------------------------
 variable |      dy/dx
 ---------+---------------
  persons |       1.7639
    child |      -1.7485
   camper |       1.1334
 -------------------------
 
 
 calculating standard errors (nonlinear method)

 persons ... continuous
  1  d^2f/dxdb = 6.6472574
  2  d^2f/dxdb = 1.7639419
  3  d^2f/dxdb = -.63714517
  4  d^2f/dxdb = -.54772145
  5  d^2f/dxdb = -.93149901
 persons: Std. Err. = .17607926
  
 child ... continuous
  1  d^2f/dxdb = -4.4202341
  2  d^2f/dxdb = -1.7485094
  3  d^2f/dxdb = -1.0882794
  4  d^2f/dxdb = .05773436
  5  d^2f/dxdb = .09819149
 child: Std. Err. = .2973726
 
 camper ... discrete
  1  d^2f/dxdb = 2.8651844
  2  d^2f/dxdb = 1.1333799
  3  d^2f/dxdb = -.0730116
  4  d^2f/dxdb = -1.1329221
  5  d^2f/dxdb = -.10674212
 camper: Std. Err. = .37428072
 
 Marginal effects after zip
       y  = predicted number of events (predict, n)
          =  2.1880131
 ------------------------------------------------------------------------------
 variable |      dy/dx    Std. Err.     z    P>|z|  [    95% C.I.   ]      X
 ---------+--------------------------------------------------------------------
  persons |   1.763942      .17608   10.02   0.000   1.41883  2.10905     2.528
    child |   -1.74851      .29737   -5.88   0.000  -2.33135 -1.16567      .684
   camper*|    1.13338      .37428    3.03   0.002   .399803  1.86696      .588
 ------------------------------------------------------------------------------
 (*) dy/dx is for discrete change of dummy variable from 0 to 1
The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ Watch us on YouTube