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

st: Re: split, combine and verify datafile(s)

From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: split, combine and verify datafile(s)
Date   Fri, 17 Jun 2005 07:23:08 -0400

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:

foreach file in sysdsn32 sysdsn33 sysdsn34 {
use `file'
sort patid
save "`file'_temp", replace
tempfile `file'_temp
I have two questions about above codes:

(1) The codes worked almost alright, except the statements
-tempfile `file'_temp-.


remain in the current directory after macro execution.
What is the problem?
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index