clear all cd c:\chililabdata\data use observation sort observeid save, replace use individual sort individid save individual, replace use death gen socialgpid = substr(observeid,1,9) replace dth_date=dth_date/86400000 format dth_date %td sort observeid merge m:1 observeid using observation, keepusing(locationid obs_round) keep if _merge ==3 drop observeid _merge rename obs_round round tostring round, replace replace round = "00" + round if strlen(round) == 1 replace round ="0" + round if strlen(round)==2 merge m:1 individid using individual drop if _merge !=3 drop _merge replace birthdate=birthdate/86400000 format dth_date %td gen age = floor((dth_date-birthdate)/365.5) recode age (min/0=1 "<1") (1/4=2 "1-4") (5/9=3 "5-9")(10/14=4 "10-14") (15/19=5 "15-19") (20/24=6 "20-24") (25/29=7 "25-29") (30/34=8 "30-34") (35/39=9 "35-39") (40/44=10 "40-44") (45/49=11 "45-49")(50/54=12 "50-54") (55/59=13 "55-59") (60/64=14 "60-64") (65/69=15 "65-69") (70/74=16 "70-74") (75/79=17 "75-79") (80/84=18 ">=80") (85/max=19 ">=85") , gen (agegrp) gen individkey = individid+ round gen householdkey = socialgpid + round sort individkey drop fatheridGuid motheridGuid bornid appround eventid individidGuid EID fatherid motherid ind_name dth_otherplace dth_reason birthdate gen communeid = substr(locationid, 1,2) /*Recode - labeling */ label variable communeid "Ma xa" label define noimat 1 "Tai nha" 2 "Co so y te" 3 "Khac" label define nguyennhan 1 "Benh tat" 2 "Gia yeu" 3 "Tai nan" 4 "Ly do khac" label values dth_placeid noimat label values dth_reasonid nguyennhan destring ethnicid, replace label define ethnic 1 "1. Kinh" 2 "2. San diu" 3 "3. Tay" 4 "4. Hoa" 5 "5. Khac" 6 "6. Thai" 7 "7. Kho me" 8 "8. Man" 9 "4. Tho" label values ethnic ethnic rename gender sex destring sex, replace label define sexs 1 "1. Nam" 2 "2. Nu" label values sex sexs save ..\newcode\data\std_deaths, replace