Home » Data » Merging data files » Merging Children with Household
Re: Merging Children with Household [message #9470 is a reply to message #9440] |
Wed, 30 March 2016 12:26 |
Bridgette-DHS
Messages: 3214 Registered: February 2013
|
Senior Member |
|
|
Additional Comments from Tom Pullum:
I have found that in this survey there are sometimes sub-households. The sub-household codes are not given by a variable but must be extracted as the 9th character in hhid and caseid. The following Stata lines will do the merge. At some points I do "tab subhh" and "tab b8" but those lines are only for checking. They are not needed for the merge. Let me know if there are still any problems.
use e:\DHS\DHS_data\PR_files\PEPR6IFL.DTA, clear
gen str2 subhh=substr(hhid,9,1)
destring subhh, replace
tab subhh,m
sort hv001 hv002 subhh hvidx
save e:\DHS\DHS_data\scratch\PEPR6IFLTEMP1.DTA, replace
use e:\DHS\DHS_data\KR_files\PEKR6IFL.DTA, clear
gen str2 subhh=substr(caseid,9,1)
destring subhh, replace
tab subhh,m
tab b8
drop if b16==0 | b16==.
rename v001 hv001
rename v002 hv002
rename b16 hvidx
sort hv001 hv002 subhh hvidx
merge 1:1 hv001 hv002 subhh hvidx using e:\DHS\DHS_data\scratch\PEPR6IFLTEMP1.DTA
tab b8 _merge,m
keep if _merge==3
drop _merge
tab b8
|
|
|
Goto Forum:
Current Time: Sun Dec 22 05:56:38 Coordinated Universal Time 2024
|