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

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


From   Gary Longton <[email protected]>
To   [email protected]
Subject   Re: st: How to pass tempfile names to called do-files
Date   Sat, 10 Apr 2004 14:51:40 -0700

Joseph Coveney wrote:

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?
You can avoid the step assigning the temporary file names to global macros. The temporary filenames/location can be passed directly to the called do-files as arguments via the local macros that were assigned to them with -tempfile-.
I've not done this with called do-files, but have often used the same idea to pass temporary file names to programs defined within a do-file, or to subprograms within a program.

your code, edited accordingly:

--------------------------master.do--------------------------------------------
tempfile tmp1 tmp2 tmp3 tmp4
do cr1 `tmp1'
do cr2 `tmp2'
[etc.]
do an1 `tmp1'
do an2 `tmp2
[etc.]
exit

---------------------------cr1.do----------------------------------------------
odbc load [. . .]
[manipulations to create analysis dataset]
save `1'
exit

---------------------------an1.do----------------------------------------------
use `1', clear
tabulate [. . .]
summarize [. . .]
[etc.]
exit
--------------------------------


I'd add an unnecessary step reassigning the do-file argument to local macro with more meaningful names, e.g.:

---------------------------cr1_rev2.do----------------------------------------------
local outfile `"`1'"'
odbc load [. . .]
[manipulations to create analysis dataset]
save `outfile'
exit
----------------

- Gary




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