help mimrgns

Title

mimrgns -- margins after mi estimate

Syntax

Use after mi estimate

mimrgns
[marginlist]
[if] [in]
[weight]
[ , options ]

Use after mi estimate , saving() esample()

mimrgns [marginlist]
[if] [in] [weight]
using miestfile
, esample(varname)
[ options ]

where miestfile.ster contains estimation results
previously saved by

mi estimate , saving(miestfile)
esample(newvarname)

Main
* esample(varname) specify varname
identifying the estimation sample

predict(default) use margins' default
prediction; mimrgns' default is predict(xb)

eform display (final) estimates in exponentiated form

cmdmargins set r(cmd) to margins; required
before marginsplot

noestimate do not re-estimate margins; only allowed
with cmdmargins

margins
margins_options options allowed
with the margins command

mi
nosmall do not use small-sample correction for
degrees of freedom

dots same as with mi estimate

noisily same as with mi estimate

trace same as with mi estimate

errorok same as with mi estimate

esampvaryok same as with mi estimate

* esample() is required with the second syntax
and not allowed with the first syntax

Description

mimrgns runs margins after mi estimate and obtains margins
of responses in multiply imputed datasets.

The command generalizes
Isabel Canette and Yulia Marchenko's
approach, which has later been adopted by the
UCLA Statistical Consulting Group. See
Remarks below.

The first syntax mirrors the regular margins command; when specified,
mimrgns runs both the estimation command and margins on the
imputed datasets. The second (using) syntax is preferred; it obtains
results from miestfile and only runs margins on the imputed
datasets.

Remarks

There might be good reasons why Stata's margins command does not work
after mi estimate. If you have not read
Using the command-specific postestimation tools
in [MI] mi estimate postestimation, please
do so.

Instead of applying margins to the (final) MI estimates, mimrgns
treats margins itself as an estimation command and combines its results
according to Rubin's rules.

Nonlinear predictions

Applying Rubin's rules to margins' results assumes asymptotic
normality. Assuming asymptotic normality is appropriate for linear
predictions and for average marginal effects (White, Royston and Wood 2011)
but might not be appropriate otherwise (also see
Example 3: Obtain MI estimates of probabilities
in [MI] mi predict). By default, mimrgns uses linear
predictions for all estimation commands.

Graph results from mimrgns

In principle, marginsplot works after mimrgns. However,
there are two issues to consider. First, the plotted
confidence intervals are based on
inappropriate degrees of freedom. mimrgns
leaves the correct degrees of freedom in r(df) (or r(df_vs),
with the pwcompare option). Although the differences should be small
for large sample sizes, consider alternatives to marginsplot that
allow specifying the degrees of freedom used to calculate confidence
intervals, e.g., Jann's coefplot. Second,
graphs might be based on summary statistics that vary
across imputed datasets. mimrgns uses dataset
specific summary statistics, requested in at() options, but
reports their combined point estimate in the legend.

Further restrictions

mimrgns does not support joint hypothesis tests with
the contrast option.

mimrgns does not save all results that margins saves. This
might lead to error messages when running post estimation commands, e.g.,
mi test. Even if no error messages appear, such results might not
be appropriate.

Options

Main

esample(varnme) specifies the observations to be used in the
estimation; varname is the same variable that was previously
created by mi estimate , esample(newvarname). The option
is required with the second syntax and not allowed with the first
syntax.

predict(default) specifies that, instead of mimrgns
default predict(xb), the default prediction of the margins
command is used. This option will usually result in nonlinear predictions
for which Rubin's rules might not be appropriate; see
Nonlinear predictions.

eform displays (final) coefficients in exponentiated form. This
option does not affect any calculations.

cmdmargins sets r(cmd) (or e(cmd), with post)
to margins. This option is required before marginsplot
(Stata 12 or higher) is used; see
Graph results from mimrgns.

noestimate is only for use with cmdmargins and does not
re-estimate margins. When you did not specify cmdmargins at
estimation time, you may still (re-)set r(cmd) to margins
typing

. mimrgns , cmdmargins noestimate

margins

margins_options are options allowed with
the margins command.

Option at() is allowed and may request summary statistics, such as
the mean, minimum, or maximum of covariates. However, when covariates are
multiply imputed there is no longer one mean (minimum, maximum, ...); there
are now M of them. mimrgns fixes covariates at the imputed
dataset specific statistic for calcutations but reports the combined point
estimate as a single value. A note is issued below the results table as a
reminder.

In general, mimrgns passes any options thru to margins. Therefore,
options affect the estimation in each imputed dataset. For most options, this
is what you want. Some options, such as most contrast_options and option
nose are not allowed. Also, most of margins' undocumented options
are not allowed.

mi_options

nosmall does not use the small-sample correction for the degrees of
freedom. See the corresponding mi estimate option
for more details.

dots, noisily and trace are the corresponding
mi estimate reporting_options.

errorok and esampvaryok are the respective
mi estimate options. With the first syntax,
you must repeat these options if you have specified them with
mi estimate before.

Examples

Setup

. webuse mheart1s20

. mi convert flong

Estimate a logistic regression model and save the results
(Note: saves a file to disk!)

. mi estimate , saving(miestfile) esample(esample) : logit attack i.smokes age bmi i.hsgrad i.female

Obtain average marginal effects (linear predictions)

. mimrgns using miestfile , esample(esample) dydx(*)

Obtain average marginal effects in terms of predicted probabilities
(but see Nonlinear predictions).

. mimrgns using miestfile , esample(esample) predict(pr) dydx(*)

Create age categories and re-run the logistic regression

. mi xeq : generate ageg = irecode(age, 20, 40 ,60, 80)

. mi estimate : logit attack i.smokes i.ageg bmi i.hsgrad i.female

Obtain pairwise comparisons of predictive margins

. mimrgns ageg , pwcompare

Contrasts of predictive margins

. mimrgns ar.ageg

Erase miestfile.ster, created above.

. erase miestfile.ster

Saved results

mimrgns saves in r() some of the results that
margins saves without the
post option.

mimrgns additionally saves the following in r():

Macros

r(est_cmdline_mi) e(cmdline_mi) from mi estimate

r(est_cmdline_margins) margins command

Addendum

Confidence intervals with marginsplot

marginsplot internally replays results from the last margins
command. It then uses the replayed results to recalculate confidence
intervals (but not point estimates and standard errors). However, the
replayed results are those obtained by margins in the last imputed
dataset, not the ones reported by mimrgns. Thus, marginsplot
does not use the correct degrees of freedom. Unfortunately, there is no
way of passing the appropriate degrees of freedom to marginsplot;
therefore, there is no way to get correct confidence intervals from
marginsplot after mimrgns. Fortunately, the differences are
often small and you can assess them as described on
Statalist.

References

Jann, B. 2013. Plotting regression coefficients and other estimates in
Stata. University of Bern Social Sciences Working Papers Nr. 1. Available
from http://ideas.repec.org/p/bss/wpaper/1.html

White, I. R., Royston, P., Wood, M. A. 2011. Multiple imputation using
chained equations: Issues and guidance for practice. Statistics in Medicine
30:377-399.

Stata FAQ. How can I get margins and marginsplot with multiply
imputated data? UCLA: Statistical Consulting Group. from
http://www.ats.ucla.edu/stat/stata/faq/ologit_mi_marginsplot.htm

Acknowledgments

Jessica Stroope reported a bug with the pwcompare(effects) option.

Liz Hensor reported a bug with the at legend when over()
was specified.

Filip Safr reported a bug when predict() was called
with more than one argument.

Wolf Edler reported problems when using mimrgns via a
remote access that would not allow *.class files
to be uploaded. This led to internal changes; mimrgns
does no longer rely on such files.

Robbie Dembo reported a bug when mimrgns was called
after xt* models fit with the i() option.

Xiao Yang (StataCorp) tracked down a bug that had gone
unnoticed under Windows but prevented mimrgns
from running under Linux.

Jesper Wulff reported a bug with
contrast-options and pwcompare-options in
Stata 13 (or higher).

Part of the code is borrowed (verbatim) from StataCorp's
_marg_report routine.

Evan Kontopantelis suggested support for contrast
operators and reporting the at legend.

Timothy Mak identified a bug with mixed models.

Oliver Klein originally stimulated the mimrgns command.

Author

Daniel Klein

German Centre for Higher Education Research and Science Studies (DZHW)

Research Data Centre

klein.daniel.81@gmail.com

Also see

Online: mi, margins

if installed: coefplot