Stata 15 help for mlmethod

[R] ml -- User-written evaluator programs for use with ml methods lf, d0, d1, d2, lf0, lf1, lf2, and gf0

Description

The ml command requires a Mata function or Stata program that evaluates the log-likelihood function. This function or program is generically referred to as a user-written evaluator. Evaluator functions written in Mata are documented in [M-5] moptimize(). Evaluator programs written in Stata are documented here.

The ml support commands mleval, mlsum, mlvecsum, mlmatsum, and mlmatbysum are helpful in writing d0, d1, d2, lf0, lf1, lf2, and gf0 evaluator programs; see mleval.

Method lf evaluators

program progname version 15.1 args lnfj theta1 theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... quietly gen double `tmp1' = ... ... quietly replace `lnfj' = ... end

where

`lnfj' variable to be filled in with observation-by-observation values of ln l_j `theta1' variable containing evaluation of 1st equation theta_1j = x_1j * b_1 `theta2' variable containing evaluation of 2nd equation theta_2j = x_2j * b_2 ...

Method d0 evaluators

program progname version 15.1 args todo b lnf tempvar theta1 theta2 ... mleval `theta1' = `b', eq(1) mleval `theta2' = `b', eq(2) // if there is a theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... gen double `tmp1' = ... ... mlsum `lnf' = ... end

where

`todo' always contains 0 (may be ignored) `b' full parameter row vector b=(b_1,b_2,...,b_E) `lnf' scalar to be filled in with overall lnL

Method d1 evaluators

program progname version 15.1 args todo b lnf g tempvar theta1 theta2 ... mleval `theta1' = `b', eq(1) mleval `theta2' = `b', eq(2) // if there is a theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... gen double `tmp1' = ... ... mlsum `lnf' = ... if (`todo'==0 | `lnf'>=.) exit tempname d1 d2 ... mlvecsum `lnf' `d1' = formula for dlnl_j/dtheta_1j, eq(1) mlvecsum `lnf' `d2' = formula for dlnl_j/dtheta_2j, eq(2) ... matrix `g' = (`d1',`d2', ... ) end

where

`todo' contains 0 or 1; 0 ==> `lnf' to be filled in; 1 ==> `lnf' and `g' to be filled in `b' full parameter row vector b=(b_1,b_2,...,b_E) `lnf' scalar to be filled in with overall lnL `g' row vector to be filled in with overall g = dlnL/db

Method d2 evaluators

program progname version 15.1 args todo b lnf g H tempvar theta1 theta2 ... mleval `theta1' = `b', eq(1) mleval `theta2' = `b', eq(2) // if there is a theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... gen double `tmp1' = ... ... mlsum `lnf' = ... if (`todo'==0 | `lnf'>=.) exit tempname d1 d2 ... mlvecsum `lnf' `d1' = formula for dlnl_j/dtheta_1j, eq(1) mlvecsum `lnf' `d2' = formula for dlnl_j/dtheta_2j, eq(2) ... matrix `g' = (`d1',`d2', ... ) if (`todo'==1 | `lnf'>=.) exit tempname d11 d12 d22 ... mlmatsum `lnf' `d11' = formula for d^2lnl_j/dtheta_1j^2, eq(1) mlmatsum `lnf' `d12' = formula for d^2lnl_j/(dtheta_1j dtheta_2j), eq(1,2) mlmatsum `lnf' `d22' = formula for d^2lnl_j/dtheta_2j^2, eq(2) ... matrix `H' = (`d11',`d12', ... \ `d12'',`d22', ... ) end

where

`todo' contains 0, 1, or 2; 0 ==> `lnf' to be filled in; 1 ==> `lnf' and `g' to be filled in; 2 ==> `lnf', `g', and `H' to be filled in `b' full parameter row vector b=(b_1,b_2,...,b_E) `lnf' scalar to be filled in with overall lnL `g' row vector to be filled in with overall g = dlnL/db `H' matrix to be filled in with overall Hessian H = d^2lnL/dbdb'

Method lf0 evaluators

program progname version 15.1 args todo b lnfj tempvar theta1 theta2 ... mleval `theta1' = `b', eq(1) mleval `theta2' = `b', eq(2) // if there is a theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... gen double `tmp1' = ... ... quietly replace `lnfj' = ... end

where

`todo' always contains 0 (may be ignored) `b' full parameter row vector b=(b_1,b_2,...,b_E) `lnfj' variable to be filled in with observation-by-observation values of ln l_j

Method lf1 evaluators

program progname version 15.1 args todo b lnfj g1 g2 ... tempvar theta1 theta2 ... mleval `theta1' = `b', eq(1) mleval `theta2' = `b', eq(2) // if there is a theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... gen double `tmp1' = ... ... quietly replace `lnfj' = ... if (`todo'==0) exit quietly replace `g1' = formula for dlnl_j/dtheta_1j quietly replace `g2' = formula for dlnl_j/dtheta_2j ... end

where

`todo' contains 0 or 1; 0 ==> `lnfj' to be filled in; 1 ==> `lnfj', `g1', `g2', ..., to be filled in `b' full parameter row vector b=(b_1,b_2,...,b_E) `lnfj' variable to be filled in with observation-by-observation values of ln l_j `g1' variable to be filled in with dlnl_j/dtheta_1j `g2' variable to be filled in with dlnl_j/dtheta_2j ...

Method lf2 evaluators

program progname version 15.1 args todo b lnfj g1 g2 ... H tempvar theta1 theta2 ... mleval `theta1' = `b', eq(1) mleval `theta2' = `b', eq(2) // if there is a theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... gen double `tmp1' = ... ... quietly replace `lnfj' = ... if (`todo'==0) exit quietly replace `g1' = formula for dlnl_j/dtheta_1j quietly replace `g2' = formula for dlnl_j/dtheta_2j ... if (`todo'==1) exit tempname d11 d12 d22 lnf ... mlmatsum `lnf' `d11' = formula for d^2lnl_j/dtheta_1j^2, eq(1) mlmatsum `lnf' `d12' = formula for d^2lnl_j/(dtheta_1j dtheta_2j), eq(1,2) mlmatsum `lnf' `d22' = formula for d^2lnl_j/dtheta_2j^2, eq(2) ... matrix `H' = (`d11',`d12', ... \ `d12'',`d22', ... ) end

where

`todo' contains 0, 1, or 2; 0 ==> `lnfj' to be filled in; 1 ==> `lnfj', `g1', `g2', ..., to be filled in; 2 ==> `lnfj', `g1', `g2', ..., and `H' to be filled in; `b' full parameter row vector b=(b_1,b_2,...,b_E) `lnfj' variable to be filled in with observation-by-observation values of ln l_j `g1' variable to be filled in with dlnl_j/dtheta_1j `g2' variable to be filled in with dlnl_j/dtheta_2j ... `H' matrix to be filled in with overall Hessian H = d^2lnL/dbdb'

Method gf0 evaluators

program progname version 15.1 args todo b lnfj tempvar theta1 theta2 ... mleval `theta1' = `b', eq(1) mleval `theta2' = `b', eq(2) // if there is a theta2 ... // if you need to create any intermediate results: tempvar tmp1 tmp2 ... gen double `tmp1' = ... ... quietly replace `lnfj' = ... end

where

`todo' always contains 0 (may be ignored) `b' full parameter row vector b=(b_1,b_2,...,b_E) `lnfj' variable to be filled in with values of the log-likelihood ln l_j

Global macros for use by all evaluators

$ML_y1 name of first dependent variable $ML_y2 name of second dependent variable, if any ... $ML_samp variable containing 1 if observation to be used; 0 otherwise $ML_w variable containing weight associated with observation or 1 if no weights specified

Method lf evaluators can ignore $ML_samp, but restricting calculations to the $ML_samp==1 subsample will speed execution. Method lf evaluators must ignore $ML_w; application of weights is handled by the method itself.

Method d0, d1, d2, lf0, lf1, lf2, and gf0 evaluators can ignore $ML_samp as long as ml model's nopreserve option is not specified. These methods will run more quickly if nopreserve is specified. These evaluators can ignore $ML_w only if they use mlsum, mlvecsum, and mlmatsum to produce final results; see mleval.


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index