The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Dataset use in Stata » Merging Birth's / Chidren's with Household Member Recode
Re: Merging Birth's / Chidren's with Household Member Recode [message #28815 is a reply to message #15108] Wed, 13 March 2024 06:32 Go to previous messageGo to previous message
Joyeuse
Messages: 1
Registered: March 2024
Member
Hi Trevor,

I have a question regarding merging PR and KR recodes. I am working with the Rwanda DHS 2019/20 dataset. My focus is on two aspects: household living arrangements (available in the PR recode) and child health indicators (available in the KR recode).

For the living arrangements, I utilized the STATA codes provided by DHS, which are accessible in the DHS indicators. I created a sub-sample based on these codes and subsequently merged it with the original PR recode.

Following this, I merged the newly created dataset with the KR recode. However, at the end of the merging process, I noticed that I am losing one category.

Could you please advise on how to resolve this issue?

Thank you

. tab cores_type

cores_type | Freq. Percent Cum.
---------------------------+-------------------------------- ---
Living with both parents | 16,982 63.60 63.60
With mother, not father | 6,046 22.64 86.24
With father, not mother | 617 2.31 88.55
Living with neither parent | 3,056 11.45 100.00
---------------------------+-------------------------------- ---
Total | 26,701 100.00


and I have this after final merging


tab cores_type

cores_type | Freq. Percent Cum.
---------------------------+-------------------------------- ---
Living with both parents | 5,620 75.05 75.05
With mother, not father | 1,866 24.92 99.97
Living with neither parent | 2 0.03 100.00
---------------------------+-------------------------------- ---
Total | 7,488 100.00



these are the codes I used

***preparation of household member recod (PR)***
use "C:\Users\pc\Desktop\Rwanda_DHS_Data\RWPR81DT_Household members recode\RWPR81FL.DTA",clear

rename hvidx c_line
rename hv001 cluster_line
rename hv002 hh_line
order c_line cluster_line hh_line
save "C:\Users\pc\Desktop\Rwanda_DHS_Data\PR.dta", replace

***preparation of children recod (KR)***
use "C:\Users\pc\Desktop\Rwanda_DHS_Data\RWKR81DT_Children recode\RWKR81FL.DTA", clear

tab b16
drop if b16==.
drop if b16==0

rename b16 c_line
rename v001 cluster_line
rename v002 hh_line
order c_line cluster_line hh_line
save "C:\Users\pc\Desktop\Rwanda_DHS_Data\KR.dta", replace

****Creation of a sub_sample of variables from PR datset to create ** Living arrangements ***

* Preparing files to produce the indicators, this required several merges
use "C:\Users\pc\Desktop\Rwanda_DHS_Data\RWPR81DT_Household members recode\RWPR81FL.DTA", replace
keep hv001 hv002 hvidx hv005 hv009 hv024 hv025 hv101-hv105 hv111-hv114 hv270 hc60
save PR_temp.dta, replace

* Prepare a file of potential mothers
use PR_temp.dta, clear
drop if hv104==1
drop if hv105<15
keep hv001 hv002 hvidx hv102
gen in_mothers=1
rename hv102 hv102_mo
rename hvidx hv112
sort hv001 hv002 hv112
save PR_temp_mothers.dta, replace

* Prepare a file of potential fathers
use PR_temp.dta, clear
drop if hv104==2
drop if hv105<15
keep hv001 hv002 hvidx hv102
gen in_fathers=1
rename hv102 hv102_fa
rename hvidx hv114
sort hv001 hv002 hv114
save PR_temp_fathers.dta, replace

* Prepare file of children for merges
use PR_temp.dta, clear
drop if hv102==0
drop if hv105>17
gen in_children=1

* Merge children with potential mothers
sort hv001 hv002 hv112
merge hv001 hv002 hv112 using PR_temp_mothers.dta
rename _merge _merge_child_mother

* Merge children with potential fathers
sort hv001 hv002 hv114
merge hv001 hv002 hv114 using PR_temp_fathers.dta
rename _merge _merge_child_father
gen hv112r=hv112
gen hv114r=hv114

* Code 99 of the mother or father is not de jure
replace hv112r=99 if hv112>0 & hv102_mo==0
replace hv114r=99 if hv114>0 & hv102_fa==0
keep if in_children==1
drop in_* _merge*
label define HV112R 0 "Mother not in household" 99 "In hh but not de jure"
label define HV114R 0 "Father not in household" 99 "In hh but not de jure"
label values hv112r HV112R
label values hv114r HV114R
tab1 hv112r hv114r

gen cores_type=.
replace cores_type=1 if (hv112r>0 & hv112r<99) & (hv114r>0 & hv114r<99)
replace cores_type=2 if (hv112r>0 & hv112r<99) & (hv114r==0 | hv114r==99)
replace cores_type=3 if (hv112r==0 | hv112r==99) & (hv114r>0 & hv114r<99)
replace cores_type=4 if (hv112r==0 | hv112r==99) & (hv114r==0 | hv114r==99)
label define cores_type 1 "Living with both parents" 2 "With mother, not father" 3 "With father, not mother" 4 "Living with neither parent"
label values cores_type cores_type
tab cores_type


***preparation for merging with PR recode**
rename hvidx c_line
rename hv001 cluster_line
rename hv002 hh_line
order c_line cluster_line hh_line


***FIRST MERGE: LIVING ARRANGEMENT + PR RECODE*****
merge 1:1 c_line cluster_line hh_line using "C:\Users\pc\Desktop\Rwanda_DHS_Data\PR.dta", keep(match)
drop _merge
tab cores_type
save "C:\Users\pc\Desktop\Rwanda_DHS_Data\RWPR81DT_Household members recode\PR_living arrangement.dta", replace

***SECOND MERGE: ABOVE DATASET + CHILDREN RECODE***

merge 1:1 c_line cluster_line hh_line using "C:\Users\pc\Desktop\Rwanda_DHS_Data\KR.dta", keep(match)
drop _merge

save "C:\Users\pc\Desktop\Rwanda_DHS_Data\RWPR81DT_Household members recode\Joy_Final dataset_DHS_Project.dta", replace
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Measles vaccination NFHS 5 India
Next Topic: DHS 5 India dataset IR file-r900 error
Goto Forum:
  


Current Time: Wed Nov 27 09:04:57 Coordinated Universal Time 2024