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]
st: Temporary variables, ado files and subprograms
From
Daniele Pacifico <[email protected]>
To
[email protected]
Subject
st: Temporary variables, ado files and subprograms
Date
Mon, 13 Sep 2010 10:01:54 +0000 (GMT)
Dear Stata users,
I am writing an ado file that - at a certain point - calls another ado file with
a ML routine. Let's call these two files "ado1" and "ado2".
The file "ado1" performs some computations and creates many temporary variables.
However, it is not an estimation command, it just creates a lot of variables and
works with them to produce and display relevant results at the end..
The file "ado2" is called within "ado1" and performs a basic ML estimation whose
results are then needed in "ado1"..
Ado2 should use the temporary variables created within "ado1" but - since they
are "local" variables - Stata deletes all tof them when "ado2" is called.. Is
there a way to keep these temporary variables in memory without necessarily
using global macros?
Here is an example of what I mean:
In "ado1" I create 20 local variables that will be filled somehow during the
program (before calling "ado2"):
*************
local times 20
forvalues s=1/`times'{
tempvar h`s'
}
gen double `h1'= something..
*************
Then "ado1" - at some point - launches "ado2":
*************
ml model lf ado2_lf (`varlist2'), maximize
*************
Where `varlist2' is another local macro that is created within ado1..
Ado2 contains (and should use) the temporary variables that are created within
ado1:
*************in "ado2":****
forvalues s=2/`times'{
qui replace `lnf'=`lnf'+`h`s''
tempvar prob`s'
qui gen double `prob`s''=`lnf'+`h`s''
}
*************
However, neither `times' nor the various `h`s'' are defined in ado2.. Clearly,
they don't exist and Stata does not read them in ado2.
Moreover, the temporary variables `prob`s'' that are created within ado2 are not
exported back in ado1 when ado2 finishes to estimate the model..
So, is there a way to tell Stata to "exchange"/"not-delete"/"keep-in-memory"
temporary variables from one subroutine (ado1) to another (ado2)? Of course, I
could create global macros and hard-coded variables but I can't do it, as this
could possibly reset caller’s macros..
Any tricks about it?
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/