The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Combining PR and KR to get child-specific malaria test results
Combining PR and KR to get child-specific malaria test results [message #10651] Thu, 25 August 2016 11:08 Go to previous message
coffeehelps
Messages: 4
Registered: August 2016
Member
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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Linking adult children (>15) to their parents
Next Topic: Linking GPS data to DHS data files
Goto Forum:
  


Current Time: Sun Apr 28 07:27:40 Coordinated Universal Time 2024