The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » Nutrition and Anthropometry » merge child under five with their parents (father, mother and child merging)
Re: merge child under five with their parents [message #22562 is a reply to message #22560] Thu, 01 April 2021 08:54 Go to previous messageGo to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3214
Registered: February 2013
Senior Member

Following is a response from DHS Research & Data Analysis Director, Tom Pullum:

If there are variables in the IR file that are not in the KR file, you can merge the KR file with the IR file by matching v001 v002 v003 in the KR file with v001 v002 v003 in the IR file and keeping the case if _merge==3. Getting the father's data from the MR file, and merging it onto the KR file, is not easy and it can only be done with a subset of children in the KR file. Both the child and the father have to be alive and in the same household. The following Stata lines will do this merge. There are only 3318 children in the KR file for whom it is possible to attach data from fathers in the MR file. You can attach data from the fathers in the PR file to a slightly larger number of children.


* How to attach hv106 (from the PR file) and mv106 (from the MR file) 
*   for the father to the record for the child in the KR file

* You will want to save more variables; this is just for illustration
* You need a temporary place to save data files (I use e:\DHS\DHS_data\scratch)


* Prepare the MR file
use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\CMMR71FL.DTA", clear
keep mv001 mv002 mv003 mv106
gen hv001=mv001
gen hv002=mv002
gen hvidx=mv003
sort hv001 hv002 hvidx
save e:\DHS\DHS_data\scratch\CMtemp.dta, replace

* Prepare the PR file and merge with the MR data
use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\CMPR71FL.DTA", clear
keep hv001 hv002 hvidx hv106
sort hv001 hv002 hvidx
merge hv001 hv002 hvidx using e:\DHS\DHS_data\scratch\CMtemp.dta
tab _merge
keep if _merge==3
drop _merge

* Prepare file of potential fathers
* hvidx is the father's line
gen fa_line=hvidx
sort hv001 hv002 fa_line
* This is a file of potential fathers with both MR and PR data
save e:\DHS\DHS_data\scratch\CMtemp.dta, replace

* Prepare a file of children in the PR file who are age 0-4 with father in the hh
* We merge children in the PR file with fathers in the PR file
use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\CMPR71FL.DTA", clear
* hv114 is father's line if in the hh
keep if hc1<. & hv114>0 & hv114<.
keep hv001 hv002 hvidx hv114
* hvidx is the child's line and hv114 is the father's line
* merge on the father's line
rename hv114 fa_line
sort hv001 hv002 fa_line
merge hv001 hv002 fa_line using e:\DHS\DHS_data\scratch\CMtemp.dta
tab _merge
drop _merge 
* This is a file of children in the PR file with their father's data attached

* Prepare this file for merge with KR file
gen v001=hv001
gen v002=hv002
gen b16=hvidx
sort v001 v002 b16
save e:\DHS\DHS_data\scratch\CMtemp.dta, replace

* Prepare the KR file
use "C:\Users\26216\ICF\Analysis - Shared Resources\Data\DHSdata\CMKR71FL.DTA" 
* b16 in the KR file is the child's line in the PR file
keep if b16>0 & b16<.
keep v001 v002 b16
sort v001 v002 b16
merge v001 v002 b16 using e:\DHS\DHS_data\scratch\CMtemp.dta
tab _merge
keep if _merge==3
drop _merge
save e:\DHS\DHS_data\scratch\CMtemp.dta, replace

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Linking children nutritional status with father or couple
Next Topic: PMT INDEX SCORE TO WEALTH INDEX SCORE/WEALTH INDEX
Goto Forum:
  


Current Time: Thu Dec 26 18:35:19 Coordinated Universal Time 2024