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 58 59 60 61 62 63 64
|
cd "C:/Users/wugan/Desktop/测算家庭规模"
use "CFPS-2018/cfps2018famecon_202101",clear keep fid18 fid16 fid14 fid12 fid10 provcd18 countyid18 cid18 urban18 iwmode feinterv fml_count fa01 cyear cmonth fa1 fa101 familysize18 releaseversion save "CFPS-2018/cfps2018famecon_202101",replace tab fml_count tab familysize18
use "CHFS-2019/chfs2019_ind_202112",clear
egen fam_size=count(hhid), by(hhid) keep hhid pline pline_order a2000c a2001 a2003 a2005 fam_size save "CHFS-2019/chfs2019_ind_202112", replace
use "CSS-2021/2021_Stata",clear keep v1 v2 v3_1 v3_2 a1a* a1b* save "CSS-2021/2021_Stata",replace
forvalues i=2/30 { gen member_`i'=0 replace member_`i'=1 if a1a`i'!=. } gen member_1=1 egen fam_size=rowtotal(member_2 member_3 member_4 member_5 member_6 member_7 member_8 member_9 member_10 member_11 member_12 member_13 member_14 member_15 member_16 member_17 member_18 member_19 member_20 member_21 member_22 member_23 member_24 member_25 member_26 member_27 member_28 member_29 member_30 member_1)
use "CSS-2021/2021_Stata",clear replace a1a1=0
reshape long a1a a1b, i(v1) j(list) drop if a1a==.
egen fam_size=count(v1), by(v1)
duplicates drop v1, force save "CSS-2021/2021_ind_fam",replace
use "CSS-2021/2021_Stata",clear merge 1:1 v1 using "CSS-2021/2021_ind_fam", keepusing(fam_size) drop _merge save "CSS-2021/2021_Stata",replace
|