cd e:\chililabdata\data clear set mem 500M global startTime = mdy($smonth, $sday, $syear) global endTime = mdy($emonth, $eday, $eyear) global refdate = $endTime do ..\GenCrossEducation do ..\GenCrossOccupation do ..\GenMaritalstatus use individual, clear sort individid save individual, replace use inmigration drop if img_date < $startTime drop if img_date > $endTime brow sort individid merge individid using individual, nokeep keep(birthdate fatherid motherid gender) rename birthdate bod drop if _merge !=3 drop _merge gen communeid= substr(locationid, 1,2) gen area=1 replace area=2 if (communeid=="02") replace area=2 if (communeid=="04") replace area=2 if (communeid=="05") replace area=2 if (communeid=="07") replace fatherid = "00000000000" if strlen(fatherid) !=11 replace motherid = "00000000000" if strlen(motherid) !=11 gen age = floor((img_date-bod)/365.5) sort individid gen refquarter = qofd(img_date) tostring refquarter, generate (qkey) gen key = individid + qkey sort key merge key using crosseducationtemp, nokeep keep (eduid) drop if _merge==2 drop _merge sort key merge key using crossoccupationtemp, nokeep keep (occupationid) drop if _merge==2 drop _merge sort key merge key using crossmarstatustemp, nokeep keep (marstatusid) drop if _merge==2 drop _merge replace key = fatherid + qkey sort key merge key using crosseducationtemp, nokeep keep (feduid) drop if _merge==2 drop _merge sort key merge key using crossoccupationtemp, nokeep keep (foccupationid) drop if _merge==2 drop _merge replace key = motherid + qkey sort key merge key using crosseducationtemp, nokeep keep (meduid) drop if _merge==2 drop _merge sort key merge key using crossoccupationtemp, nokeep keep (moccupationid) drop if _merge==2 drop _merge save $savefolder/infull$suffix, replace gen male =0 gen female =0 replace male =1 if gender == "1" replace female =1 if gender == "2" sort communeid img_type age collapse (sum) male female, by (communeid img_type age) save $savefolder/in_commune_type_age$suffix, replace recode age (min/0=1 "<1") (1/4=2 "1-4") (5/9=3 "5-9")(10/14=4 "10-14") (15/19=5 "15-19") (20/24=6 "20-24") (25/29=7 "25-29") (30/34=8 "30-34") (35/39=9 "35-39") (40/44=10 "40-44") (45/49=11 "45-49")(50/54=12 "50-54") (55/59=13 "55-59") (60/64=14 "60-64") (65/69=15 "65-69") (70/74=16 "70-74") (75/79=17 "75-79") (80/max=18 ">=80") , gen (agegrp) collapse (sum) male female, by (communeid img_type agegrp) save $savefolder/in_commune_type_agegrp$suffix, replace collapse (sum) male female, by (img_type agegrp) save $savefolder/in_type_agegrp$suffix, replace