| 
		
			| How to merge IR, KR and HR files in stata [message #19867] | Mon, 24 August 2020 02:00  |  
			| 
				
				
					|  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   |  
			| 
				
				
					|  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 |  
	|  |  | 
	|  | 
	|  |