use "D:\CHFS数据库11-19\15年调查数据\2015年家庭金融调查数据库\2015年家庭金融调查数据_数据集_14版\chfs2015_hh_20191120_version14.dta", clear
rename hhid_2015 householdid     
save hh_temp.dta, replace    

use "D:\CHFS数据库11-19\15年调查数据\2015年家庭金融调查数据库\2015年家庭金融调查数据_数据集_14版\chfs2015_ind_20191120_version14.dta", clear
rename hhid_2015 householdid    
save ind_temp.dta, replace   


use hh_temp.dta, clear
merge 1:m householdid using ind_temp.dta, nogen
drop *it
egen tt_c3024 = rowtotal(c3024*)
egen total_h1004a = rowtotal(h1004a*) 

egen wage = rowtotal(a3022 a3023 a3020)
egen oper_inc = rowtotal(b1004i_* b1008 b1013c b1010 b2022 b2037_* b2041 )
egen prop_inc = rowtotal(d2106  d3117  d4111  d5109  d6116  d7112  d8106  c2002d tt_c3024)
egen fku = rowtotal(c3002a* c2027b)
gen fku1 = -fku
egen Hous_net_worth = rowtotal(c1015 c2023d c2016_* fku1)
egen hou_pro_fund1 = rowtotal(f4008)
egen clothing_food_housing_etc = rowtotal(g1001 g1011 g1005 g1006 g1007 g1008)
egen communi_fees = rowtotal(g1009 g1010 g1014 g1015 g1018)
egen hous_mainte = rowtotal(g1012 g1013)
egen deposits_stocks_bonds_funds_etc = rowtotal(d1105 d2104 d3109 d4103_* d5107 d6100a d7106a d7110 d8104 k1101 k2102c d9100aa d9110a)
egen real_esta_hous_prop_etc = rowtotal(c2016_* c3019 c2023d c5010_*)
egen car = rowtotal(c7009  c7058)
egen other_nonfin_ass = rowtotal(c8002 c8005)
egen hous_size = rowtotal(a2000a a2000b)
gen age = 2015 - a2005


egen medic_care = rowtotal(g1019a g1019b)

rename total_h1004a transf_inc
rename h2004 other_inc
rename f1010 soci_sec
rename f1031 corp_hous_fund
rename f2006 medi_ins
rename g1016 education
rename g1017 susta_transp
rename a4003 invest_risk_atti
rename a2003 gender
rename a2012 education1
rename a2024 marital_status
rename a3000 employment
rename a2025b heal_status

keep householdid hhead pline  age wage oper_inc prop_inc other_inc Hous_net_worth soci_sec  medi_ins corp_hous_fund  hou_pro_fund clothing_food_housing_etc hous_mainte education susta_transp invest_risk_atti deposits_stocks_bonds_funds_etc  real_esta_hous_prop_etc car gender education marital_status hous_size heal_status communi_fees other_nonfin_ass transf_inc medic_care education1 marital_status
save "2015.dta", replace