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)
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 previous 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

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Which DHS File should I use?
Next Topic: Weighing countries in a multi-country study
Goto Forum:
  


Current Time: Sun Dec 22 16:24:17 Coordinated Universal Time 2024