The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » General » MERGING IR AND HR FILE ((Problem with STATA compilation))
MERGING IR AND HR FILE [message #28965] Wed, 03 April 2024 12:31 Go to next message
Noyel Sebastian is currently offline  Noyel Sebastian
Messages: 11
Registered: March 2024
Member
Hello,

I tried to merge the IR file with HR file for NFHS in STATA and used the following codes:

*Saving the IR file alternatively
use IAIR74FL, clear
save irtemp.dta, replace

*Renaming Key variables in HR file.
use IAHR74FL, clear
rename (hv001 hv002) (v001 v002)
save hrtemp.dta, replace

*Merging master IR file with HR file
use irtemp.dta, clear
merge m:1 (v001 v002) using hrtemp.dta
keep if _merge==3
save Merged_File, replace

However, STATA takes a long time to compile and does not merge. Is there any problem with this code? Can you give me an alternative code, if any? I want to extract certain Household characteristics for each woman and Domestic violence characteristics. Later, I have to analyse this with the BR file (by merging it). Can you help me with the IR and HR merger, or are there any alternatives to get the HH characteristics for each record in the BR file?



Thank You
Re: MERGING IR AND HR FILE [message #29008 is a reply to message #28965] Wed, 10 April 2024 09:02 Go to previous messageGo to next message
Janet-DHS is currently offline  Janet-DHS
Messages: 880
Registered: April 2022
Senior Member
Following is a response from DHS staff member, Tom Pullum:

You may not realize that the records in the HR file are VERY wide. They include data for everyone in the household, all on the same record. I suspect that what you really want from the HR file is the information that is specifically about the household, but not about the individual members. If you include a line "drop *_*" then you will drop all the subscripted variables in the HR file, that is, those that refer to individuals.

Also you may not realize that the IR file already includes many household-level variables, often with different names. For example, hv270 in the household file is copied into the IR file as v190.

You may want to merge with the PR file, which has one record for each person in the household, rather than the HR file,

I will paste below Stata lines to merge the IR and HR files. The main difference from what you did is the "drop" line in the preparation of the HR file. This works for me and is fast.

* Specify a workspace

cd e:\DHS\DHS_data\scratch

 

* Prepare the HR file; keep only the household-level variables

use "...IAHR7EFL.DTA", clear

drop *_*

gen cluster=hv001

gen hh=hv002

save HRtemp.dta, replace

 

use "...IAIR7EFL.DTA", clear

gen cluster=v001

gen hh=v002

 

merge m:1 cluster hh using HRtemp.dta

 

* Some households have no women in the IR file; drop them

tab _merge

keep if _merge==3

drop _merge 
Re: MERGING IR AND HR FILE [message #29066 is a reply to message #29008] Fri, 19 April 2024 00:47 Go to previous messageGo to next message
Noyel Sebastian is currently offline  Noyel Sebastian
Messages: 11
Registered: March 2024
Member
Thank you for the reply. I would like to clarify whether merging my IR file with the PR file will give me the respective women's household characteristics (which are not in the IR file). I understood from your reply that it is better if I merge the IR and PR files to get the missing household variables for women. I can follow this by merging the new file with the BR file.

Is there anything I need to focus on concerning the merging codes of the IR and PR files? Is it possible to share the merge code?



Thank You
Re: MERGING IR AND HR FILE [message #29095 is a reply to message #29066] Tue, 23 April 2024 13:52 Go to previous message
Janet-DHS is currently offline  Janet-DHS
Messages: 880
Registered: April 2022
Senior Member
Following is a response from DHS staff member, Tom Pullum:

Here is a Stata program to merge the PR and IR files. It differs only slightly from the one to merge the HR and PR files.

* Specify a workspace
cd e:\DHS\DHS_data\scratch
* Prepare the PR file; keep only the household-level variables
use "...IAPR7EFL.DTA", clear
* Reduce to eligible women
keep if hv117==1
gen cluster=hv001
gen hh=hv002
gen line=hvidx
save PRtemp.dta, replace
 use "...IAIR7EFL.DTA", clear
gen cluster=v001
gen hh=v002
gen line=v003
merge 1:1 cluster hh line using PRtemp.dta
* Some women were eligible but were not interviewed (nonresponse cases); drop them
tab _merge
keep if _merge==3
drop _merge 
Previous Topic: Regional variable v024
Next Topic: Agricultural Land ownership: Treatment of Zero values
Goto Forum:
  


Current Time: Wed Nov 13 05:22:33 Coordinated Universal Time 2024