The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Merging Senegal KR files to PR files
Merging Senegal KR files to PR files [message #24149] Thu, 03 March 2022 15:29 Go to next message
tundexZ is currently offline  tundexZ
Messages: 4
Registered: March 2022
Member
Hi All,

I am trying to merge some mother characteristics from the KR file to the PR file for all DHS data available for Senegal. using PR as the base file. I have encountered a problem that many seem to have faced in this forum. I started with merging the 2019 dataset and I keep getting error messages "variables hv001 hv002 and hvidx do not uniquely identify the observations in the using data".

Sincerly have i tried to find and used the answers in the forum thread but I am stil getting the same error message
( https://userforum.dhsprogram.com/index.php?t=msg&goto=21 769&&srch=merging+KR+to+PR+file#msg_21769)
( https://userforum.dhsprogram.com/index.php?t=msg&goto=13 952&&srch=merging+KR+to+PR+file#msg_13952)

Here are my statacodes I used

**preparing kr file
use "C:\Users\owolba\Desktop\foodways project\Senegal DHS DAta\STATA DATASET SENEGAL\SNKR8BFL.DTA", clear
keep caseid v001 v002 b16 v131 v130 v704 v705 v716 v717 v732 v745b
rename v001 hv001
rename v002 hv002
rename b16 hvidx
drop if hvidx==0 | hvidx==.
sort hv001 hv002 hvidx`
save temp.dta, replace


**preparing pr file for merge
use "C:\Users\owolba\Desktop\foodways project\Senegal DHS DAta\STATA DATASET SENEGAL\SNPR8BFL.DTA",clear
sort hv001 hv002 hvidx
merge 1:1 hv001 hv002 hvidx using temp.dta


I have tried this codes and all other suggestions but i still get get the error code: "variables hv001 hv002 hvidx do not uniquely identify observations in the using data"

Thank you in anticipation for your response

Regards,
Babs

Re: Merging Senegal KR files to PR files [message #24150 is a reply to message #24149] Fri, 04 March 2022 07:18 Go to previous messageGo to next message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 2537
Registered: February 2013
Senior Member
Following is a response from DHS Research & Data Analysis Director, Tom Pullum:

You have made an interesting discovery. It happens that there are two duplicated children in the KR file, specifically those with b16=6 and 7 in the household with v001=43 and v002=14.

Your Stata code was correct. When you get the kind of message you got, with "merge 1:1", you can change to an older and more flexible version of the command, just "merge". I won't go into all the steps I used, but I found that the duplicates were in the KR file, not the PR file, and then ran these lines in the KR file:

sort v001 v002 b16
egen dup=seq() if b16~=0 & b16~=., by(v001 v002 b16)
tab dup,m

You can then list v001 v002 b16 for the cases with dup=2.

If you add two more lines:
drop if dup==2
drop dup
Then you have a file with no duplicates and the 1:1 merge will work ok. I will report this and I hope eventually a corrected file will be issued. Thanks for discovering this issue! The problem was not with your code, but with the data file.
Re: Merging Senegal KR files to PR files [message #24154 is a reply to message #24150] Fri, 04 March 2022 14:39 Go to previous message
tundexZ is currently offline  tundexZ
Messages: 4
Registered: March 2022
Member
Thank you very much for this information and update about the dataset. The added lines shared worked, I was able to merge the the KR file to the PR file.

Thank you.

Regards,
Babs
Previous Topic: Merging MR to KR
Next Topic: Linking parents to anthropometric Data
Goto Forum:
  


Current Time: Mon Jun 27 13:51:30 Coordinated Universal Time 2022