Title

mtable -- Construct tables of predictions usingmargins

General syntax

mtable [if] [in], [ mtable-options margins-options ]

Overview

mtable uses margins to construct tables of predictions.
If the outcome has multiple categories, mtable automatically
submits multiple margins commands for all outcomes and combines the
results in the table. Results from multiple calls of mtable can be
combined into a single table.

margins is a complicated command with many options.
It is possible that mtable will not work with every option that is
available with margins.

Options

Options for margins
Which statistics to display
Displaying at-variables
Controlling how results are displayed
Combining tables
Matrices that are created
Returns

Options for margins

mtable supports most options from margins. Below are margins options commonly used by mtable.

at(atspec)
Specify the values of regressors for which predictions are calculated.
For example, at(wc=(0 1) k5=(0 1 2 3)).
A single value or multiple values can be specified for variables.
A single variable or multiple variables can be included.
For details, see at(atspec).

atmeans
All regressors not specified with at() are held at their means.
If if or in are used to specify the sample, the means are
computed for the selected observations. If atmeans is not specified,
marginal effects are averaged across observations.

over(varlist)
Predictions are calculated separately for groups defined by varlist.
Values must be nonnegative integers. Variables in varlist do not need to
be in your model.

post
For binary models, this options posts the estimates in the same way that
margins, post does.
With the outcomes() option, results can be posted for
a single outcome category of a categorical outcome. For details on
using posted results, see mlincom

dydx(varlist)
Computes marginal effects of variables included in varlist.
Different marginal effects are computed depending on the factor variable notation
included in the preceding regression model.
By default, a marginal change is computed for variables
with no factor variable notation and variables with the c. prefix.
Discrete changes between categories are computed for
variables with the i. prefix. See factor variable notation for
more information.

if or in conditions select the observations
used by margins.
With atmeans, the means are computed conditionally
on the if or in conditions. If atmeans is not used, the
average prediction is the average for the sample selected by the
if or in conditions.

details
Display output from margins used to estimate quantities in table.

commands
Display margins commands used to estimate quantities in table.

Statistics to include in the table

statistics(statlist) specifies which statistics to
include in the table. By default only estimates are displayed. Additional
statistics can be select with this option.

Name Description

estimate Estimates including probabilities, dydx, etc.

ll Lower level bound of confidence interval.

ul Upper level bound of confidence interval.

pvalue p-value for test prediction is 0.

se Standard error of prediction.

z z-value for test prediction is 0.

all Display all statistics.

ci Display estimate, ll, and ul.

allstats
Display all statictics.
Equivalent to statistics(all).

ci
Display estimate and bounds of confidence interval.
Equivalent to statistics(est ll ul).

level(#)
Adjusts the range of confidence intervals, from 10 to 99.99.

pvalue
Display estimate and p-value.
Equivalent to statistics(est pvalue).

outcomes(numlist)
Estimates displayed for these values of the outcome for models
where outcomes() is an option for predict, such as mlogit.
Outcome values must be non-negative integers.

pr(numlist)
Estimates displayed for these probabilities for models
where pr() is an option for predict, such as poisson.
Outcome values must be non-negative integers.

cpr(numlist)
Estimates displayed for these conditional probabilities for models
where pr() is an option for predict.
Outcome values must be non-negative integers.

at-variables in the table

By default, the table includes values of those variables specified with at()
that vary.
For example, with mtable, at(a=(0 1) b=1), variable a is included
in the table, but variable b is not.
Variables included in the table are referred to as "at-variables".

The following options control how at-variables are included in the table.

atvars(varlist) Selects the at-variables to
include in the table.
atvars(_none) excludes all at-variables.
atvars(_all) includes all variables including those that do not vary.

noatvars Do not include any at-variables in table.
This is equivalent to atvars(_none).

atright By default, the at-variables are listed
before the estimates. atright places the at-variables to the
right.

Controlling how results are displayed

long
Display table with statistics in rows. The column are labeled
with the category number or label.

wide
Display table with statistics in columns. Column names are the
name of the statistic plus the category name or label.

roweqnm(string)
Add a row equation name to the table.
For details, see matrix roweq.

coleqnm(string)
Add a column equation name to the table.
For details, see matrix coleq.

rowstub(string)
String is added to all row names.

colstub(string)
String is added to all column names.

rowname(string)
Name to label row.

title(string) Title used to label table. If stacking multiple
mtable results using below or right, the most recent title is used.

twidth(#) Width of margins for row labels.

width(#) Width of columns with estimates.

decimal(#) Number of decimal digits displayed.

estname(string) Name to label estimates. By
default the name from margins is used.

nolabel Do not use value labels when labeling outcomes.

nofvlabel Do not use factor variable labels for labeling
output.

nobs Display number of observations used by margins.

valuelength(#) Limits length of value labels used to
label results.

names(rows|columns|all|none) Specify whether row names,
column names, all (row and column) names, or no names will be shown in
table. See matlist for details. This option overwrites the
defaults and can lead to poorly formatted output.

norownumbers Is a synonyms for names(columns).

Combining tables

You can combine the current mtable results with those
from the last execution of mtable. This allows you to build tables
using as many mtable commands as needed. The table is displayed using
the display options from the last mtable used.

below
Place the current results below those from last mtable.

right
Place current results to the right of those from last mtable.

clear
Clear prior results before saving results to construct a new table.

Model types

Behavior of command depends on
what options are permitted by predict.
For convenience, three major types of models are called categorical,
count, and binary models.

categorical predict allows outcome(#),
such as mlogit.

count predict allows pr(#),
such as poisson.

binary predict default is pr, such as logit.

other None of the above, such as regress.

Categorical or binary models assume all outcomes
unless either outcome() is specified
or the marginal prediction is specified using the margins options
predict() or expression().

Matrices that are created

Matrices with the displayed results are saved to memory if the statistic is
shown in the table (controlled by statistics()).

Name Description

_mtab_display The displayed table.

_mtab_atdisplay The displayed values of at-variables.

To view these matrices, use the matrix list command.

matrix(name)
Save _mtab_display to the matrix named matrix-name. If the matrix
exists, it will be over-written. By default, _mtab_display is saved as
r(table) in Stata's memory.
_mtab_atdisplay is saved as r(atspec) by default
in Stata's memory.

Returns

r(table) is a matrix with the results shown in the prediction table.

r(atspec) is a local with the at-specification used in making predictions.

Examples

Example 1: Computing probabilities for two levels of a categorical variable

. spex logit

. mtable, at(wc=(0 1)) atmeans

Example 2: Stacking multiple mtable commands, labeling row equations

. spex ologit

. mtable, at(female=(0 1)) roweqnm(MEM) atmeans

. mtable, at(female=(0 1)) roweqnm(AME) below

Example 3: Changing displayed statistics

. spex ologit

. mtable, at(age=(30(15)60) year=3) stat(ul ll z)

Example 4: Changing estimate name

. spex logit

. mtable, estname(Estimate)

Example 5: Viewing matrix of results

. spex mlogit

. mtable, matrix(store_results)

. matrix list store_results

Example 6: Changing variables shown using atvar()

. spex nbreg

. mtable, at(female=(0 1) married=(0 1) kid5=(1 2) ) atvar(female)

Example 7: Computing probabilities with means conditioned on an if statement

. spex ologit

. mtable if female==1, at(white=(0 1)) atmeans