clear all cd c:\chililabdata\data use observation sort observeid save, replace use householdinfo sort observeid duplicates drop observeid, force merge m:1 observeid using observation, keepusing(obs_round obs_entry_date) keep if _merge==3 drop _merge drop round rename obs_round sround rename obs_entry_date visit_date replace visit_date = visit_date/86400000 sort socialgpid sround gen eround =0 replace eround = sround[_n+1] if socialgpid[_n]==socialgpid[_n+1] replace eround =23 if eround ==0 gen period = eround -sround expand period sort socialgpid sround egen minround = min(sround), by (socialgpid) by socialgpid: gen step=_n-1 gen round = minround + step drop if round > 22 tostring round, replace replace round = "00" + round if strlen(round) == 1 replace round ="0" + round if strlen(round)==2 gen householdkey = socialgpid + round drop hhinforid observeid sround eround period minround step eco_inside_sup eco_inside_suptd eco_outside_sup eco_outside_suptd merge 1:1 householdkey using ..\newcode\data\std_househead, keepusing(househeadid) drop if _merge ==2 drop responsorID entryDate fieldWrkr dataClerk deDate statusDat _merge sort householdkey /*recode*/ label variable roof "Kieu mai nha" label define kieumainha 1 "Be tong" 2 "Mai ngoi, ton, xi mang" 3 "Mai tranh, rom ra, giay dau" 4 "Khac" label values roof kieumainha label variable wall "Kieu tuong" label define kieutuong 1 "Go" 2 "Tuong xay" 3 "Vach dat, tre, giay dau" 4 "Khac" label values wall kieutuong label variable house_foundation "Kieu nen nha" label define kieunennha 1 "Go" 2 "Gach men, da hoa" 3 "Gacn lat/xi mang" 4 "Dat" 5 "Khac" label values house_foundation kieunennha label variable water "Nguon uoc" label define nguonnuoc 1 "Nuoc may" 2 "Nuoc gieng khoan" 3 "Nuoc giang khoi" 4 "Nuoc mua" 5 "Nuoc ao ho" 6 "Nuoc suoi, song" label values water nguonnuoc label variable toilet "Kieu toilet" label define kieutoilet 1 "Tu hoai/ban tu hoai/tham doi nuoc" 2 "Hai ngan" 3 "Mot ngan" 4 "Ho xi cau" 5 "Chung voi gia xuc" 6 "Khac" 7 "Khong co" label values toilet kieutoilet label variable bathroom "Kieu nha tam" label define kieunhatam 1 "Nha tam co mai" 2 "Nha tam khong co mai" 3 "Khac" 4 "Khong co" label values bathroom kieunhatam label define cokhong 1 "Co" 0 "Khong" label values cabletv cokhong label values adsl cokhong save ..\newcode\data\std_householdinfo, replace