Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Fw: ADO file for ML estimation and temporary variables


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Fw: ADO file for ML estimation and temporary variables
Date   Fri, 17 Sep 2010 09:14:38 +0000 (GMT)

--- On Fri, 17/9/10, Daniele Pacifico wrote:
> Let's assume I have an ado file called "newcmd1.ado" that
> should perform some manipulations of the variables in "varlist"..
> At some point, this ado file calls another ado file -
> "newcmd2.ado" - that should perform the maximisation of a
> likelihood function. The results of this maximisation will be
> used WITHIN "newcmd.ado" (the first one) once the likelihood
> has been estimated (by using newcmd2.ado).
> 
> Okay, the first problem is how to pass the temporary variables
> that  "newcmd1" creates before calling "newcmd2" into the ml
> evaluator contained in "newcmd2".. <snip> this seems really
> impossible!

Here is one example how you might do this:

*------------------- begin example -----------------------
program drop _all

program define newcmd2_lf
  args lnf mu lnsigma
  quietly replace `lnf' = ln( normalden( $ML_y1,  `mu', exp(`lnsigma') ) )
end

program define newcmd2, eclass
    syntax varlist
	gettoken y x : varlist
	ml model lf  newcmd2_lf (mu:`y' = `x') /lnsigma , maximize
	ereturn display
end

program define newcmd1
	syntax varlist(min=2), GENerate(name)
	gettoken y x: varlist
	gettoken xx x : x
	tempvar xx2
	gen `xx2' = `xx'^2
	newcmd2 `y' `xx' `xx2' `x'
	predict `generate', xb eq(#1)
end

sysuse auto, clear
newcmd1 mpg price, gen(foo)

// check if -newcmd1- works:
gen price2 = price^2
reg mpg price price2
predict xb
scatter xb foo, aspect(1) || function y=x, range(15 26)
*--------------------------- end example ---------------------

The most efficient way of programming such a thing depends on
all the little details of your problem, so you are the only person
who can do that. However, this example shows at least that it
is possible.

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index