|
Re: Merging Datasets [message #11637 is a reply to message #11625] |
Thu, 19 January 2017 13:19 |
Bridgette-DHS
Messages: 3218 Registered: February 2013
|
Senior Member |
|
|
Following is a response from Senior DHS Stata Specialist, Tom Pullum:
I do not use SAS. The following Stata program will do this merge. You should be able to figure out the logic. You would also have to change the paths for the input and output files, of course.
* Merge AR IR MR files for Kenya 2008-09 DHS
set more off
use e:\DHS\DHS_data\AR_files\KEAR51FL.dta, clear
* construct id's that can match the IR file or the MR file
gen v001=hivclust
gen v002=hivnumb
gen v003=hivline
sort v001 v002 v003
save e:\DHS\scratch\artemp.dta, replace
use e:\DHS\DHS_data\IR_files\KEIR52FL.dta, clear
sort v001 v002 v003
merge v001 v002 v003 using e:\DHS\scratch\artemp.dta
tab _merge
keep if _merge==3
gen sex=2
save e:\DHS\scratch\KE51_IR_AR.dta, replace
use e:\DHS\DHS_data\AR_files\KEAR51FL.dta, clear
gen mv001=hivclust
gen mv002=hivnumb
gen mv003=hivline
sort mv001 mv002 mv003
save e:\DHS\scratch\artemp.dta, replace
use e:\DHS\DHS_data\MR_files\KEMR52FL.dta
sort mv001 mv002 mv003
merge mv001 mv002 mv003 using e:\DHS\scratch\artemp.dta
tab _merge
keep if _merge==3
gen sex=1
save e:\DHS\scratch\KE51_MR_AR.dta, replace
* NOTE: rename mv variables to match the v variables
rename mv* v*
append using e:\DHS\scratch\KE51_IR_AR.dta
* in this file
sort v001 v002 v003
label define sex 1 "man" 2 "woman"
label values sex sex
tab sex hiv03, row
tab sex hiv03 [iweight=hiv05/1000000], row
save e:\DHS\scratch\KE51_IR_MR_AR.dta, replace
|
|
|