clear all cd c:\chililabdata\data use observation sort observeid save, replace use indmarstatus rename mar_sobserveid observeid sort individid observeid duplicates drop individid observeid, force merge m:1 observeid using observation, keepusing(obs_round obs_entry_date) keep if _merge==3 drop _merge rename obs_round round rename obs_entry_date visit_date sort individid round gen rounds =0 replace rounds = round[_n+1] if individid[_n]==individid[_n+1] replace rounds =23 if rounds ==0 gen period = rounds -round expand period sort individid round egen minround = min(round), by (individid) by individid: gen step=_n-1 replace 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 individkey = individ + round drop mar_episodeid mar_eobserveid observeid rounds period minround step label variable marstatusid "Tinh trang hon nhan" recode marstatusid (0=0)(1 6 = 1) (2/4 = 2) (5=3) label define marstatus 0 "0. Khong biet" 1 "1. Song cung vo/chong" 2 "2. Ly than/Ly di/Goa" 3 "3. Doc than" label values marstatusid marstatus sort individkey save ..\newcode\data\std_marstatus, replace