* do e:\DHS\Requests_and_queries\questions_on_merges\PH_sick_injured_do_27Aug2015.txt set logtype text log using e:\DHS\Requests_and_queries\questions_on_merges\PH_sick_injured_log_27Aug2015.txt, replace * Procedure to recode the sick and injured variables in the Philippines 2013 PR file use e:\DHS\DHS_data\PR_files\PHPR61FL.dta cd c:\scratch set more off drop if sh201==. | sh201==0 save tempa.dta, replace * all the desired information is exactly the same on every line in the household; keep one line per hh keep hv001 hv002 hvidx sh203_* sh204a_* sh204b_* sh204c_* sh204d_* sh204e_* * add any other variables that you want to keep * line for checking list hv001 hv002 hvidx sh203_01-sh203_03 sh204a_01-sh204a_03 if _n<=100 , table clean * line numbers of sick persons are given as sh203_01 through sh203_12 * Stata expects 1, 2, ....9 and NOT 01, 02, 09. We must remove the leading zeroes * line to eliminate leading zeroes from indices 01 through 09 on ALL variables rename *_0* *_* gen sh204a=. gen sh204b=. gen sh204c=. gen sh204d=. gen sh204e=. * seqno is sequence number, the number of sh203 (1 through 12) that gives the person's line number gen seqno=. local li=1 while `li'<=12 { replace seqno=`li' if sh203_`li'==hvidx local li=`li'+1 } * Now pull off just the variables with that sequence number local li=1 while `li'<=12 { replace sh204a=sh204a_`li' if seqno==`li' replace sh204b=sh204b_`li' if seqno==`li' replace sh204c=sh204c_`li' if seqno==`li' replace sh204d=sh204d_`li' if seqno==`li' replace sh204e=sh204e_`li' if seqno==`li' local li=`li'+1 } * restore labels label values sh204a SH204A label values sh204b SH204B label values sh204c SH204C label values sh204d SH204D label values sh204e SH204E * line to check results, just sh204a and the first 3 people listed as injured or sick in the household list hv001 hv002 hvidx sh204a_1-sh204a_3 sh204a if _n<=100, table clean nolabel list hv001 hv002 hvidx sh204a sh204b sh204c sh204d sh204e if _n<=100, table clean drop sh204a_* drop sh204b_* drop sh204c_* drop sh204d_* drop sh204e_*