I am trying to merge KR and PR files for various samples, for instance for Angola MIS 2006-2007. I am primarily interest in adding the result of the malaria test from the PR file (variable hml33) to the KR file.
My concern is how to attach the malaria test result to the correct child in the KR file. My intuition is that there should be a unique 1:1 match for children in KR and PR so that the test result is properly assigned. That means that there should be no duplicate for a specific child in either file.
I understand that some children in KR may not appear in PR, and dropped those below. But there are still duplicates in the KR file, as seen below.
Any advice is much appreciated.
. * Start with kids recode KR and merge to person recode PR
.
. use AOKR51FL.dta, clear
. gen hv001=v001
. gen hv002=v002
. gen hvidx=b16
(140 missing values generated)
.
. * Exclude children who have died or live elsewhere
. drop if inlist(b16, 0, .)
(195 observations deleted)
.
. * Would expect to have unique observations - but there are duplicates
. duplicates list hv001 hv002 hvidx
Duplicates in terms of hv001 hv002 hvidx
+---------------------------------------+
| group: obs: hv001 hv002 hvidx |
|---------------------------------------|
| 1 776 58 53 7 |
| 1 777 58 53 7 |
| 2 1171 96 69 5 |
| 2 1172 96 69 5 |
+---------------------------------------+
.
. * 1:1 merge fails
. merge 1:1 hv001 hv002 hvidx using AOPR51FL
variables hv001 hv002 hvidx do not uniquely identify observations in the master data
r(459);
Clean code
* Start with kids recode KR and merge to person recode PR
use AOKR51FL.dta, clear
gen hv001=v001
gen hv002=v002
gen hvidx=b16
* Exclude children who have died or live elsewhere
drop if inlist(b16, 0, .)
* Would expect to have unique observations - but there are duplicates
duplicates list hv001 hv002 hvidx
* 1:1 merge fails
merge 1:1 hv001 hv002 hvidx using AOPR51FL