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

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*


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? 

(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.

*   For searches and help try:

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