The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » merging HR and IR
Re: merging HR and IR [message #13843 is a reply to message #13838] Thu, 11 January 2018 08:18 Go to previous messageGo to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3040
Registered: February 2013
Senior Member
Following is a response from Senior DHS Stata Specialist, Tom Pullum:

In every survey, there are some households that have no eligible women. Those will show up as cases in the merged file for which the diagnostic variable "_merge" is different from 3. If you drop such cases, you will get as many cases as there are in the IR file. I have written lines for this kind of merge that will attach the education of the household head to the woman, and also the household-level smoking variable hv252. The wealth quintile is already in the IR file. (It is v190 in the IR file and hv270 in the HR file.)

You will have to change the paths and you will not want to reduce the variables the way I have done. Let me know if you have questions.

set more off
use e:\DHS\DHS_data\HR_files\IDHR63FL.dta, clear 
keep hv001 hv002 hv252 hv101* hv106*
rename hv101_0* hv101_*
rename hv106_0* hv106_*

* Identify the household head and the education of the household head
* Note: It appears that in this survey the household head is always on line 1
*   but in many surveys there are some exceptions to this
gen hvidx_hhhead=.
gen ed_hhhead=.

local li=1
while `li'<=31 {
replace hvidx_hhhead=`li'    if hv101_`li'==1
replace ed_hhhead=hv106_`li' if hv101_`li'==1
local li=`li'+1
}

keep hv001 hv002 hv252 *head
rename hv001 v001
rename hv002 v002
sort v001 v002
save e:\DHS\DHS_data\scratch\temp.dta, replace

use e:\DHS\DHS_data\IR_files\IDIR63FL.dta, clear
keep v001 v002 v003 v106 v190 v191
sort v001 v002 v003

merge v001 v002 using e:\DHS\DHS_data\scratch\temp.dta

tab hvidx _merge

* drop cases in the merge for households with no woman in the IR file
drop if _merge~=3
drop _merge

* It may be helpful to know when the woman is in fact the household head
gen woman_is_hhhead=0
replace woman_is_hhhead=1 if hvidx_hhhead==v003

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Merging PR file with KR file
Next Topic: Issue merging household and individual (women's) file
Goto Forum:
  


Current Time: Thu Apr 25 19:44:48 Coordinated Universal Time 2024