**[R] ml** -- Programs for use by ml method d0, d1, d2, lf0, lf1, lf2, and gf0
log-likelihood evaluators

__Syntax for subroutines for use by ml log-likelihood evaluators__

**mleval** *newvar* **=** *vecname* [**,** **eq(***#***)**]

**mleval** *scalarname* **=** *vecname* **,** **scalar** [**eq(***#***)**]

**mlsum** *scalarname_lnf* **=** *exp* [*if*] [**,** __nowei__**ght**]

**mlvecsum** *scalarname_lnf* *rowvecname* **=** *exp* [*if*] [**,** **eq(***#***)**]

**mlmatsum** *scalarname_lnf* *matrixname* **=** *exp* [*if*] [**,** **eq(***#*[**,***#*]**)**]

**mlmatbysum** *scalarname_lnf* *matrixname* *varname_a* *varname_b* [*varname_c*]
[*if*] **,** **by(***varname***)** [**eq(***#*[**,***#*]**)**]

__Description__

These commands assist in coding the likelihood-evaluation program when
using **ml** methods d0, d1, d2, lf0, lf1, lf2, and gf0. They are of no
assistance when coding a method lf evaluator.

**mleval** is a subroutine used by method d0, d1, d2, lf0, lf1, lf2, and gf0
evaluators to evaluate the coefficient vector that they are passed.

**mlsum** is a subroutine used by method d0, d1, and d2 evaluators to define
the value ln L that is to be returned.

**mlvecsum** is a subroutine used by method d1 and d2 evaluators to define
the gradient vector g that is to be returned. It is suitable for use
only when the likelihood function meets the linear-form restrictions.

**mlmatsum** is a subroutine for use by method d2 and lf2 evaluators to
define the Hessian matrix, H, that is to be returned. It is suitable for
use only when the likelihood function meets the linear-form restrictions.

**mlmatbysum** is a subroutine for use by method d2 evaluator to help define
the Hessian matrix, H, that is to be returned. It is suitable for use
when the likelihood function contains terms made up of grouped sums, such
as in panel-data models. For such models, use **mlmatsum** to compute the
observation-level outer products and **mlmatbysum** to compute the
group-level outer products. **mlmatbysum** requires that the data be sorted
by the variable identified in the **by()** option.

__Options for use with mleval__

**eq(***#***)** specifies the equation number, *i*, for which *theta_ij* = *x_ij* * *b_i*
is to be evaluated. **eq(1)** is assumed if **eq()** is not specified.

**scalar** asserts that the *i*th equation is known to evaluate to a constant,
meaning that the equation was specified as **()**, **(***name***:)**, or **/***name* on
the **ml model** statement. If you specify this option, the new variable
created is created as a scalar. If the *i*th equation does not
evaluate to a scalar, an error message is issued.

__Option for use with mlsum__

**noweight** specifies that weights (**$ML_w**) be ignored when summing the
likelihood function.

__Option for use with mlvecsum__

**eq(***#***)** specifies the equation for which a gradient vector *d*ln*L*/*db_i* is to
be constructed. The default is **eq(1)**.

__Option for use with mlmatsum__

**eq(***#*[**,***#*]**)** specifies the equations for which the Hessian matrix is to be
constructed. The default is **eq(1)**, which is the same as **eq(1,1)**,
which means *d*^2ln*L*/(*db_*1 *db*_1'). Specifying **eq(***i***,***j***)** results in
*d*^2ln*L*/(*db_i* *db_j*').

__Options for use with mlmatbysum__

**by(***varname***)** is required and specifies the group variable.

**eq(***#*[**,***#*]**)** specifies the equations for which the Hessian matrix is to be
constructed. The default is **eq(1)**, which is the same as **eq(1,1)**,
which means *d*^2ln*L*/(*db_*1 *db*_1'). Specifying **eq(***i***,***j***)** results in
*d*^2ln*L*/(*db_i* *db_j*').

__Examples__

See mlmethod for outlines of log-likelihood evaluators that use the
**mleval**, **mlsum**, **mlvecsum**, and **mlmatsum** commands. **[R] ml** contains more
examples. Further examples can be found in *Maximum Likelihood Estimation*
*with Stata, 4th Edition* (Gould, Pitblado, and Poi 2010) - available from
StataCorp.