1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
cd "C:\Users\wugan\Desktop\CFPS-中国家庭追踪调查(2010-2020)\CFPS2018\data" use "cfps2018childproxy_202012.dta", clear
ssc install ereplace, replace egen male_size=count(fid18) if gender_update==1, by(fid18) ereplace male_size=mean(male_size), by(fid18) replace male_size=0 if male_size==. egen female_size=count(fid18) if gender_update==0, by(fid18) ereplace female_size=mean(female_size), by(fid18) replace female_size=0 if female_size==.
egen child_num=rowtotal(male_size female_size)
duplicates drop fid18, force keep fid18 male_size female_size child_num save "merge_data__child",replace
use "cfps2018famecon_202101",clear merge 1:1 fid18 using "merge_data__child" drop if _merge==2 replace male_size=0 if _merge==1 replace female_size=0 if _merge==1 replace child_num=0 if _merge==1 drop _merge save "cfps2018famecon",replace
use "cfps2018famconf_202008.dta",clear gen member_age=2018-tb1y_a_p if tb1y_a_p!=-1 & tb1y_a_p!=-9
egen male_size2=count(fid18) if tb2_a_p==1 & member_age<=15, by(fid18) ereplace male_size2=mean(male_size2), by(fid18) replace male_size2=0 if male_size2==. egen female_size2=count(fid18) if tb2_a_p==0 & member_age<=15, by(fid18) ereplace female_size2=mean(female_size2), by(fid18) replace female_size2=0 if female_size2==.
egen child_num2=rowtotal(male_size2 female_size2)
duplicates drop fid18, force save "cfps2018famconf_202008.dta", replace
use "cfps2018famecon",clear merge 1:1 fid18 using "cfps2018famconf_202008", keepusing(male_size2 female_size2 child_num2) keep if _merge==3 drop _merge save "cfps2018famecon",replace
|