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

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


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Re: split, combine and verify datafile(s)
Date   Sat, 18 Jun 2005 10:25:17 -0400

You failed to properly reference the tempfile in your merge statement. You should read up on using tempfiles. The name of the tempfile must be enclosed in single quotes.

don't code this:
merge patid using "`file'_temp"


instead code this:
merge patid using "``file'_temp'"

tempfile assigns a local macro (that you name) the name of a tempfile (that Stata selects and you usually never see). When you want to refer to the actual tempfile filename you need to remember to use the single quotes so Stata evaluates the local macro to give you the actual filename.

I think you added to the confusion by having using a macro as part of the tempfile name. You don't really need to name your tempfile `file'_temp, you could just name it temp and Stata should take care of the rest.

Michael Blasnik
michael.blasnik@verizon.net

----- Original Message ----- From: "Katsuhide Isa" <katu@ier.hit-u.ac.jp>
To: <statalist@hsphsun2.harvard.edu>
Sent: Saturday, June 18, 2005 8:18 AM
Subject: st: Re: split, combine and verify datafile(s)



Michael,

Thank you for your suggestion.
Following your suggestion, I modified the original codes as
follows:

foreach file in sysdsn32 sysdsn33 sysdsn34 {
use `file'
sort patid
tempfile `file'_temp
save ``file'_temp'
use sysdsn31
sort patid
capture drop _merge
merge patid using "`file'_temp"
save sysdsn31, replace
}

But when running these codes, I got an error, saying

file sysdsn32_temp.dta not found
r(601);

What would be the problem?
Or there may be any misunderstanding in my modification.

Any suggestions welcome.
Thanks in advance.

K.I.
*
*   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