Files
Dss/Chililabdata/genLongYMarStatus.do
admin 8c43da1d1c Uloading
Uloading
2025-08-02 05:26:16 +07:00

44 lines
1.1 KiB
Plaintext

clear all
cd e:\chililabdata\data
use individual
sort individid
save, replace
use observation
sort observeid
save, replace
use indmarstatus
rename mar_sobserveid observeid
sort observeid
merge m:1 observeid using observation, keepusing(obs_entry_date)
keep if _merge ==3
gen visitdate = obs_entry_date/86400000
gen year = year( obs_entry_date/86400000)
drop if year < 2004
gen round = year
sort individid round
gen period = round[_n+1]-round
replace period = 2014-round if individid!=individid[_n+1]
expand period
replace round = round-2004
sort individid round
by individid round: gen p= _n-1
replace round = round + p
drop if round > 19
drop period p _merge
tostring round, generate(rounds)
replace rounds = "0" + rounds if strlen(rounds) == 1
gen individkey = individid + rounds
sort individkey
duplicates drop individkey, force
sort individid
merge m:1 individid using individual, keepusing(gender ethnicid bod)
gen firstyear = 2004
gen roundyear = firstyear+ round
gen age = roundyear-year(bod)
drop mar_episodeid observeid mar_eobserveid obs_entry_date year _merge
save rYMarstatus, replace