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

st: split, combine and verify datafile(s)


From   "Katsuhide Isa" <[email protected]>
To   Statalist <[email protected]>
Subject   st: split, combine and verify datafile(s)
Date   Fri, 17 Jun 2005 16:56:29 +0900

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:

----------
webuse sysdsn3, clear
sum

local j = 1
local k = 161
forvalues i = 1/4 {
webuse sysdsn3, clear
keep in `j'/`k'
save sysdsn3`i'
local j = `j' + 161
local k = `k' + 161
}
dir sys*

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

sum

----------
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? 

(2)I'd like to verify if the original file(sysdsn3.dta)
 and the newly created one(sysdsn31.dta) are consistent.
Is there a Stata command to implement it?

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