The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Countries » Kenya » Merging Datasets
Merging Datasets [message #11625] Tue, 17 January 2017 19:14 Go to next message
fadams12 is currently offline  fadams12
Messages: 1
Registered: January 2017
Location: Atlanta

Hi I am doing my thesis using DHS 2008-9 DHS dataset. I am having trouble merging these datasets KEAR KEIR and KEMR. I have followed the procedure provided in section for merging datasets without any success. Can I please get step by step process I am using SAS for my analysis. Also where can I get the information about these data set since I have look the DHS manual and not see description on datasets.
Re: Merging Datasets [message #11637 is a reply to message #11625] Thu, 19 January 2017 13:19 Go to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 1485
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
Previous Topic: Bed Net Usage in the 2014 DHS
Next Topic: Kenya 2014 Table 13.19
Goto Forum:

Current Time: Sun Oct 21 20:03:31 Eastern Daylight Time 2018