Title

mgenl -- BETA: Generate variables for plotting with predictions
from margins using local means

General syntax

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

Overview

mgenl uses results from margins to create variables for plots.
mgenl has the advantage of allowing marginal effects from multiple models to be combined in the same plot, and for marginal effects from multiple categories to be combined in the same plot.

Options

BETA Options for local means
Options for margins
Naming variables
Statistics and values generated
Variables generate with the meanpred option
How mgenl works with various types of models
Miscellaneous options
Returns
Examples

BETA Options for local means

localvars(variable-list)
Specify the values of regressors for which predictions are calculated.
For example, at(age=(20(5)85).
For details, see at(atspec).

binwidth(number)
With of region around value of variable that is varying that is used to
select observations for computing local means. For example, with
at(age=(30(10)80)) binwidth(20) the means of other variables when
age=30 are computed for age>=20 & age <=40.

Options for margins

Most options from margins can be used.

at(atspec)
Specify the values of regressors for which predictions are calculated.
For example, at(age=(20(5)85).
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.

dydx(covariate)
Computes marginal effects of one covariate.
The type of marginal effect computed depends on the factor variable notation
included in the 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. These conditions are not used to
restrict the sample when the meandpred is specified (i.e., the
average prediction is the average over the entire sample).

Naming and summarizing variables

Variables that are generated have names of the form:

<stubname><quantity><category>.

<stubname> is common to all variables.
<quantity> describes the content contained in
the variable
(e.g., se indicates a standard error).
<category> is the value or the value label of the outcome category;
for some models there is no <category>.

stub(string)
All variables begin with stubname.
If unspecified, default is "_".

replace
If the variables to be generated already exist, they will be
replaced.

predname(string)
The name used for the prediction (e.g., a probability or discrete change).
By default the name of the expression from margins is used.
For example, pr is used for predicted probabilities with
logit. If you want a different name, use predname().

predlabel(string)
This label is used in the variable label for the prediction.
This can be useful for labeling the variables that are being plotted.

nolabel Do not use value labels from the outcome
variable for <category>. For example, use mystubdydx1
rather than mystubdydxSR where SR is the value label for
category 1 of the outcome.

valuelength(integer)
Set the length of value labels used to label the outcome category.

Statistics and variables generated

Variables generated by mgenl include estimates and related statistics from
margins and values of the regressor that is changing as specified by
at().
The following names are used in naming variables.

<quantity> Description

predname Estimate such as probabilities, dydx.
By default the prediction name from margins
is used; optionally the name from predname()) is used.

atvar Values of the regressor; see atvar() below.

ll Lower-level bound of confidence interval.

ul Upper-level bound of confidence interval.

pval p-value for test estimate is 0.

se Standard error of estimate.

z z-value of test that estimate is 0.

By default, variables are generated with the estimate
and the upper and lower bounds of the confidence interval.
Other statistics can be requested with these option:

allstats
Variables with all statistics are generatged.

noci
Suppress generating variables containing bounds of confidence interval.

level(#)
Sets the level of the of confidence interval, from 10 to 99.99.

force
Forces the computation of predictions for count
models where the dependent variable has non-integer values.

outcomes(numlist)
Variables are generated 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)
Variables are generated for these probabilities for models
where pr() is an option for predict, such as poisson.
Outcome values must be non-negative integers.

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

atvars(varlist)
By default, variables are generated only for those independent variables
that vary within at().
All variables can be included by specifying _all; none by specifying _none.

Variables generated with meanpred

meanpred
Additional variables are generated where each observation is for a
specific value of the at-variable that is changing.

meanpred can only be used for count models.
Variables are based on the observed proportions in the
estimation samples, average predictions, and the value of the outcome
being predicted (e.g., value 5 for predictions of a count 5).
Variables are created with the name <stubname><quantity>.

<quantity> Description

val Value of the outcome

obeq Observed proportion y = value

oble Observed proportion y <= value

preq Predicted proportion y = value

prle Predicted proportion y <= value

obpr Difference between observed and predicted proportions of y = value

cpreq Average predicted Pr(y=value | y>0) when conditional option specified

cprle Average predicted Pr(y<=value | y>0) when conditional option specified

Model types

mgenl has different default behavior depending 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() are specified
or the marginal prediction is specified using the margins options
predict() or expression().

Cumulative predictions are calculated for categorical and count outcomes,
unless outcome() is used to specify values that exclude
a subset of the lowest observed values of the outcome.

Miscellaneous options

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

commands
Display margins commands used to estimate quantities in table.

brief By default, the non-varying values of at-variables are
listed. They are not displayed with the brief option.

Returns

r(ifin) is a local macro containing the if and in conditions used for predictions.

r(newvars) is a local macro containing a list of new variables that were generated.

Examples

Example 1: Computing probabilities for a binary outcome

. spex logit

. mgenl, at(lwg=(-2(.5)3)) stub(prlfp)

. twoway connected prlfppr1 prlfplwg

Example 2: Plotting cumulative probabilities for an ordinal outcome

. spex ologit

. mgenl, at(age = (20(5)85) year=3 white=1) stub(prclass)

. twoway connected prclassCpr1 prclassCpr2 prclassCpr3

> prclassCpr4 prclassage

Example 3: Plotting variables from multiple mgenl commands

. spex logit

. mgenl, at(inc=(0(5)95) wc=0) stub(wc0)

. mgenl, at(inc=(0(5)95) wc=1) stub(wc1)

. twoway connected wc0pr1 wc1pr1 wc0inc