set mem 800M cd e:\chililabdata\data use e:\chililabdata\data\houseres.dta, clear keep locationid socialgpid res_seventtype res_sdate rename res_seventtype eventtype rename res_sdate eventdate save houseres_start, replace use e:\chililabdata\data\houseres.dta, clear keep locationid socialgpid res_eeventtype res_edate rename res_eeventtype eventtype rename res_edate eventdate save houseres_end, replace keep if strlen(eventtype) > 0 append using "e:\chililabdata\data\houseres_start.dta" recast str24 locationid recast str7 locationid recast str3 eventtype save houseres_events, replace sort socialgpid eventdate drop if strlen(socialgpid) ==0 sort socialgpid eventdate by socialgpid : gen n = _n egen maxn = count (n), by(socialgpid) keep if n==maxn drop n maxn sort socialgpid