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

77 lines
1.9 KiB
Plaintext

clear all
cd c:\chililabdata\newcode\data
use std_births
gen year = year(bod)
tostring year, replace
sort individid
drop individkey
rename individid childid
rename bornid childbornid
gen individkey = motherid + round
sort individkey
merge m:1 individkey using std_education, keepusing(eduid)
keep if _merge !=2
rename eduid meduid
drop _merge
merge m:1 individkey using std_occupation, keepusing(occupationid)
keep if _merge !=2
rename occupationid moccupationid
drop _merge
replace individkey = fatherid + round
sort individkey
merge m:1 individkey using std_education, keepusing(eduid)
keep if _merge !=2
rename eduid feduid
drop _merge
merge m:1 individkey using std_occupation,keepusing(occupationid)
keep if _merge !=2
rename occupationid foccupationid
drop _merge
drop individkey
rename motherid individid
sort individid
merge m:1 individid using std_individual , keepusing(birthdate bornid)
keep if _merge !=2
drop _merge
rename birthdate mbod
rename bornid mbornid
rename individid motherid
rename fatherid individid
sort individid
merge m:1 individid using std_individual , keepusing(birthdate bornid)
keep if _merge !=2
drop _merge
rename birthdate fbod
rename bornid fbornid
rename individid fatherid
rename childid individid
drop motheridGuid fatheridGuid appround
replace householdkey = socialgpid + year
merge m:1 householdkey using houseinfo, keepusing (quintile)
keep if _merge !=2
drop _merge
sort individid
save std_allbirths, replace
use std_individual
keep if length(motherid)==11
sort motherid birthdate
gen prevchildid = individid[_n-1] if mother[_n-1] ==motherid
gen prevgender = sex[_n-1] if mother[_n-1] ==motherid
gen prevbirthdate = birthdate[_n-1] if mother[_n-1] ==motherid
sort individid
save tmp_individual, replace
use std_allbirths
merge 1:1 individid using tmp_individual, keepusing(prevchildid prevgender prevbirthdate)
keep if _merge!=2
drop _merge
cd c:\chililabdata\newcode