**xtmixed** has been renamed to **mixed**; see **[ME] mixed postestimation**.
**xtmixed** continues to work but, as of Stata 13, is no longer an official
part of Stata. This is the original help file, which we will no longer
update, so some links may no longer work.

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

__Title__

**[XT] xtmixed postestimation** -- Postestimation tools for xtmixed

__Description__

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

Command Description
-------------------------------------------------------------------------
**estat group** summarize the composition of the nested groups
**estat recovariance** display the estimated random-effects covariance
matrix
**estat icc** estimate intraclass correlations
-------------------------------------------------------------------------

The following standard postestimation commands are also available:

Command Description
-------------------------------------------------------------------------
**contrast** contrasts and ANOVA-style joint tests of estimates
**estat** AIC, BIC, VCE, and estimation sample summary
**estimates** cataloging estimation results
**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
-------------------------------------------------------------------------

__Special-interest postestimation commands__

**estat group** reports number of groups and minimum, average, and maximum
group sizes for each level of the model. Model levels are identified by
the corresponding group variable in the data. Because groups are treated
as nested, the information in this summary may differ from what you would
get had you **tabulate**d each group variable yourself.

**estat recovariance** displays the estimated variance-covariance matrix of
the random effects for each level. Random effects can be either random
intercepts, in which case the corresponding rows and columns of the
matrix are labeled as _cons, or random coefficients, in which case the
label is the name of the associated variable in the data.

**estat icc** displays the intraclass correlation for pairs of responses at
each nested level of the model. Intraclass correlations are available for
random-intercept models or for random-coefficient models conditional on
random-effects covariates being equal to zero. They are not available
for crossed-effects models or with residual error structures other than
independent structures.

__Syntax for predict__

Syntax for obtaining best linear unbiased predictions (BLUPs) of random
effects, or the BLUPs' standard errors

**predict** [*type*] {*stub******|*newvarlist*} [*if*] [*in*] **,** {__ref__**fects** | **reses**}
[__l__**evel(***levelvar***)**]

Syntax for obtaining scores after ML estimation

**predict** [*type*] {*stub******|*newvarlist*} [*if*] [*in*] **,** __sc__**ores**

Syntax for obtaining other predictions

**predict** [*type*] *newvar* [*if*] [*in*] [**,** *statistic* __l__**evel(***levelvar***)**]

*statistic* Description
-------------------------------------------------------------------------
Main
**xb** xb, linear predictor for the *fixed* portion of the model
**stdp** standard error of the fixed-portion linear prediction xb
__fit__**ted** fitted values, linear predictor of the fixed portion plus
contributions based on predicted random effects
__r__**esiduals** 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**

__Options for predict__

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

**xb** calculates the linear prediction for the fixed portion of the model.

**stdp** calculates the standard error of the fixed-portion linear
prediction.

**level(***levelvar***)** specifies the level in the model at which predictions
involving random effects are to be obtained; see below 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
**_all**, a special designation for a group comprising all the estimation
data.

**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 **level(***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

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

would be used to obtain 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**...*stubq* for you.

**reses** calculates the standard errors of the best linear unbiased
predictions (BLUPs) of the random effects. By default, standard
errors for all BLUPs in the model are calculated. However, if the
**level(***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**...*stubq* for you.

Option **reses** is not available after estimation with robust/cluster
variances.

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 **xtmixed**. Still,
examining the variable labels of the generated variables (using the
**describe** command, for instance) can be useful in deciphering which
variables correspond to which terms in the model.

**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.

**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 **level(***levelvar***)** option is specified, then the fitted
values are fit beginning at the top-most level down to and including
level *levelvar*. For example, if **class**es are nested within **school**s,
then

**. predict yhat1, fitted level(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 **level(***levelvar***)**
option is specified, then the fitted values are fit beginning at the
top-most 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.

__Syntax for estat group__

**estat** __gr__**oup**

__Menu for estat__

**Statistics > Postestimation**

__Syntax for estat recovariance__

**estat** __recov__**ariance** [**,** __l__**evel(***levelvar***)** __corr__**elation** *matlist_options*]

__Menu for estat__

**Statistics > Postestimation**

__Options for estat recovariance__

**level(***levelvar***)** specifies the level in the model for which the
random-effects covariance matrix is to be displayed. By default, the
covariance matrices for all levels in the model are displayed.
*levelvar* is the name of the model level and is either the name of
variable describing the grouping at that level or **_all**, a special
designation for a group comprising all the estimation data.

**correlation** displays the covariance matrix as a correlation matrix.

*matlist_options* control how the matrix (or matrices) are displayed. See
**[P] matlist** for details.

__Syntax for estat icc__

**estat** **icc** [**,** __l__**evel(***#***)**]

__Menu for estat__

**Statistics > Postestimation**

__Option for estat icc__

**level(***#***)** specifies the confidence level, as a percentage, for confidence
intervals. The default is **level(95)** or as set by **set level**.

__Examples__

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

Random-effects covariance matrix for level id
**. estat recovariance**

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

BLUPS of random effects
**. predict u1 u0, reffects**

Standard errors of BLUPs
**. predict s1 s0, reses**

---------------------------------------------------------------------------
Setup
**. webuse productivity, clear**
**. xtmixed 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 level(region)**

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

Compute residual intraclass correlations
**. estat icc**

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

__Saved results__

**estat recovariance** saves the last-displayed random-effects covariance
matrix in **r(cov)** or in **r(corr)** if it is displayed as a correlation
matrix.

**estat icc** saves the following in **r()**:

Scalars
**r(icc***#***)** level-*#* intraclass correlation
**r(se***#***)** standard errors of level-*#* intraclass correlation
**r(level)** confidence level of confidence intervals

Macros
**r(label***#***)** label for level *#*

Matrices
**r(ci***#***)** vector of confidence intervals (lower and upper) for
level-*#* intraclass correlation

For a *G*-level nested model, *#* can be any integer between 2 and *G*.