help mfx dialog: mfx
-------------------------------------------------------------------------------
mfx has been superseded by margins. margins can do everything that mfx
did and more. margins syntax differs from mfx; see margins. mfx
continues to work but does not support factor variables and will often
fail if you do not run your estimation command under version control,
with the version set to less than 11. This help file remains to assist
those who encounter an mfx command in old do-files and programs.
Title
[R] mfx -- Obtain marginal effects or elasticities after estimation
Syntax
mfx [compute] [if] [in] [, options]
mfx replay [, level(#)]
options description
-------------------------------------------------------------------------
Model
predict(predict_option) calculate marginal effects (elasticities)
for predict_option
varlist(varlist) calculate marginal effects (elasticities)
for varlist
dydx calculate marginal effects; the default
eyex calculate elasticities in the form of
d(lny)/d(lnx)
dyex calculate elasticities in the form of
d(y)/d(lnx)
eydx calculate elasticities in the form of
d(lny)/d(x)
nodiscrete treat dummy (indicator) variables as
continuous
nose do not calculate standard errors
Model 2
at(atlist) calculate marginal effects (elasticities) at
these values
noesample do not restrict calculation of means and
medians to the estimation sample
nowght ignore weights when calculating means and
medians
Adv. model
nonlinear do not use the linear method
force calculate marginal effects and standard
errors when it would otherwise refuse to
do so
Reporting
level(#) set confidence level; default is level(95)
diagnostics(beta) report suitability of marginal-effect
calculation
diagnostics(vce) report suitability of standard-error
calculation
diagnostics(all) report all diagnostic information
tracelvl(#) report increasing levels of detail during
calculations
-------------------------------------------------------------------------
where atlist is numlist or matname or
[mean|median|zero] [varname = # [, varname = #] [...]]
where mean is the default.
Menu
Statistics > Postestimation > Marginal effects or elasticities
Description
mfx numerically calculates the marginal effects or the elasticities and
their standard errors after estimation. Exactly what mfx can calculate
is determined by the previous estimation command and the
predict(predict_option) option. The values at which the marginal effects
or elasticities are to be evaluated is determined by the at(atlist)
option. By default, mfx calculates the marginal effects or elasticities
at the means of the independent variables by using the default prediction
option associated with the previous estimation command.
Some disciplines use the term partial effects, rather than marginal
effects, for what is computed by mfx.
mfx replay replays the results of the previous mfx computation.
Options
+-------+
----+ Model +------------------------------------------------------------
predict(predict_option) specifies the function (that is, the form of y)
for which to calculate the marginal effects or elasticities. The
default is to use the default predict option of the preceding
estimation command. To see which predict options are available, see
help for the particular estimation command.
varlist(varlist) specifies the variables for which to calculate marginal
effects (elasticities). The default is all variables.
dydx specifies that marginal effects be calculated. This is the default.
eyex specifies that elasticities be calculated in the form of
d(lny)/d(lnx)
dyex specifies that elasticities be calculated in the form of d(y)/d(lnx)
eydx specifies that elasticities be calculated in the form of d(lny)/d(x)
nodiscrete treats dummy variables as continuous. A dummy variable is one
that takes on the value 0 or 1 in the estimation sample. If
nodiscrete is not specified, the marginal effect of a dummy variable
is calculated as the discrete change in y as the dummy variable
changes from 0 to 1. This option is irrelevant to the computation of
the elasticities because all the dummy variables are treated as
continuous when computing elasticities.
nose specifies that standard errors of the marginal effects
(elasticities) not be computed.
+---------+
----+ Model 2 +----------------------------------------------------------
at(atlist) specifies the values at which the marginal effects
(elasticities) are to be calculated. The default is to calculate at
the means of the independent variables.
at(numlist) specifies that the marginal effects (elasticities) be
calculated at numlist. For instance,
. sysuse auto
. sureg (price disp weight) (mpg disp weight foreign)
. mfx, predict(xb eq(#2)) at(200 3000 0.5)
computes the marginal effects for the second equation, setting
disp=200, weight=3000, and foreign=0.5.
The order of the values in the numlist is the same as the variables
in the preceding estimation command, from left to right, without
repetition. For instance,
. sureg (price disp weight) (mpg foreign disp)
. mfx, predict(xb) at(200 3000 0.5)
at(matname) specifies the points in a matrix format. The ordering of
the variables is the same as that of numlist. For instance,
. probit foreign mpg weight price
. matrix A = (21, 3000, 6000)
. mfx, at(A)
at([mean | median | zero] [varname = # [, varname = # [...]]])
specifies that the marginal effects (elasticities) be calculated at
means, at medians of the independent variables, or at zeros. It also
allows users to specify particular values for one or more independent
variables, assuming that the rest are means, medians, or zeros.
. probit foreign mpg weight price
. mfx, at(mean mpg=30)
at(varname = # [, varname = # ] [...]) specifies that the marginal
effects or the elasticities be calculated at particular values for
one or more independent variables, assuming that the rest are means.
. probit foreign mpg weight price
. mfx, at(mpg=30)
noesample affects at(atlist), any offsets used in the preceding
estimation, and the determination of dummy variables. It specifies
that the whole dataset be considered instead of only those marked in
the e(sample) defined by the previous estimation command.
nowght affects only at(atlist) and offsets. It specifies that weights be
ignored when calculating the means or medians for the atlist and when
calculating the means for any offsets.
+------------+
----+ Adv. model +-------------------------------------------------------
nonlinear specifies that y, the function to be calculated for the
marginal effects or the elasticities, does not meet the linear-form
restriction. By default, mfx assumes that y meets the linear-form
restriction, unless one or more dependent variables are shared by
multiple equations or the previous estimation command was nl. For
instance, predictions after
. heckman mpg price, sel(foreign=rep78)
meet the linear-form restriction, but those after
. heckman mpg price, sel(foreign=rep78 price)
do not. If y meets the linear-form restriction, specifying nonlinear
should produce the same results as not specifying it. However, the
nonlinear method is generally more time consuming. Most likely, you
do not need to specify nonlinear after an official Stata command.
For user-written commands, if you are not sure whether y is of linear
form, specifying nonlinear is a safe choice.
force specifies that marginal effects and their standard errors be
calculated when it would otherwise refuse to do so. Such cases
arise, for instance, when the marginal effect is a function of a
random quantity other than the coefficients of the model (e.g., a
residual). If you specify this option, there is no guarantee that
the resulting marginal effects and standard errors are correct.
+-----------+
----+ Reporting +--------------------------------------------------------
level(#) specifies the confidence level, as a percentage, for confidence
intervals. The default is level(95) or as set by set level.
diagnostics(diaglist) asks mfx to display various diagnostic information.
diagnostics(beta) shows the information used to determine whether the
prediction option is suitable for computing marginal effects.
diagnostics(vce) shows the information used to determine whether the
prediction option is suitable for computing the standard errors of
the marginal effects.
diagnostics(all) shows all the above diagnostic information.
tracelvl(#) shows increasing levels of detail during calculations. # may
be 1, 2, 3, or 4. Level 1 shows the marginal effects and standard
errors as they are computed, and which method, either linear or
nonlinear, was used. Level 2 shows, in addition, the components of
the matrix of partial derivatives needed for each standard error as
they are computed. Level 3 shows counts of iterations in obtaining a
suitable finite difference for each numerical derivative. Level 4
shows the values of these finite differences.
Using mfx after nl
You must specify the independent variables by using the variables()
option when using the interactive version of nl to obtain marginal
effects. Otherwise, mfx has no way of distinguishing the independent
variables from the parameters of your model and will therefore exit with
an error message.
Instead of typing
. nl (mpg = {b0} + {b1}*gear^{b2=1})
type
. nl (mpg = {b0} + {b1}*gear^{b2=1}), variables(gear)
If you use the programmed substitutable expression or function evaluator
program versions of nl, you do not need to use the variables() option.
Examples
. sysuse auto
. logit foreign mpg price
. mfx, predict(p)
. mfx, predict(p) at(mpg = 20, price = 6000)
. mfx, predict(p) at(20 6000)
. mlogit rep78 mpg displ
. mfx, predict(p outcome(2))
. mfx, predict(p outcome(2)) at(20 400)
. mfx, predict(p outcome(2)) varlist(mpg)
. heckman mpg weight length, sel(foreign = length displ)
. mfx, predict(xb)
. mfx, predict(xbsel)
. mfx, predict(yexpected) varlist(length)
. regress mpg length weight
. mfx, eyex
. mfx replay, level(90)
Saved results
In addition to the e() results from the preceding estimation, mfx saves
the following in e():
Scalars
e(Xmfx_y) value of y given X
e(Xmfx_off) value of mean of the offset variable or log of the
exposure variable
e(Xmfx_off#) value of mean of the offset variable for equation #
Macros
e(Xmfx_type) dydx, eyex, eydx or dyex
e(Xmfx_discrete) discrete or nodiscrete
e(Xmfx_cmd) mfx
e(Xmfx_label_p) label for prediction in output
e(Xmfx_predict) predict_option specified in predict()
e(Xmfx_dummy) corresponding to independent variables; 1 means
dummy, 0 means continuous
e(Xmfx_variables) corresponding to independent variables; 1 means
marginal effect calculated, 0 otherwise
e(Xmfx_method) linear or nonlinear
Matrices
e(Xmfx_dydx) marginal effects
e(Xmfx_se_dydx) standard errors of the marginal effects
e(Xmfx_eyex) elasticities of form eyex
e(Xmfx_se_eyex) standard errors of elasticities of form eyex
e(Xmfx_eydx) elasticities of form eydx
e(Xmfx_se_eydx) standard errors of elasticities of form eydx
e(Xmfx_dyex) elasticities of form dyex
e(Xmfx_se_dyex) standard errors of elasticities of form dyex
e(Xmfx_X) values around which marginal effects (elasticities)
were estimated
Also see
Manual: [R] mfx
Help: [R] predict