The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » How to merge IR, KR and HR files in stata (merging dataset)
How to merge IR, KR and HR files in stata [message #19867] Mon, 24 August 2020 02:00 Go to next message
Kaung Suu is currently offline  Kaung Suu
Messages: 2
Registered: August 2020
Member
Dear DHS expert,

May I request your kind guidance on how can I merge IR, KR, and HR files in STATA?
Currently, I am using the following command. But the total observations are multiplied.

use "HR"
rename hv001 v001
rename hv002 v002
merge m:m v001 v002 using "KR"
drop _merge
merge m:m v001 v002 using "IR"

Thank you and looking forward to your kind reply.

Best,
Kaung Suu
Re: How to merge IR, KR and HR files in stata [message #19868 is a reply to message #19867] Mon, 24 August 2020 05:54 Go to previous messageGo to next message
Sami Abel is currently offline  Sami Abel
Messages: 3
Registered: May 2020
Member
Hi Kaung Suu,

Most of the variable in the IR file are on the PR file. So these code could probably help you.
It is from the DHS guide stats. You should read it, it's very helpful.

use "/Users/ Kaung_Suu/Desktop/IR_PR_KR_MERGE/YOUR_PR_FILE.DTA", clear

sort hhid hvidx

* save temporary data file tempfile secondary
save "file_for_merge", replace

* open primary file - KR file
use "/Users/Kaung_Suu/Desktop/IR_PR_KR_MERGE/YOUR_KR_FILE.DTA", clear

* generate household and person ID for matching on

gen hhid = substr(caseid,1,12)
gen hvidx = b16

* sort file by IDs
sort hhid hvidx

* merge mother's characteristics into PR file
merge m:1 hhid hvidx using "file_for_merge", keep(master match)

* check the merge
tab _merge,m
save _merge_enfin, replace

[Updated on: Mon, 24 August 2020 05:56]

Report message to a moderator

Re: How to merge IR, KR and HR files in stata [message #19921 is a reply to message #19868] Tue, 01 September 2020 00:53 Go to previous messageGo to next message
Kaung Suu is currently offline  Kaung Suu
Messages: 2
Registered: August 2020
Member
Hi Sami,

Thank you for your support.

best,
Kaung Suu
Re: How to merge IR, KR and HR files in stata [message #19922 is a reply to message #19921] Tue, 01 September 2020 07:30 Go to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3214
Registered: February 2013
Senior Member
This kind of question has come up many times on the forum. If you search with keyword "merge" you should find answers to your question.
Previous Topic: Which DHS File should I use?
Next Topic: Weighing countries in a multi-country study
Goto Forum:
  


Current Time: Sun Dec 22 22:00:36 Coordinated Universal Time 2024