The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Mother's and Father's occupation
Re: Mother's and Father's occupation [message #9324 is a reply to message #9311] Thu, 10 March 2016 11:15 Go to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3214
Registered: February 2013
Senior Member
Following is a response from Senior DHS Stata Specialist, Tom Pullum:

The following Stata lines will do this merge. You must add the other variables you want to retain in the "keep" lines and you must change the paths. I am using the old version of "merge" but it still works in Stata 14.

* Prepare IR file
use e:\DHS\DHS_data\IR_files\MLIR41FL.dta, clear
rename v001 hv001
rename v002 hv002
rename v003 hv112
* bring along more variables if you want
keep hv001 hv002 hv112 v716 v717 v704 v705
gen mother_present=1
sort hv001 hv002 hv112
save e:\DHS\DHS_data\scratch\temp_IR.dta, replace

* Prepare MR file
use e:\DHS\DHS_data\MR_files\MLMR41FL.dta, clear
rename mv001 hv001
rename mv002 hv002
rename mv003 hv114
* bring along more variables if you want
keep hv001 hv002 hv114 mv716 mv717
gen father_present=1
sort hv001 hv002 hv114
save e:\DHS\DHS_data\scratch\temp_MR.dta, replace

* Prepare PR file
use e:\DHS\DHS_data\PR_files\MLPR41FL.dta, clear
keep if hv105>=5 & hv105<=14
* bring along more variables if you want
keep hv001 hv002 hvidx hv104 hv105 hv112 hv114

* Merge with mother's data
sort hv001 hv002 hv112
merge hv001 hv002 hv112 using e:\DHS\DHS_data\scratch\temp_IR.dta
tab _merge
drop if _merge==2
drop _merge
replace mother_present=0 if mother_present==.
tab hv105 mother_present

* Merge with father's data
sort hv001 hv002 hv114
merge hv001 hv002 hv114 using e:\DHS\DHS_data\scratch\temp_MR.dta
tab _merge
drop if _merge==2
drop _merge
replace father_present=0 if father_present==.
tab hv105 father_present

tab mother_present father_present
 
Read Message
Read Message
Previous Topic: Merging Birth's Recode and Household Member Recode
Next Topic: Couples and HIV merge in STATA
Goto Forum:
  


Current Time: Mon Dec 23 02:51:11 Coordinated Universal Time 2024