help for mfx2

Enhanced mfx command for obtaining marginal effects or elasticities after estim > ation

mfx2 [, stub(name) replace multiple single trustme nolabel nolog predict(prediction_option) nose level(#) other_mfx_options ]

If (and only if) the estimates from the marginal effects are currently active, mfx2 typed without arguments redisplays previous results. Otherwise typing mfx2 causes the marginal effects for the last estimation command to be computed.


mfx2 obtains marginal effects or elasticities after estimation. It is probably most useful after multiple-outcome commands like ologit, oprobit, gologit2, slogit, mlogit, oglm, and mprobit, but it works with other commands as well. mfx2 offers two key enhancements to Stata's mfx compute command: (a) after multiple- outcome commands mfx2 automates the calling of mfx and saves the marginal effects for all outcomes in a single matrix; and (b) marginal effects are stored in a way that makes them easy to use with post-estimation table formatting commands like outreg2 and estout. mfx2 is inspired, in part, by Tamas Bartus's margeff command. margeff is often quicker than mfx2 and offers powerful additional options but mfx2 works with a wider range of commands. Presumably/hopefully, mfx2 will work whenever mfx will work (and will not work whenever mfx doesn't), but not all possible commands have been tested. In order to fully understand mfx2 you should also understand mfx; see help mfx.


stub(name) causes the original estimates to be saved as name_coef and the marginal effects estimates to be saved as name_mfx, e.g. stub(model1) will cause the saved estimates to be named model1_coef and model1_mfx. If stub is not specified, the name of the program that produced the estimates is used, e.g. if mfx2 is run after ologit the stored estimates will be named ologit_coef and ologit_mfx. NOTE: Matrices for the marginal effects and their standard errors are also added to the original estimates. However, the name_mfx file may be easier to work with when using commands like outreg2 and estout.

replace (abbreviated r) causes the marginal effects to become the active estimates. Note that, whether you use replace or not, both the marginal effects and the original estimates get saved.

multiple and single (abbreviated m and s) can be used to specify whether the estimation command is for multiple-outcome (e.g. ologit, mlogit) or single/binary/count outcome (e.g. regress, logit, poisson) models. mfx2 often already knows this but these options can be helpful if mfx2 is guessing wrong.

trustme lets you override mfx2's default preferences. The code includes (incomplete) lists of programs that do not work with it. This hard-coding could be wrong, especially if you happen to have a different program by the same name as those that are hard-coded. Hence, if you specify trustme, the program will try to work with a program it doesn't think is supported. You may get a fatal error later but you can go ahead and try this option if you really believe that mfx2 should work.

predict specifies the prediction option to be used, e.g. predict(pr), predict(pu0). If not specified, then the default prediction option for the estimation command is used. For multiple outcome models you should NOT include the outcome #, e.g. do not specify something like predict(pr o(1)). Instead, mfx2 will internally generate the commands for each possible outcome.

nolabel causes the equations in multiple-outcome models to be named eq1, eq2, etc. The default is to use the first 32 characters of the value labels and/or the values of Y as the equation labels. Note that some characters cannot be used in equation names, e.g. the space ( ), the period (.), the dollar sign ($), and the colon(:), and will be replaced with the underscore (_) character. The default behavior works well when the value labels are short and descriptive. It may not work well when value labels are very long and/or include characters that have to be changed to underscores. If the printout looks unattractive and/or you are getting strange errors, try changing the value labels of Y or else use the nolabel option. If you are estimating a series of models you probably want to be consistent in your use or nonuse of nolabel.

nose specifies that standard errors of the marginal effects (elasticities) not be computed. This can result in much faster execution. The variances and covariances will all be set to 0. Note that even if you do not use nose, only the standard errors of the marginal effects are correct, hence use of commands like test may produce incorrect results. Also, if standard errors are estimated, any missing values will be changed to 0 in the _mfx estimates.

level(#) specifies the confidence level in percent for the confidence intervals of the coefficients; see help level.

nolog suppresses the printing of everything but the final results. Otherwise, mfx2 prints out the results from each intermediate command it runs. This display can be useful in that it can (a) help identify any problems when computing marginal effects, and (b) let you know the program really is running, since estimation can take a while, especially after multiple-outcome commands like ologit and mlogit. But, if you only want to see the final results, use nolog.

other_mfx_options are the other options allowed by Stata's mfx compute command, e.g. at(atlist), varlist(varlist); see help mfx. The output from some of these options will be hidden if you use the nolog option.


It is important to realize that, if mfx does not work for your problem, then mfx2 isn't going to work either. mfx2 simplifies the use of mfx and restructures mfx's output for easier use with table formatting programs. But, when it comes to actually estimating the marginal effects mfx2 has the same limitations that mfx does. Typing findit marginal effects may either lead you to a FAQ that addresses your problem or show you a program that is better suited for your needs. For example, if you have interaction effects in your logit model, you may want to check out inteff. Or, if your model includes multiple dummy variables, margeff may handle your needs. In general, there are several different programs for marginal effects, and if mfx2 does not do what you want maybe another one will. There is little point in asking the author of mfx2 how to do something that can't be done with mfx, because he probably won't know! (Or at least he won't know more than what can be found in the FAQs and other available programs.).

Especially if you are having problems with your estimation, I recommend NOT using the nolog option. The output can be a little tedious, but you will see all the intermediate calculations and any warning messages that are being issued by mfx. For example, warning messages like "derivatives not found" will be hidden if you use the nolog option.

Sometimes switching to a different estimation program will help. For example, the original gologit does not work with either mfx or mfx2, but gologit2 does (make sure you have version 2.1.3 or later; earlier versions had a problem that kept them from working correctly with mfx). My guess is that user- written routines are more likely to be problematic than official Stata programs, because they are less likely to follow official Stata's standard programming practices.

If you get an "equation not found" error it may be because mfx2 has incorrectly guessed that the estimation routine is for multiple outcomes, similar to ologit. Try rerunning mfx2 using the single option. Conversely, if you get a message like "too few variables specified," it may be because mfx2 does not realize the original estimation command is for multiple outcomes; try rerunning mfx2 using the multiple option.

In theory, if mfx works fine for a problem, then mfx2 should too. This has been true for the programs most used by mfx2's author, but there are lots of programs, and lots of mfx options, that he has never tried. If you encounter a situation where mfx works but mfx2 does not, please email the author with the details.


. * Compute marginal effects after ologit, gologit2, mlogit . * Output and compare results using outreg2 and esttab . * Be patient, since it can take a painfully long time to compute s.e.'s . * gologit2 & outreg2 need to be installed for this example . * If not otherwise specified, the stubname is the name of the command that produced the estimates. . use http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta, clear . ologit warm yr89 male white age ed prst . mfx2 . gologit2 warm yr89 male white age ed prst, npl(yr89 male) . mfx2 . mlogit warm yr89 male white age ed prst, b(4) . mfx2 . outreg2 [ologit_mfx gologit2_mfx mlogit_mfx] using mymfx1a, replace long onecol nor2 word . esttab ologit_mfx gologit2_mfx mlogit_mfx using mymfx1b, mtitle se replace rtf

. * If you don't need the standard errors, this is much quicker!!! . * The standard errors will all be reported as equaling zero. . * The nolog option will reduce the amount of printout . use http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta, clear . ologit warm yr89 male white age ed prst . mfx2, nose nolog . gologit2 warm yr89 male white age ed prst, npl(yr89 male) . mfx2, nose nolog . mlogit warm yr89 male white age ed prst, b(4) . mfx2, nose nolog . outreg2 [ologit_mfx gologit2_mfx mlogit_mfx] using mymfx2a, replace word long onecol nor2 noaster nonotes . esttab ologit_mfx gologit2_mfx mlogit_mfx using mymfx2b, mtitle not replace rtf

. * oglm needs to be installed for the following, which means you also need Stata 9 . use http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta, clear . oglm warm yr89 male white age ed prst . mfx2, stub(nonhetero) . oglm warm yr89 male white age ed prst, het(yr89 male) . mfx2, stub(hetero) . outreg2 [nonhetero_mfx hetero_mfx] using mymfx3a, replace long onecol nor2 word . esttab nonhetero_mfx hetero_mfx using mymfx3b, mtitle se replace rtf

. * Compare marginal effects at different values . use http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta, clear . ologit warm yr89 male white age ed prst . mfx2, at(mean) stub(mean) . mfx2, at(median) stub(median) . mfx2, at(zero) stub(zero) . outreg2 [mean_mfx median_mfx zero_mfx] using mymfx4a, replace long onecol nor2 noaster nonotes word . esttab mean_mfx median_mfx zero_mfx using mymfx4b, mtitle se replace rtf


Richard Williams Notre Dame Department of Sociology Richard.A.Williams.5@ND.Edu http://www.nd.edu/~rwilliam/