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" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
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
michael.blasnik@verizon.net


----- Original Message ----- From: "Katsuhide Isa" <katu@ier.hit-u.ac.jp>
To: "Statalist" <statalist@hsphsun2.harvard.edu>
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/



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