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

40 lines
971 B
Plaintext

set mem 500M
* Determine the last location that an individual was resident at and the last time that location was visited.
clear
* Calculate the last date that a location was visited
cd \chililabdata\data
use observation
sort locationid
egen lastdate=max(obs_entry_date), by(locationid)
format lastdate %d
drop if !(obs_entry_date==lastdate)
keep locationid obs_entry_date
sort locationid
save lastvisit,replace
clear
* Determine the last location that an individual was resident
use individres
sor individid
egen lastsdate=max(res_sdate), by(individid)
format lastsdate %d
drop if !(res_sdate==lastsdate)
keep individid locationid res_edate res_eeventtype
sort individid
save lastlocation,replace
* Combine last location an individual was resident and the last visit date of the location
sort locationid
merge locationid using lastvisit, nokeep keep(obs_entry_date)
rename obs_entry_date lastvisit
drop _merge
sort individid
save lastobservation, replace