Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: ADO file for ML estimation and temporary variables


From   Daniele Pacifico <danielepacifico@yahoo.it>
To   statalist@hsphsun2.harvard.edu
Subject   st: ADO file for ML estimation and temporary variables
Date   Thu, 16 Sep 2010 15:33:12 +0000 (GMT)

Dear Stata users,

I am trying to write an ado file for a maximum likelihood estimator and I hope 
you can help me with a problem I had..

Okay, let's assume I have an ado file called "newcmd1.ado" that should perform 
some manipulations of the variables in "varlist"..
Here is the syntax:
**********************************
program newcmd1
newcmd1 varlist [if] [in], etc...
**********************************
Please, note that "newcmd1.ado" is not an estimation command.. It just performs 
manipulations of existing variables..

At some point, this ado file calls another ado file - "newcmd2.ado" - that 
should perform the maximisation of a likelihood function. Then, the results of 
this maximisation will be used WITHIN "newcmd.ado" (the first one) once the 
likelihood has been estimated (by using newcmd2.ado).

Hence, in the middle of "newcmd1" it appears the syntax for the other ado file 
"newcom2" so as to call it:
**********************************
newcmd2 varlist2 [if] [in], etc..
**********************************
Since this is an estimation file, we also need "newcmd2_ll", which contains the 
secret ml evaluator..

Okay, the first problem is how to pass the temporary variables that 
"newcmd1" creates before calling "newcmd2" into the ml evaluator contained 
in "newcmd2".. Importantly, these variables are EXTRA variables with respect to 
those in "varlist2", i.e. the list of variables that I want to compute the 
parameters of (see the syntax of newcmd2 above for "varlist2"..).
More crucially, these "extra" temporary variables should also be read WITHIN 
newcmd2_ll.. but this seems really impossible! 
I hope I was clear enough.. Here is an example of my problem:

______Start example_______
In "newcmd1.ado" I create a local variable `age' and a local scalar `ls'.. both 
these elements will be needed within "newcmd2.ado"..

In "newcmd2.ado" I specified the syntax line as:

**********
program newcmd2
syntax varlist [if] [in], ncl(real) othervar(varlist)
**********

Hence - in "newcmd1" - I can write this:

**********
local varlist2 `sex educ'
newcom2 `varlist2', ncl(`ls') othervar(`age')
**********
______End example_________

In this way, I manage somehow to pass the elements I need - the scalar `ls' and 
the variable `age' - from "newcmd1.ado" to "newcmd2.ado"..
Clearly, in "newcmd2" the scalar `ls' is now called `ncl' and the local variable 
`age' is now `othervar'.. (Isn't this a waste of memory by the way?).

Well, these two elements are then used within "newcmd2.ado" to create some NEW 
elements: new temporary variables and new local scalars..
So, I would like to pass these new elements from "newcmd2" to "newcmd2_ll" since 
they enter the likelihood function I want to maximize.. However, neither `ncl' 
nor `othervar' can be read within newcmd2_ll... How is it possible? How can I 
push a temporary variable created within newcmd2.ado into the ml evaluator 
"newcmd2_ll"?

Hope you can help me!  do not know what else I can try!


Thanks in advance,
Daniele Pacifico


      


*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index