Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Max likelihood programing and sub-routines


From   [email protected] (Jeff Pitblado, Stata Corp.)
To   [email protected]
Subject   Re: st: Max likelihood programing and sub-routines
Date   Mon, 27 Jan 2003 17:30:55 -0600

Hoetker, Glenn <[email protected]> asks about -ml- programming:

> Hi all.  I am trying to develop an ado file that calls a maximum
> likelihood estimator and am having a horrid time.  I've included the
> code below.  When it reaches " ml model lf palogit (`dep'=`xvars'
> `group') (delta: `group', nocons)", execution stops with "Unrecognized
> command:  palogit
> program palogit not found".  

> Yet from the documentation and various examples, defining palogit at the
> bottom of the program would appear to be a valid means of defining a
> sub-routine.  What am I doing wrong?  Do I need to have palogit defined
> as a separate ado file (I really hope not for ease of distribution)?

> (example code)
>
> program define complogit
> 	version 8.0
> 	syntax varlist, Group(varlist min=1 max=1)
> 	capture program drop palogit
> 	
> //Parse variable list
> 	gettoken dep xvars : varlist
> 	
> //Run logit equations and save results
> 	logit `dep' `xvars'
> 	estimates store all
> 	
> 	ml model lf palogit (`dep'=`xvars' `group') (delta: `group', nocons)
> 	ml search
> 	ml maximize
> end
> 
> program palogit
> 	version 8
> 	args lnf theta delta
> 	quietly replace `lnf'= 				///
> 	$ML_y1 * `theta' * (1+`delta')- 		///
> 	ln(1+exp(`theta' * (1+`delta')))
> end

Glenn is correct that "sub-routine"s of a program in an ado-file are defined
in the same file after the main program definition.  Such sub-routines are
then callable by the main program and other sub-routines but not by anyone
else.

Now the command (within -complogit-)

 	ml model lf palogit (`dep'=`xvars' `group') (delta: `group', nocons)

passes -palogit- as an argument to -ml model-.  This "argument" is actually a
program name that -ml- will call to get likelihood values.  Thus, -palogit-
must be contained in its own ado-file.

This is true of all commands that use -ml-.

--Jeff
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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