**[ME] mestreg** -- Multilevel mixed-effects parametric survival models

__Syntax__

**mestreg** *fe_equation* [**||** *re_equation*] [**||** *re_equation* ...]**,**
__dist__**ribution(***distname***)** [*options*]

where the syntax of *fe_equation* is

[*indepvars*] [*if*] [*in*] [*weight*] [**,** *fe_options*]

and the syntax of *re_equation* is one of the following:

for random coefficients and intercepts

*levelvar***:** [*varlist*] [**,** *re_options*]

for random effects among the values of a factor variable

*levelvar***:** **R.***varname*

*levelvar* is a variable identifying the group structure for the random
effects at that level or is **_all** representing one group comprising all
observations.

*fe_options* Description
-------------------------------------------------------------------------
Model
__nocons__**tant** suppress constant term from the fixed-effects
equation
__off__**set(***varname***)** include *varname* in model with coefficient
constrained to 1
-------------------------------------------------------------------------

*re_options* Description
-------------------------------------------------------------------------
Model
__cov__**ariance(***vartype***)** variance-covariance structure of the random
effects
__nocons__**tant** suppress constant term from the random-effects
equation
__fw__**eight(***varname***)** frequency weights at higher levels
__iw__**eight(***varname***)** importance weights at higher levels
__pw__**eight(***varname***)** sampling weights at higher levels
-------------------------------------------------------------------------

*options* Description
-------------------------------------------------------------------------
Model
* __dist__**ribution(***distname***)** specify survival distribution
**time** use accelerated failure-time metric
__const__**raints(***constraints***)** apply specified linear constraints
__col__**linear** keep collinear variables

SE/Robust
**vce(***vcetype***)** *vcetype* may be **oim**, __r__**obust**, or __cl__**uster**
*clustvar*

Reporting
__l__**evel(***#***)** set confidence level; default is **level(95)**
**nohr** do not report hazard ratios
__tr__**atio** report time ratios
__nos__**how** do not show st setting information
__nocnsr__**eport** do not display constraints
__notab__**le** suppress coefficient table
__nohead__**er** suppress output header
__nogr__**oup** suppress table summarizing groups
*display_options* control columns and column formats, row
spacing, line width, display of omitted
variables and base and empty cells, and
factor-variable labeling

Integration
__intm__**ethod(***intmethod***)** integration method
__intp__**oints(***#***)** set the number of integration (quadrature)
points for all levels; default is
**intpoints(7)**

Maximization
*maximize_options* control the maximization process; seldom used

__startv__**alues(***svmethod***)** method for obtaining starting values
__startg__**rid**[**(***gridspec***)**] perform a grid search to improve starting
values
__noest__**imate** do not fit the model; show starting values
instead
**dnumerical** use numerical derivative techniques
__coefl__**egend** display legend instead of statistics
-------------------------------------------------------------------------
* **distribution(***distname***)** is required.

*vartype* Description
-------------------------------------------------------------------------
__ind__**ependent** one unique variance parameter per random
effect, all covariances 0; the default
unless the **R.** notation is used
__exc__**hangeable** equal variances for random effects, and one
common pairwise covariance
__id__**entity** equal variances for random effects, all
covariances 0; the default if the **R.**
notation is used
__un__**structured** all variances and covariances to be distinctly
estimated
__fix__**ed(***matname***)** user-selected variances and covariances
constrained to specified values; the
remaining variances and covariances
unrestricted
__pat__**tern(***matname***)** user-selected variances and covariances
constrained to be equal; the remaining
variances and covariances unrestricted
-------------------------------------------------------------------------

*distname* Description
-------------------------------------------------------------------------
__e__**xponential** exponential survival distribution
__logl__**ogistic** loglogistic survival distribution
__ll__**ogistic** synonym for **loglogistic**
__w__**eibull** Weibull survival distribution
__logn__**ormal** lognormal survival distribution
__ln__**ormal** synonym for **lognormal**
__gam__**ma** gamma survival distribution
-------------------------------------------------------------------------

*intmethod* Description
-------------------------------------------------------------------------
__mv__**aghermite** mean-variance adaptive Gauss-Hermite
quadrature; the default unless a crossed
random-effects model is fit
__mc__**aghermite** mode-curvature adaptive Gauss-Hermite
quadrature
__gh__**ermite** nonadaptive Gauss-Hermite quadrature
__lap__**lace** Laplacian approximation; the default for
crossed random-effects models
-------------------------------------------------------------------------

You must **stset** your data before using **mestreg**; see **[ST] stset**.
*indepvars* may contain factor variables; see fvvarlist.
**bayes**, **by**, and **svy** are allowed; see prefix. For more details, see
**[BAYES] bayes: mestreg**.
**vce()** and weights are not allowed with the **svy** prefix.
**fweight**s, **iweight**s, and **pweight**s are allowed; see weight. Only one type
of weight may be specified. Weights are not supported under the
Laplacian approximation or for crossed models.
**startvalues()**, **startgrid**, **noestimate**, **dnumerical**, and **coeflegend** do not
appear in the dialog box.
See **[ME] mestreg postestimation** for features available after estimation.

__Menu__

**Statistics > Multilevel mixed-effects models >** **Parametric survival**
**regression**

__Description__

**mestreg** fits a mixed-effects parametric survival-time model. The
conditional distribution of the response given the random effects is
assumed to be an exponential, Weibull, lognormal, loglogistic, or gamma
distribution. **mestreg** can be used with single- or multiple-record st
data.

__Options__

+-------+
----+ Model +------------------------------------------------------------

**noconstant** suppresses the constant (intercept) term and may be specified
for the fixed-effects equation and for any of or all the
random-effects equations.

**offset(***varname***)** specifies that *varname* be included in the fixed-effects
portion of the model with the coefficient constrained to be 1.

**covariance(***vartype***)** specifies the structure of the covariance matrix for
the random effects and may be specified for each random-effects
equation. *vartype* is one of the following: **independent**,
**exchangeable**, **identity**, **unstructured**, **fixed(***matname***)**, or
**pattern(***matname***)**.

**covariance(independent)** covariance structure allows for a distinct
variance for each random effect within a random-effects equation
and assumes that all covariances are 0. The default is
**covariance(independent)** unless a crossed random-effects model is
fit, in which case the default is **covariance(identity)**.

**covariance(exchangeable)** structure specifies one common variance for
all random effects and one common pairwise covariance.

**covariance(identity)** is short for "multiple of the identity"; that
is, all variances are equal and all covariances are 0.

**covariance(unstructured)** allows for all variances and covariances to
be distinct. If an equation consists of p random-effects terms,
the unstructured covariance matrix will have p(p+1)/2 unique
parameters.

**covariance(fixed(***matname***))** and **covariance(pattern(***matname***))**
covariance structures provide a convenient way to impose
constraints on variances and covariances of random effects. Each
specification requires a *matname* that defines the restrictions
placed on variances and covariances. Only elements in the lower
triangle of *matname* are used, and row and column names of *matname*
are ignored. A missing value in *matname* means that a given
element is unrestricted. In a **fixed(***matname***)** covariance
structure, (co)variance (i,j) is constrained to equal the value
specified in the i,jth entry of *matname*. In a **pattern(***matname***)**
covariance structure, (co)variances (i,j) and (k,l) are
constrained to be equal if *matname*[i,j] = *matname*[k,l].

**fweight(***varname***)** specifies frequency weights at higher levels in a
multilevel model, whereas frequency weights at the first level (the
observation level) are specified in the usual manner, for example,
**[fw=***fwtvar1***]**. *varname* can be any valid Stata variable name, and you
can specify **fweight()** at levels two and higher of a multilevel model.
For example, in the two-level model

**. me**... *fixed_portion* **[fw = wt1]** **|| school:** ... **, fweight(wt2)**
...

the variable **wt1** would hold the first-level (the observation-level)
frequency weights, and **wt2** would hold the second-level (the
school-level) frequency weights.

**iweight(***varname***)** specifies importance weights at higher levels in a
multilevel model, whereas importance weights at the first level (the
observation level) are specified in the usual manner, for example,
**[iw=***iwtvar1***]**. *varname* can be any valid Stata variable name, and you
can specify **iweight()** at levels two and higher of a multilevel model.
For example, in the two-level model

**. me**... *fixed_portion* **[iw = wt1]** **|| school:** ... **, iweight(wt2)**
...

the variable **wt1** would hold the first-level (the observation-level)
importance weights, and **wt2** would hold the second-level (the
school-level) importance weights.

**pweight(***varname***)** specifies sampling weights at higher levels in a
multilevel model, whereas sampling weights at the first level (the
observation level) are specified in the usual manner, for example,
**[pw=***pwtvar1***]**. *varname* can be any valid Stata variable name, and you
can specify **pweight()** at levels two and higher of a multilevel model.
For example, in the two-level model

**. me**... *fixed_portion* **[pw = wt1]** **|| school:** ... **, pweight(wt2)**
...

variable **wt1** would hold the first-level (the observation-level)
sampling weights, and **wt2** would hold the second-level (the
school-level) sampling weights.

**distribution(***distname***)** specifies the survival model to be fit. *distname*
is one of the following: **exponential**, **loglogistic**, **llogistic**,
**weibull**, **lognormal**, **lnormal**, or **gamma**. This option is required.

**time** specifies that the model be fit in the accelerated failure-time
metric rather than in the log relative-hazard metric. This option is
valid only for the exponential and Weibull models because these are
the only models that have both a proportional-hazards and an
accelerated failure-time parameterization. Regardless of metric, the
likelihood function is the same, and models are equally appropriate
in either metric; it is just a matter of changing interpretation.

**time** must be specified at estimation.

**constraints(***constraints***)**, **collinear**; see **[R] estimation options**.

+-----------+
----+ SE/Robust +--------------------------------------------------------

**vce(***vcetype***)** specifies the type of standard error reported, which
includes types that are derived from asymptotic theory (**oim**), that
are robust to some kinds of misspecification (**robust**), and that allow
for intragroup correlation (**cluster** *clustvar*); see **[R] ***vce_option*.
If **vce(robust)** is specified, robust variances are clustered at the
highest level in the multilevel model.

+-----------+
----+ Reporting +--------------------------------------------------------

**level(***#***)**; see **[R] estimation options**.

**nohr**, which may be specified at estimation or upon redisplaying results,
specifies that coefficients rather than exponentiated coefficients be
displayed, that is, that coefficients rather than hazard ratios be
displayed. This option affects only how coefficients are displayed,
not how they are estimated.

This option is valid only for the exponential and Weibull models
because they have a natural proportional-hazards parameterization.
These two models, by default, report hazards ratios (exponentiated
coefficients).

**tratio** specifies that exponentiated coefficients, which are interpreted
as time ratios, be displayed. **tratio** is appropriate only for the
loglogistic, lognormal, and gamma models or for the exponential and
Weibull models when fit in the accelerated failure-time metric.

**tratio** may be specified at estimation or upon replay.

**noshow** prevents **mestreg** from showing the key st variables. This option
is rarely used because most users type **stset**, **show** or **stset, noshow**
to set once and for all whether they want to see these variables
mentioned at the top of the output of every st command; see **[ST]**
**stset**.

**nocnsreport**; see **[R] estimation options**.

**notable** suppresses the estimation table, either at estimation or upon
replay.

**noheader** suppresses the output header, either at estimation or upon
replay.

**nogroup** suppresses the display of group summary information (number of
groups, average group size, minimum, and maximum) from the output
header.

*display_options*: **noci**, __nopv__**alues**, __noomit__**ted**, **vsquish**, __noempty__**cells**,
__base__**levels**, __allbase__**levels**, __nofvlab__**el**, **fvwrap(***#***)**, **fvwrapon(***style***)**,
**cformat(***%fmt***)**, **pformat(%***fmt***)**, **sformat(%***fmt***)**, and **nolstretch**; see **[R]**
**estimation options**.

+-------------+
----+ Integration +------------------------------------------------------

**intmethod(***intmethod***)** specifies the integration method to be used for the
random-effects model. **mvaghermite** performs mean-variance adaptive
Gauss-Hermite quadrature; **mcaghermite** performs mode-curvature
adaptive Gauss-Hermite quadrature; **ghermite** performs nonadaptive
Gauss-Hermite quadrature; and **laplace** performs the Laplacian
approximation, equivalent to mode-curvature adaptive Gaussian
quadrature with one integration point.

The default integration method is **mvaghermite** unless a crossed
random-effects model is fit, in which case the default integration
method is **laplace**. The Laplacian approximation has been known to
produce biased parameter estimates; however, the bias tends to be
more prominent in the estimates of the variance components rather
than in the estimates of the fixed effects.

For crossed random-effects models, estimation with more than one
quadrature point may be prohibitively intensive even for a small
number of levels. For this reason, the integration method defaults
to the Laplacian approximation. You may override this behavior by
specifying a different integration method.

**intpoints(***#***)** sets the number of integration points for quadrature. The
default is **intpoints(7)**, which means that seven quadrature points are
used for each level of random effects. This option is not allowed
with **intmethod(laplace)**.

The more integration points, the more accurate the approximation to
the log likelihood. However, computation time increases as a
function of the number of quadrature points raised to a power
equaling the dimension of the random-effects specification. In
crossed random-effects models and in models with many levels or many
random coefficients, this increase can be substantial.

+--------------+
----+ Maximization +-----------------------------------------------------

*maximize_options*: __dif__**ficult**, __tech__**nique(***algorithm_spec***)**, __iter__**ate(***#***)**,
[__no__]__lo__**g**, __tr__**ace**, __grad__**ient**, **showstep**, __hess__**ian**, __showtol__**erance**,
__tol__**erance(***#***)**, __ltol__**erance(***#***)**, __nrtol__**erance(***#***)**, __nonrtol__**erance**, and
**from(***init_specs***)**; see **[R] maximize**. Those that require special
mention for **mestreg** are listed below.

**from()** accepts a properly labeled vector of initial values or a list
of coefficient names with values. A list of values is not allowed.

The following options are available with **mestreg** but are not shown in the
dialog box:

**startvalues(***svmethod***)**, **startgrid**[**(***gridspec***)**], **noestimate**, and **dnumerical**;
see **[ME] meglm**.

**coeflegend**; see **[R] estimation options**.

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse catheter**

Two-level random-intercept Weibull survival model, analogous to **xtstreg**
**. mestreg age female || patient:, distribution(weibull)**

Two-level random-intercept Weibull survival model in the accelerated
failure-time metric
**. mestreg age female || patient:, distribution(weibull) time**

Two-level random-intercept gamma survival model
**. mestreg age female || patient:, distribution(gamma)**

---------------------------------------------------------------------------
Setup
**. webuse jobhistory**
**. stset tend, origin(tstart) fail(failure)**

Three-level random-intercept lognormal survival model
**. mestreg education njobs prestige i.female || birthyear: || id:,**
**distribution(lognormal)**

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

__Stored results__

**mestreg** stores the following in **e()**:

Scalars
**e(N)** number of observations
**e(k)** number of parameters
**e(k_eq)** number of equations in **e(b)**
**e(k_eq_model)** number of equations in overall model test
**e(k_dv)** number of dependent variables
**e(k_f)** number of fixed-effects parameters
**e(k_r)** number of random-effects parameters
**e(k_rs)** number of variances
**e(k_rc)** number of covariances
**e(df_m)** model degrees of freedom
**e(ll)** log likelihood
**e(chi2)** chi-squared
**e(p)** p-value for model test
**e(ll_c)** log likelihood, comparison model
**e(chi2_c)** chi-squared, comparison test
**e(df_c)** degrees of freedom, comparison test
**e(p_c)** p-value for comparison test
**e(N_clust)** number of clusters
**e(rank)** rank of **e(V)**
**e(ic)** number of iterations
**e(rc)** return code
**e(converged)** **1** if converged, **0** otherwise

Macros
**e(cmd)** **gsem**
**e(cmd2)** **mestreg**
**e(cmdline)** command as typed
**e(depvar)** name of dependent variable
**e(wtype)** weight type
**e(wexp)** weight expression (first-level weights)
**e(fweight***k***)** **fweight** variable for *k*th highest level, if
specified
**e(iweight***k***)** **iweight** variable for *k*th highest level, if
specified
**e(pweight***k***)** **pweight** variable for *k*th highest level, if
specified
**e(covariates)** list of covariates
**e(ivars)** grouping variables
**e(model)** model name
**e(title)** title in estimation output
**e(distribution)** distribution
**e(clustvar)** name of cluster variable
**e(offset)** offset
**e(intmethod)** integration method
**e(n_quad)** number of integration points
**e(chi2type)** **Wald**; type of model chi-squared
**e(vce)** *vcetype* specified in **vce()**
**e(vcetype)** title used to label Std. Err.
**e(frm2)** **hazard** or **time**
**e(opt)** type of optimization
**e(which)** **max** or **min**; whether optimizer is to perform
maximization or minimization
**e(ml_method)** type of **ml** method
**e(user)** name of likelihood-evaluator program
**e(technique)** maximization technique
**e(datasignature)** the checksum
**e(datasignaturevars)** variables used in calculation of checksum
**e(properties)** **b V**
**e(estat_cmd)** program used to implement **estat**
**e(predict)** program used to implement **predict**
**e(marginsnotok)** predictions disallowed by **margins**
**e(marginswtype)** weight type for **margins**
**e(marginswexp)** weight expression for **margins**
**e(asbalanced)** factor variables **fvset** as **asbalanced**
**e(asobserved)** factor variables **fvset** as **asobserved**

Matrices
**e(b)** coefficient vector
**e(Cns)** constraints matrix
**e(ilog)** iteration log (up to 20 iterations)
**e(gradient)** gradient vector
**e(N_g)** group counts
**e(g_min)** group-size minimums
**e(g_avg)** group-size averages
**e(g_max)** group-size maximums
**e(V)** variance-covariance matrix of the estimators
**e(V_modelbased)** model-based variance

Functions
**e(sample)** marks estimation sample