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

st: How to pass tempfile names to called do-files


From   Joseph Coveney <jcoveney@bigplanet.com>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   st: How to pass tempfile names to called do-files
Date   Sat, 10 Apr 2004 12:28:38 +0900

In accordance with recommendations from a NetCourse taken some time ago, I'm 
writing a master do-file that calls dataset-creating do-files and then calls 
analysis do-files to act upon the datasets created.  

I would like to use temporary files (-tempfile-) for the analysis datasets that 
are shared.  So, I create a global macro to hold the physical file name in 
order to pass the tempfile to the called do-files so that it can be shared 
between the dataset-creating and analysis do-files.  (Illustrated below.)  

Question:  is this the recommended approach to sharing tempfiles among 
do-files?

Joseph Coveney

--------------------------master.do--------------------------------------------
tempfile tmp1 tmp2 tmp3 tmp4
forvalues fileno = 1/4 {
    save `tmp`fileno'', emptyok
    global crtmp`fileno' : display "`tmp`fileno''"
}
do cr1
do cr2
[etc.]
do an1
do an2
[etc.]
exit

---------------------------cr1.do----------------------------------------------
odbc load [. . .]
[manipulations to create analysis dataset]
save "$crtmp1", replace
exit

---------------------------an1.do----------------------------------------------
use "$crtmp1", clear
tabulate [. . .]
summarize [. . .]
[etc.]
exit

--------------------------------------------------------------------------------



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index