The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Merging IR, KR and HR files
Re: Merging IR, KR and HR files [message #29796 is a reply to message #29789] Tue, 06 August 2024 16:00 Go to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3199
Registered: February 2013
Senior Member
Following is a response from Senior DHS staff member, Tom Pullum:

You would only do this kind of merge if you need IR and HR variables that are not already in the KR file. That seems to be your situation. The Stata program below will do this merge. Let us know if you have questions about it.

* Merge needed variables from the HR and IR files onto the KR file
* This illustrative example just adds one HR variable and some v75* variables
*  from the IR file.  You would add other variables. 

* Illustrated with NFHS-5

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

* Prepare HR file
use "...IAHR7EFL.DTA", clear 
rename hv001 cluster
rename hv002 hh 

* keep the merging variables and other needed HR variables
keep cluster hh hv201
save HRtemp.dta, replace

* Prepare IR file
use "...IAIR7EFL.DTA", clear 
rename v001 cluster
rename v002 hh
rename v003 line
*keep the merging variables and other needed IR variables
keep cluster hh line v75*
save IRtemp.dta, replace

* Prepare KR file
use "...IAKR7EFL.DTA", clear 
rename v001 cluster
rename v002 hh
rename v003 line

* keep just the merging variables
keep cluster hh line
save KRtemp.dta, replace

* Do the merge, starting with KR, then adding IR and HR
use KRtemp.dta, clear

* m:1 because many children to one woman
merge m:1 cluster hh line using IRtemp.dta
tab _merge

* _merge=2 for women in the IR file who do not have a child in the KR file
keep if _merge==3
drop _merge

* m:1 because many children to one household
merge m:1 cluster hh using HRtemp.dta
tab _merge

* _merge=2 for households in the HR file that do not have a child in the KR file
keep if _merge==3
drop _merge
 
Read Message
Read Message
Previous Topic: Merging data
Next Topic: Merging data files
Goto Forum:
  


Current Time: Thu Nov 28 06:28:47 Coordinated Universal Time 2024