The problem is that your tempfile command is doing nothing but reserving a
name for a tempfile. The save command precedes it and uses a valid
filename, so those files are saved and are left behind at the end of the
program. If you want them to be tempfiles you need to change the order of
the commands and fix the save command:
tempfile `file'_temp
save ``file'_temp'
Note that the save command needs to have the tempfile name enclosed in
single quotes because tempfile creates a local macro.
Michael Blasnik
[email protected]
----- Original Message -----
From: "Katsuhide Isa" <[email protected]>
To: "Statalist" <[email protected]>
Sent: Friday, June 17, 2005 3:56 AM
Subject: st: split, combine and verify datafile(s)
Dear Statalisters,
I wrote the following codes (as a pure practice of -merge-)
to split a sample dataset(sysdsn3.dta) into four sub-files
(sysdsn31.dta-sysdsn34.dta) and re-combine them:
<snip>
foreach file in sysdsn32 sysdsn33 sysdsn34 {
use `file'
sort patid
save "`file'_temp", replace
tempfile `file'_temp
<snip>
I have two questions about above codes:
(1) The codes worked almost alright, except the statements
-tempfile `file'_temp-.
Namely,
sysdsn32_temp.dta
sysdsn33_temp.dta
sysdsn34_temp.dta
remain in the current directory after macro execution.
What is the problem?
*
* 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/