__Title__

**[R] margins, contrast** -- Contrasts of margins

__Syntax__

**margins** [*marginlist*] [*if*] [*in*] [*weight*] [**,** __contr__**ast** *margins_options*]

**margins** [*marginlist*] [*if*] [*in*] [*weight*] [**,** __contr__**ast(***suboptions***)**
*margins_options*]

where *marginlist* is a list of factor variables or interactions that
appear in the current estimation results. The variables may be typed
with or without contrast operators, and you may use any factor-variable
syntax:

. **margins sex##group, contrast**

. **margins sex##g.group, contrast**

. **margins sex@group, contrast**

See the *operators (op.)* table in **[R] contrast** for the list of contrast
operators. Contrast operators may also be specified on the variables in
**margins**'s **over()** and **within()** options to perform contrasts across the
levels of those variables.

*suboptions* Description
-------------------------------------------------------------------------
Contrast
**overall** add a joint hypothesis test for all specified
contrasts
**lincom** treat user-defined contrasts as linear
combinations
__pred__**ict(***op*[**._predict**]**)** apply the *op***.** contrast operator to the groups
defined by multiple **predict()** options
__at__**contrast(***op*[**._at**]**)** apply the *op***.** contrast operator to the groups
defined by **at()**
__pred__**ictjoint** test jointly across all groups defined by
multiple **predict()** options
__at__**joint** test jointly across all groups defined by **at()**
__over__**joint** test jointly across all levels of the
unoperated **over()** variables
__within__**joint** test jointly across all levels of the
unoperated **within()** variables
__marginsw__**ithin** perform contrasts within the levels of the
unoperated terms in *marginlist*

__ci__**effects** show effects table with confidence intervals
__pv__**effects** show effects table with p-values
__eff__**ects** show effects table with confidence intervals
and p-values
**nowald** suppress table of Wald tests
__noatlev__**els** report only the overall Wald test for terms
that use the within **@** or nested **|** operator
__nosvy__**adjust** compute unadjusted Wald tests for survey
results
-------------------------------------------------------------------------

**fweight**s, **aweight**s, **iweight**s, and **pweight**s are allowed; see weight.

__Menu__

**Statistics > Postestimation**

__Description__

**margins** with the **contrast** option or with contrast operators performs
contrasts of margins. This extends the capabilities of **contrast** to any
of the nonlinear responses, predictive margins, or other margins that can
be estimated by **margins**.

__Suboptions__

+----------+
----+ Contrast +---------------------------------------------------------

**overall** specifies that a joint hypothesis test over all terms be
performed.

**lincom** specifies that user-defined contrasts be treated as linear
combinations. The default is to require that all user-defined
contrasts sum to zero. (Summing to zero is part of the definition of
a contrast.)

**predict(***op***._predict)** specifies that the *op***.** contrast operator be applied
to the groups defined by multiple specifications of **margins**'s
**predict()** option. The default behavior, by comparison, is to perform
tests and contrasts within these groups.

**atcontrast(***op***._at)** specifies that the *op***.** contrast operator be applied to
the groups defined by the **at()** option(s). The default behavior, by
comparison, is to perform tests and contrasts within the groups
defined by the **at()** option(s).

See example 6 in *Remarks and examples* of **[R] margins, contrast**.

**predictjoint** specifies that joint tests be performed across all groups
defined by multiple specifications of **margins**'s **predict()** option.
The default behavior, by comparison, is to perform contrasts and
tests within each group.

**atjoint** specifies that joint tests be performed across all groups defined
by the **at()** option. The default behavior, by comparison, is to
perform contrasts and tests within each group.

See example 5 in *Remarks and examples* of **[R] margins, contrast**.

**overjoint** specifies how unoperated variables in the **over()** option are
treated.

Each variable in the **over()** option may be specified either with or
without a contrast operator. For contrast-operated variables, the
specified contrast comparisons are always performed.

**overjoint** specifies that joint tests be performed across all levels
of the unoperated variables. The default behavior, by comparison, is
to perform contrasts and tests within each combination of levels of
the unoperated variables.

See example 3 in *Remarks and examples* in **[R] margins, contrast**.

**withinjoint** specifies how unoperated variables in the **within()** option are
treated.

Each variable in the **within()** option may be specified either with or
without a contrast operator. For contrast-operated variables, the
specified contrast comparisons are always performed.

**withinjoint** specifies that joint tests be performed across all levels
of the unoperated variables. The default behavior, by comparison, is
to perform contrasts and tests within each combination of levels of
the unoperated variables.

**marginswithin** specifies how unoperated variables in *marginlist* are
treated.

Each variable in *marginlist* may be specified either with or without a
contrast operator. For contrast-operated variables, the specified
contrast comparisons are always performed.

**marginswithin** specifies that contrasts and tests be performed within
each combination of levels of the unoperated variables. The default
behavior, by comparison, is to perform joint tests across all levels
of the unoperated variables.

See example 4 in *Remarks and examples* in **[R] margins, contrast**.

**cieffects** specifies that a table containing a confidence interval for
each individual contrast be reported.

**pveffects** specifies that a table containing a p-value for each individual
contrast be reported.

**effects** specifies that a single table containing a confidence interval
and p-value for each individual contrast be reported.

**nowald** suppresses the table of Wald tests.

**noatlevels** indicates that only the overall Wald test be reported for each
term containing within or nested (**@** or **|**) operators.

**nosvyadjust** is for use with **svy** estimation commands. It specifies that
the Wald test be carried out without the default adjustment for the
design degrees of freedom. That is to say the test is carried out as
W/k ~ F(k,d) rather than as (d-k+1)W/(kd) ~ F(k,d-k+1), where k is
the dimension of the test and d is the total number of sampled PSUs
minus the total number of strata.

__Examples__

These examples are intended for quick reference. For a conceptual
overview of **margins,** **contrast** and examples with discussion, see **Remarks**
**and examples** in **[R] margins, contrast**.

**. webuse margex**
**. logistic outcome treatment##group age c.age#c.age treatment#c.age**
**. margins, dydx(treatment)**
**. margins r.treatment**
**. margins treatment#group, contrast(wald)**
**. margins treatment@group, contrast(wald)**
**. margins treatment, over(group) contrast(wald overjoint)**
**. margins treatment, over(group) contrast(wald)**

__Stored results__

**margins,** **contrast** stores the following additional results in **r()**:

Scalars
**r(k_terms)** number of terms participating in contrasts

Macros
**r(cmd)** **contrast**
**r(cmd2)** **margins**
**r(overall)** **overall** or empty

Matrices
**r(L)** matrix of contrasts applied to the margins
**r(chi2)** vector of chi-squared statistics
**r(p)** vector of p-values corresponding to **r(chi2)**
**r(df)** vector of degrees of freedom corresponding to **r(p)**

**margins,** **contrast** with the **post** option also stores the following
additional results in **e()**:

Scalars
**e(k_terms)** number of terms participating in contrasts

Macros
**e(cmd)** **contrast**
**e(cmd2)** **margins**
**e(overall)** **overall** or empty

Matrices
**e(L)** matrix of contrasts applied to the margins
**e(chi2)** vector of chi-squared statistics
**e(p)** vector of p-values corresponding to **e(chi2)**
**e(df)** vector of degrees of freedom corresponding to **e(p)**