**[ME] mixed postestimation** -- Postestimation tools for mixed

__Postestimation commands__

The following postestimation commands are of special interest after
**mixed**:

Command Description
-------------------------------------------------------------------------
**estat df** calculate and display degrees of freedom for fixed
effects
**estat group** summarize the composition of the nested groups
**estat icc** estimate intraclass correlations
**estat recovariance** display the estimated random-effects covariance
matrices
**estat sd** display variance components as standard deviations
and correlations
**estat wcorrelation** display model-implied within-cluster correlations and
standard deviations
-------------------------------------------------------------------------

The following standard postestimation commands are also available:

Command Description
-------------------------------------------------------------------------
**contrast** contrasts and ANOVA-style joint tests of estimates
**estat ic** Akaike's and Schwarz's Bayesian information criteria
(AIC and BIC)
**estat summarize** summary statistics for the estimation sample
**estat vce** variance-covariance matrix of the estimators (VCE)
**estimates** cataloging estimation results
**hausman** Hausman's specification test
**lincom** point estimates, standard errors, testing, and
inference for linear combinations of coefficients
**lrtest** likelihood-ratio test
**margins** marginal means, predictive margins, marginal effects,
and average marginal effects
**marginsplot** graph the results from margins (profile plots,
interaction plots, etc.)
**nlcom** point estimates, standard errors, testing, and
inference for nonlinear combinations of
coefficients
**predict** predictions, residuals, influence statistics, and
other diagnostic measures
**predictnl** point estimates, standard errors, testing, and
inference for generalized predictions
**pwcompare** pairwise comparisons of estimates
**test** Wald tests of simple and composite linear hypotheses
**testnl** Wald tests of nonlinear hypotheses
-------------------------------------------------------------------------

__Syntax for predict__

Syntax for obtaining BLUPs of random effects and the BLUPs' standard
errors

**predict** [*type*] *newvarsspec* [*if*] [*in*] **,** __ref__**fects** [**reses(***newvarsspec***)**
__relev__**el(***levelvar***)**]

Syntax for obtaining scores after ML estimation

**predict** [*type*] *newvarsspec* [*if*] [*in*] **,** __sc__**ores**

Syntax for obtaining other predictions

**predict** [*type*] *newvar* [*if*] [*in*] [**,** *statistic* __relev__**el(***levelvar***)**]

*newvarsspec* is *stub****** or *newvarlist*.

*statistic* Description
-------------------------------------------------------------------------
Main
**xb** linear prediction for the fixed portion of the model
only; the default
**stdp** standard error of the fixed-portion linear prediction
__fit__**ted** fitted values, fixed-portion linear prediction plus
contributions based on predicted random effects
__res__**iduals** residuals, response minus fitted values
* __rsta__**ndard** standardized residuals
-------------------------------------------------------------------------
Unstarred statistics are available both in and out of sample; type
**predict** *...* **if e(sample)** *...* if wanted only for the estimation sample.
Starred statistics are calculated only for the estimation sample, even
when **if e(sample)** is not specified.

__Menu for predict__

**Statistics > Postestimation**

__Description for predict__

**predict** creates a new variable containing predictions such as linear
predictions, standard errors, fitted values, residuals, and standardized
residuals.

__Options for predict__

+------+
----+ Main +-------------------------------------------------------------

**xb**, the default, calculates the linear prediction xb based on the
estimated fixed effects (coefficients) in the model. This is
equivalent to fixing all random effects in the model to their
theoretical mean value of 0.

**stdp** calculates the standard error of the linear predictor xb.

**reffects** calculates best linear unbiased predictions (BLUPs) of the
random effects. By default, BLUPs for all random effects in the
model are calculated. However, if the **relevel(***levelvar***)** option is
specified, then BLUPs for only level *levelvar* in the model are
calculated. For example, if **class**es are nested within **school**s, then
typing

**. predict b*, reffects relevel(school)**

would produce BLUPs at the school level. You must specify q new
variables, where q is the number of random-effects terms in the model
(or level). However, it is much easier to just specify *stub****** and let
Stata name the variables *stub***1**, *stub***2**, ..., *stub*q for you.

Rabe-Hesketh and Skrondal (2012, sec. 2.11.2) discuss the link
between the empirical Bayes predictions and BLUPs and how these
predictions are unbiased. They are unbiased when the groups
associated with the random effects are expected to vary in repeated
samples. If you expect the groups to be fixed in repeated samples,
then these predictions are no longer unbiased.

**reses(***newvarsspec***)** calculates the standard errors of the BLUPs of the
random effects. By default, standard errors for all BLUPs in the
model are calculated. However, if the **relevel(***levelvar***)** option is
specified, then standard errors for only level *levelvar* in the model
are calculated; see the **reffects** option.

You must specify q new variables, where q is the number of
random-effects terms in the model (or level). However, it is much
easier to just specify *stub****** and let Stata name the variables *stub***1**,
*stub***2**, ..., *stub*q for you. The new variables will have the same
storage type as the corresponding random-effects variables.

The **reffects** and **reses()** options often generate multiple new
variables at once. When this occurs, the random effects (or standard
errors) contained in the generated variables correspond to the order
in which the variance components are listed in the output of **mixed**.
Still, examining the variable labels of the generated variables (with
the **describe** command, for instance) can be useful in deciphering
which variables correspond to which terms in the model.

**fitted** calculates fitted values, which are equal to the fixed-portion
linear predictor plus contributions based on predicted random
effects, or in mixed-model notation, xb + Zu. By default, the fitted
values take into account random effects from all levels in the model,
however, if the **relevel(***levelvar***)** option is specified, then the
fitted values are fit beginning at the topmost level down to and
including level *levelvar*. For example, if **class**es are nested within
**school**s, then typing

**. predict yhat_school, fitted relevel(school)**

would produce school-level predictions. That is, the predictions
would incorporate school-specific random effects but not those for
each class nested within each school.

**residuals** calculates residuals, equal to the responses minus fitted
values. By default, the fitted values take into account random
effects from all levels in the model; however, if the
**relevel(***levelvar***)** option is specified, then the fitted values are fit
beginning at the topmost level down to and including level *levelvar*.

**rstandard** calculates standardized residuals, equal to the residuals
multiplied by the inverse square root of the estimated error
covariance matrix.

**scores** calculates the parameter-level scores, one for each parameter in
the model including regression coefficients and variance components.
The score for a parameter is the first derivative of the log
likelihood (or log pseudolikelihood) with respect to that parameter.
One score per highest-level group is calculated, and it is placed on
the last record within that group. Scores are calculated in the
estimation metric as stored in **e(b)**.

**scores** is not available after restricted maximum-likelihood (REML)
estimation.

**relevel(***levelvar***)** specifies the level in the model at which predictions
involving random effects are to be obtained; see the options above
for the specifics. *levelvar* is the name of the model level and is
either the name of the variable describing the grouping at that level
or is **_all**, a special designation for a group comprising all the
estimation data.

__Syntax for margins__

**margins** [*marginlist*] [**,** *options*]

**margins** [*marginlist*] **,** __pr__**edict(***statistic *...**)** [*options*]

*statistic* Description
-------------------------------------------------------------------------
**xb** linear prediction for the fixed portion of the model
only; the default
__ref__**fects** not allowed with **margins**
__sc__**ores** not allowed with **margins**
**stdp** not allowed with **margins**
__fit__**ted** not allowed with **margins**
__res__**iduals** not allowed with **margins**
__rsta__**ndard** not allowed with **margins**
-------------------------------------------------------------------------

Statistics not allowed with **margins** are functions of stochastic
quantities other than **e(b)**.

For the full syntax, see **[R] margins**.

__Menu for margins__

**Statistics > Postestimation**

__Description for margins__

**margins** estimates margins of response for linear predictions.

__Syntax for test and testparm__

__te__**st** **(***spec***)** [**(***spec***)** ...] [**,** *test_options* **small**]

**testparm** *varlist* [**,** *testparm_options* **small**]

__Menu for test and testparm__

**Statistics > Postestimation**

__Description for test and testparm__

**test** and **testparm**, by default, perform chi-squared tests of simple and
composite linear hypotheses about the parameters for the most recently
fit **mixed** model. They also support F tests with a small-sample
adjustment for fixed effects.

__Options for test and testparm__

+---------+
----+ Options +----------------------------------------------------------

*test_options*; see **[R] test** options. Options **df()**, **common**, and **nosvyadjust**
may not be specified together with **small**.

*testparm_options*; see options of *testparm* in **[R] test**. Options **df()** and
**nosvyadjust** may not be specified together with **small**.

**small** specifies that F tests for fixed effects be carried out with the
denominator degrees of freedom (DDF) obtained by the same method used
in the most recently fit **mixed** model. If option **dfmethod()** is not
specified in the previous **mixed** command, option **small** is not allowed.
For certain methods, the DDF for some tests may not be available.
See *Small-sample inference for fixed effects* in **[ME] mixed** for more
details.

__Syntax for lincom__

**lincom** *exp* [**,** *lincom_options* **small**]

__Menu for lincom__

**Statistics > Postestimation**

__Description for lincom__

**lincom**, by default, computes point estimates, standard errors, z
statistics, p-values, and confidence intervals for linear combinations of
coefficients after **mixed**. **lincom** also provides t statistics for linear
combinations of the fixed effects, with the degrees of freedom calculated
by the DF method specified in option **dfmethod()** of **mixed**.

__Options for lincom__

*lincom_options*; see **[R] lincom** options. Options **df()** may not be specified
together with **small**.

**small** specifies that t statistics for linear combinations of fixed
effects be displayed with the degrees of freedom obtained by the same
method used in the most recently fit **mixed** model. If option
**dfmethod()** is not specified in the previous **mixed** command, option
**small** is not allowed. For certain methods, the degrees of freedom
for some linear combinations may not be available. See *Small-sample*
*inference for fixed effects* in **[ME] mixed** for more details.

__Syntax for contrast__

**contrast** *termlist* [**,** *contrast_options* **small**]

__Menu for contrast__

**Statistics > Postestimation**

__Description for contrast__

**contrast**, by default, performs chi-squared tests of linear hypotheses and
forms contrasts involving factor variables and their interactions for the
most recently fit **mixed** model. **contrast** also supports tests with
small-sample adjustments after **mixed, dfmethod()**.

__Options for contrast__

*contrast_options*; see **[R] contrast** options. Options **df()** and **nosvyadjust**
may not be specified together with **small**.

**small** specifies that tests for contrasts be carried out with the DDF
obtained by the same method used in the most recently fit **mixed**
model. If option **dfmethod()** is not specified in the previous **mixed**
command, option **small** is not allowed. For certain methods, the DDF
for some contrasts may not be available. See *Small-sample inference*
*for fixed effects* in **[ME] mixed** for more details.

__Syntax for pwcompare__

**pwcompare** *marginlist* [**,** *pwcompare_options* **small**]

__Menu for pwcompare__

**Statistics > Postestimation**

__Description for pwcompare__

**pwcompare** performs pairwise comparisons across the levels of factor
variables from the most recently fit **mixed** model. **pwcompare**, by default,
reports the comparisons as contrasts (differences) of margins along with
z tests or confidence intervals for the pairwise comparisons. **pwcompare**
also supports t tests with small-sample adjustments after **mixed,**
**dfmethod()**.

__Options for pwcompare__

*pwcompare_options*; see **[R] pwcompare** options. Options **df()** may not be
specified together with **small**.

**small** specifies that t tests for pairwise comparisons be carried out with
the degrees of freedom obtained by the same method used in the most
recently fit **mixed** model with the **dfmethod()** option. If option
**dfmethod()** is not specified in the previous **mixed** command, option
**small** is not allowed. For certain methods, the degrees of freedom
for some pairwise comparisons may not be available. See *Small-sample*
*inference for fixed effects* in **[ME] mixed** for more details.

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse pig**
**. mixed weight week || id: week, covariance(unstructured)**

Random-effects correlation matrix for level ID
**. estat recovariance, correlation**

Display within-cluster marginal standard deviations and correlations for
a cluster
**. estat wcorrelation, format(%4.2g)**

BLUPS of random effects and standard errors of BLUPs
**. predict u1 u0, reffects reses(s1 s0)**

---------------------------------------------------------------------------
Setup
**. webuse productivity, clear**
**. mixed gsp private emp hwy water other unemp || region: ||** **state:**

Summarize composition of nested groups
**. estat group**

Fitted values at region level
**. predict gsp_region, fitted relevel(region)**

Log likelihood scores
**. predict double sc*, scores**

Compute residual intraclass correlations
**. estat icc**

---------------------------------------------------------------------------
Setup
**. webuse childweight, clear**
**. mixed weight age || id: age, covariance(unstructured)**

Display within-cluster correlations for the first cluster
**. estat wcorrelation, list**

Display within-cluster correlations for ID 258
**. estat wcorrelation, at(id=258) list**

---------------------------------------------------------------------------
Setup
**. webuse pig, clear**
**. mixed weight i.week || id:, reml**

Calculate and compare the DFs using three different methods
**. estat df, method(kroger anova repeated)**

Post the **kroger** method to **e()**
**. estat df, method(kroger) post**

Test that coefficient on **2.week** equals coefficient on **3.week**, and adjust
for small sample using the Kenward-Roger method
**. test 2.week = 3.week, small**

---------------------------------------------------------------------------
Setup
**. webuse pig, clear**
**. mixed weight i.week || id:, reml dfmethod(kroger)**

Test that coefficient on **2.week** equals coefficient on **3.week**, and adjust
for small sample using the Kenward-Roger method
**. test 2.week = 3.week, small**

Test that all coefficients on **i.week** are 0, and adjust for small sample
using the Kenward-Roger method
**. testparm i.week, small**

Estimate a linear combination of fixed effects, and adjust for small
sample using the Kenward-Roger method
**. lincom 2.week + 3.week, small**

---------------------------------------------------------------------------
Setup
**. webuse cont3way, clear**
**. mixed y sex##race || group:, reml dfmethod(kroger)**

Test the main effects of each factor with small-sample adjustment using
the Kenward-Roger method
**. contrast sex race, small**

Test the reference category contrasts of **race**, and adjust for small
sample
**. contrast r.race, small**

Test the interaction effects with small-sample adjustment
**. contrast race#sex, small**

---------------------------------------------------------------------------

__Stored results__

**pwcompare** with option **small** stores the following in **r()**:

Matrices
**r(L_df)** degrees of freedom for each margin difference
**r(M_df)** degrees of freedom for each margin estimate

**pwcompare** with options **post** and **small** stores the following in **e()**:

Matrices
**e(L_df)** degrees of freedom for each margin difference
**e(M_df)** degrees of freedom for each margin estimate

__Reference__

Rabe-Hesketh, S., and A. Skrondal. 2012. *Multilevel and Longitudinal*
*Modeling Using Stata*. 3rd ed. College Station, TX: Stata Press.