clear all cd c:\chililabdata\data use observation sort observeid save, replace use individual sort individid save individual, replace use birth gen socialgpid = substr(observeid,1,9) gen round = substr(observeid, 10,3) replace bth_date=bth_date/86400000 format bth_date %td merge m:1 observeid using observation, keepusing(locationid) keep if _merge ==3 drop observeid _merge sort individid merge m:1 individid using individual drop if _merge !=3 drop _merge drop eventid individidGuid ind_name individidGuid eventid birthdate rename bth_date bod gen individkey = individid+ round gen householdkey = socialgpid + round sort individkey label variable gender "Gioi tinh" gen communeid = substr(locationid,3,2) destring gender, replace label define sex 1 "Nam" 2 "Nu" label values gender sex destring ethnicid, replace duplicates drop individid, force save ..\newcode\data\std_births, replace