Uloading
Uloading
This commit is contained in:
33
Chililabdata/GenMaritalstatus.do
Normal file
33
Chililabdata/GenMaritalstatus.do
Normal file
@@ -0,0 +1,33 @@
|
||||
use observation
|
||||
sort observeid
|
||||
save observation, replace
|
||||
use indmarstatus
|
||||
keep individid marstatusid mar_sobserveid
|
||||
rename mar_sobserveid observeid
|
||||
sort observeid
|
||||
merge observeid using observation, nokeep keep (obs_de_date)
|
||||
|
||||
drop if $refdate < obs_de_date
|
||||
gen period = qofd($refdate )-qofd(obs_de_date ) +1
|
||||
expand period
|
||||
sort individid obs_de_date
|
||||
by individid obs_de_date: gen p= _n-1
|
||||
gen quarterdate = qofd(obs_de_date) + p
|
||||
sort individ quarterdate
|
||||
gen refquarter = qofd($refdate )
|
||||
sort individid quarterdate
|
||||
egen maxobs_de_date = max(obs_de_date), by(individid quarterdate)
|
||||
keep if obs_de_date == maxobs_de_date
|
||||
tostring quarterdate, generate(key)
|
||||
replace key = individid + key
|
||||
duplicates drop key, force
|
||||
drop _merge
|
||||
sort key
|
||||
save crossmarstatustemp, replace
|
||||
keep if refquarter == quarterdate
|
||||
gen refdate = $refdate
|
||||
format refdate %td
|
||||
keep individid marstatusid refdate obs_de_date observeid
|
||||
duplicates drop individid, force
|
||||
sort individid
|
||||
save cross\crossmarstatus, replace
|
||||
Reference in New Issue
Block a user