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

32 lines
828 B
Plaintext

clear
cd e:\chililabdata\data
use individual
sort individid
save, replace
use pregnance
sort individid
merge m:1 individid using individual, keepusing(birthdate)
drop if _merge!=3
drop _merge
gen socialgpid = substr(sobserveid,1,9)
replace preg_sdate= preg_sdate/86400000
rename preg_sdate sdate
replace preg_edate= preg_edate/86400000
rename preg_edate edate
replace birthdate= birthdate/86400000
rename birthdate bod
format bod %td
format sdate %td
format edate %td
gen year = year( sdate)
gen h = halfyear(sdate)
gen round = yh(year,h)-89
tostring round, generate(rounds)
replace rounds = "0" + rounds if strlen(rounds) ==1
gen socialkey = socialgpid+ rounds
gen individkey = individid+ rounds
drop eventid sobserveid fatherid fatheridGuid EID rounds h year
sort individid round
drop if round < 0
save rPregnance, replace