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: Dropping Program Saved as an ado-file


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Dropping Program Saved as an ado-file
Date   Wed, 5 Sep 2012 10:31:18 +0200

On Wed, Sep 5, 2012 at 12:44 AM, Christoph Engel wrote:
> I am writing a program, which I wish to save as an ado-file. The program consists of two components: a maximum likelihood estimator, and the program calling the estimator. I need several auxiliary variables that are available in both components. I have found out that this works if I generate them as _x-variables, i.e. as variables with the variable name preceded by an underscore (assuming that users are very unlikely to have such variable names in their original datasets).

I would do this differently:

I assume you have a main program, which calls -ml-, which calls your
likelihood evaluator program, and that you want to create temporary
variables in your main program and use those in your likelihood
evaluator program.

The trick is that temporary variables continue to exist as long as the
program that created them has not ended. So all you need is a way to
pass on the names of those temporary variables from your main program
to your likelihood evaluator program. This can be done with global
macros.

So:

Inside the main program I would do something like:
gettoken y x: varlist
tempvar yvar
qui gen `yvar' = <some manipulation involving `y'>
global yvar "`yvar'"

foreach var of local x {
    tempvar x`var'
    qui gen `x`var'' = <some manipulation involving `var'
    global xvars "$xvars `x`var''
}

Inside the likelihood evaluator program I can than use $yvar and
$xvars to get access to these temporary variables and still have all
the protection provided to me by temporary variables.

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
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