The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Countries » Kenya » Merging KR and PR files
Merging KR and PR files [message #28006] Wed, 01 November 2023 12:09 Go to next message
sokiya is currently offline  sokiya
Messages: 80
Registered: May 2017
Location: Nairobi
Senior Member
I am trying to merge the KR file with the PR file using the codes below

use "KEKR8AFL.DTA", clear
drop if b16 == .
duplicates tag v001 v002 b16, gen(dup)
drop if dup!=0
ren (v001 v002 b16) (hv001 hv002 hvidx)
merge 1:1 hv001 hv002 hvidx using "KEPR8AFL.dta"

However, a few issues arise
a) b16 is missing in some case
b) KR file has some duplicates cases in v001 v002 b16

Any help will be greatly appreciated.
Thanks in advance
Re: Merging KR and PR files [message #28016 is a reply to message #28006] Thu, 02 November 2023 08:15 Go to previous messageGo to next message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3202
Registered: February 2013
Senior Member
Following is a response from Senior DHS staff member, Tom Pullum:

The Stata lines pasted below will do this merge. In the KR file, you have to drop children with b16=. (they have died) or b16=0 (they are not in the household).

* Merge the KR and PR files, Kenya 2022 survey

* Specify workspace
cd e:\DHS\DHS_data\scratch

* Prepare KR file
use "...KEKR8BFL.DTA", clear
gen cluster=v001
gen hh=v002

* b16 is na if the child has died and 0 if the child is not in the hh
drop if b16==. | b16==0
gen line=b16
sort cluster hh line
save KR8BKRtemp.dta, replace

* Prepare PR file and merge
use "...KEPR8BFL.DTA", clear
gen cluster=hv001
gen hh=hv002
gen line=hvidx
sort cluster hh line
merge 1:1 cluster hh line using KR8BKRtemp.dta
tab _merge
keep if _merge==3
drop _merge
Re: Merging KR and PR files [message #28024 is a reply to message #28016] Fri, 03 November 2023 05:50 Go to previous message
sokiya is currently offline  sokiya
Messages: 80
Registered: May 2017
Location: Nairobi
Senior Member
Thanks so much for the guidance. I sincerely appreciate.
Previous Topic: Figure 4.4 Trends in early marriage
Next Topic: KDHS 2014 : Table 14.10.1 Health insurance coverage: Women
Goto Forum:
  


Current Time: Mon Dec 2 23:50:57 Coordinated Universal Time 2024