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

39 lines
1.1 KiB
Plaintext

clear all
cd c:\chililabdata\data
use observation
sort observeid
save, replace
use household_head
rename hhd_sobserveid observeid
sort observeid
duplicates drop observeid, force
merge m:1 observeid using observation, keepusing(obs_round obs_entry_date)
keep if _merge==3
drop _merge
rename obs_round sround
rename obs_entry_date visit_date
replace visit_date = visit_date/86400000
sort socialgpid sround
gen eround =0
replace eround = sround[_n+1] if socialgpid[_n]==socialgpid[_n+1]
replace eround =23 if eround ==0
gen period = eround -sround
expand period
sort socialgpid sround
egen minround = min(sround), by (socialgpid)
by socialgpid: gen step=_n-1
gen 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 householdkey = socialgpid + round
drop hhd_episodeid observeid hhd_sdate hhd_seventtype hhd_eobserveid hhd_edate hhd_eeventtype sround eround period minround step
rename individid househeadid
sort householdkey
gen individkey = househeadid + round
/*recode*/
save ..\newcode\data\std_househead, replace