# Re: st: re: ML program and ML maximize help

 From Greg Evans To statalist@hsphsun2.harvard.edu Subject Re: st: re: ML program and ML maximize help Date Thu, 11 Sep 2008 14:40:07 -0400

Thanks Kit.

You are absolutely right about fixing this error leading to several others. I've managed to work through some of them, but am still having some problems, though the problem appears to be closer to the likelihood itself (which is progress!).

The lnf variable seems to get replaced with "ML_f" and then Stata gives me an error that ML_f is not found. It appears to have to do with my attempt to do a 3 step likelihood (when I take the 2 steps out and just try to do one, I get an error " { required "). At no time do I create or refer to ML_f so this appears to be something Stata does on it's own.

Here I will reprint the likelihood portion and below I will produce the error:

mlsum `lnf'= -ln(`sigma') - (1/(2*`sigma'^2))*(\$ML_y1 + `alpha1' - `beta')^2 if \$ML_y1 < 0
replace `lnf' = -ln(`sigma') - (1/(2*`sigma'^2))*(\$ML_y1 + `alpha2' - `beta')^2 if \$ML_y1 > 0
replace `lnf' = ln(normal(`alpha2'-`beta')/`sigma') - normal(`alpha1'-`beta')/`sigma') if \$ML_y1=0
if `last' == 1

Below is the error code from the ml check output (it's ugly, but I'm copying and pasting just as is without cleaning anything up for fear I would change anything):

- mlsum `lnf'= -ln(`sigma') - (1/(2*`sigma'^2))*(\$ML_y1 + `alph
> a1' - `beta')^2 if \$ML_y1 < 0
= mlsum ML_f= -ln(__00000F) - (1/(2*__00000F^2))*(ri_r + __0000
> 0C - __00000E)^2 if ri_r < 0
- replace `lnf' = -ln(`sigma') - (1/(2*`sigma'^2))*(\$ML_y1 + `a
> lpha2' - `beta')^2 if \$ML_y1 > 0
= replace ML_f = -ln(__00000F) - (1/(2*__00000F^2))*(ri_r + __0
> 0000D - __00000E)^2 if ri_r > 0
replace `lnf' = ln(normal(`alpha2'-`beta')/`sigma') - normal(
> `alpha1'-`beta')/`sigma') if \$ML_y1=0
if `last' == 1
}

~~~~~~~~~~~~~~~~~~~~~
Greg Evans
University of Georgia
Choose Happy!

Kit Baum wrote:

< >
global stock

program define lesmond
version 10.1
args todo b lnf
tempvar alpha1 alpha2 beta sigma last
mleval `alpha1' = `b', eq(1)
mleval `alpha2' = `b', eq(2)
mleval `beta' = `b', eq(3)
mleval `sigma' = `b', eq(4)
// MY_panel contains the panel ID
local by \$stock
sort `by'

I don't think this has anything to do with ML. Your 'global stock' defines the macro \$stock as empty, and then you say

local by \$stock

which will cause the local to be empty, and then you

sort `by'

which evaluates to

sort

It is true that sort requires a varlist. This is why you're getting a `varlist required' error. Define the stock macro as having some content and it should work (or at least give you a new, interesting error message).

Cheers
Kit

Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html

*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

```*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```