use "C:\...badcase_activity.dta", clear /*creating a combination of files in one to be changed later into HAF, HSF for Canada GSS 2010 main file*/ sort RECID save "C:\...badcase_activity.dta", replace drop WTBS* drop WTCBS_* drop WTSBS_* gen str2 country="CA" gen survey=2010 gen swave=0 gen msamp=0 gen hldid=0 gen persid=RECID gen id=1 gen parntid1=-9 gen parntid2=-9 gen partid=-9 save "C:\...badcase_activity.dta", replace ***** use "C:\...badcase_activity.dta", clear save "C:\...badcase_activity.dta", replace gen day=DDAY label variable day "Day of week diary kept" label values day DDAY tab day save "C:\...badcase_activity.dta", replace ***** use "C:\...badcase_activity.dta", clear gen cday=-9 gen month=-9 gen year=2010 gen diary=1 gen badcase=. gen hhtype=. replace hhtype=1 if LIVARR12==1 & HSDSIZEC==1 replace hhtype=1 if LIVARR12==12 & HSDSIZEC==1 replace hhtype=2 if LIVARR12==2 & HSDSIZEC==2 replace hhtype=3 if (LIVARR12==3|LIVARR12==4|LIVARR12==5|LIVARR12==6) & HSDSIZEC>2 replace hhtype=3 if LIVARR12==9 & HSDSIZEC>2 replace hhtype=3 if LIVARR12==10 & HSDSIZEC>2 replace hhtype=2 if MARSTAT<=2 & HSDSIZEC==2 & (LIVARR12==12|LIVARR12==10) replace hhtype=3 if MARSTAT<=2 & HSDSIZEC>2 & (LIVARR12==12|LIVARR12==11) recode hhtype (.=4) gen hhldsize=HSDSIZEC ****** BUGGED CORRECTION gen nchild=0 replace nchild=1 if CHH0014C==1 & CHRINHSDC==1 replace nchild=2 if CHH0014C==2 & CHRINHSDC==2 replace nchild=3 if CHH0014C==3 & CHRINHSDC==3 replace nchild=4 if CHH0014C==3 & CHRINHSDC==4 replace nchild=nchild+1 if nchild==0 & AGECHRYC<18 replace nchild=nchild+1 if nchild==0 & AGEHSDYC<18 ************************* gen agekidx=-5 replace agekidx=4 if AGECHRYC>17 & AGECHRYC<=25 replace agekidx=1 if AGEHSDYC<=4/*this order of AGECHRYC coming before AGEHSDYC is important because the youngest child in the household can be younger than the youngest child of the respondent*/ replace agekidx=2 if AGEHSDYC>4 & AGEHSDYC<13 replace agekidx=3 if AGEHSDYC>12 & AGEHSDYC<18 replace agekidx=4 if AGEHSDYC>17 & AGEHSDYC<=25 replace agekidx=4 if CHRINHSDC>0 & AGECHRYC==97 & AGEHSDYC>=18/*few respondent's children seem to be not single so they did not appear in the AGECHRYC, recoded as agekidx=3 for AGEHSDYC>17 and <25 and agekidx=4 for AGEHSDYC>=25*/ recode agekidx (-5=-7) gen agekid2=-5 replace agekid2=AGEHSDYC if AGEHSDYC<18 replace agekid2=AGECHRYC if AGECHRYC>17 & AGECHRYC<=25 replace agekid2=AGEHSDYC if AGECHRYC==25 & AGEHSDYC>=25 replace agekid2=AGEHSDYC if CHRINHSDC>0 & AGECHRYC==97 & AGEHSDYC>17 recode agekid2(-5=-7) replace agekid2=60 if agekid2>60 gen incorig=-5 replace incorig=INCMHSD label values incorig INCMHSD recode incorig (98=-8)(99=-8) xtile quart = incorig if incorig>=0, nq(4) replace quart=4 if incorig==12 recode quart (2/3=2)(4=3), gen(income) recode income (.=-8) drop quart gen ownhome=-5 replace ownhome=1 if DWELLOWN==1 replace ownhome=2 if DWELLOWN==2 recode ownhome (-5=-8) recode LUC_RST (1=1)(2/3=2), gen(urban) label variable urban "Urban or rural household" gen computer=-9 recode ATT_Q120 (1/3=3)(4=0)(8/9=.),gen(vehicle) replace vehicle=2 if EPI8220>=1 & (vehicle==.|vehicle==0) /*bicycles are common types of transportation and more environment-friendly choices which should not be ignored even in the industrialized countries*/ recode vehicle (.=-8) recode SEX (1=1)(2=2), gen(sex) recode AGEGR5 (1=16)(2=18)(3=22)(4=27)(5=32)(6=37)(7=42)(8=47)(9=52)(10=57)(11=62)(12=67)(13=72)(14=77)(15=80), gen(age) gen famstat=-8 replace famstat=0 if (age>=18 & age<40) & nchild==0 replace famstat=3 if age>=40 & nchild==0 replace famstat=1 if age>=18 & nchild>0 & agekidx==1 replace famstat=2 if age>=18 & nchild>0 & (agekidx==2 | agekidx==3) replace famstat=4 if age<18 & (LIVARR12==10 | LIVARR12==11) /*10 Living with 2 parents; 11 Living with 1 parent*/ replace famstat=5 if age<18 & (LIVARR12!=10 & LIVARR12!=11) replace famstat=0 if famstat==-8 & (age>=18 & age<40)/**/ replace famstat=3 if famstat==-8 & age>=40 gen singpar=-5 replace singpar=1 if LIVARR12==7|LIVARR12==8|LIVARR12==9 replace singpar=0 if nchild==1 & AGEGR5==1 /*412 observations"*/ replace singpar=0 if singpar==-5 & LIVARR12<12 replace singpar=0 if singpar==-5 & LIVARR12==12 & nchild==0/*LIVARR12 are "Other" and nchild=0 so it is safe to assume that the respondent is not a single parent*/ recode singpar (-5=-8) gen relrefp=1 /*only the respondent completed the diary*/ #delim ; gen civstat = cond(MARSTAT==1, 1, cond(MARSTAT==2, 1, cond(LIVARR12==2, 1, cond(LIVARR12==3, 1, cond(LIVARR12==4, 1, cond(LIVARR12==5, 1, cond(LIVARR12==6, 1,2)))))));/*no inconsistencies between living arrangements and marital status found, even though they were present in 1986 data. still the code is as follows: all married or in common law, even those reporting not living with a partner are included. Also, all people who report living with a partner are also included even though they do not report being married or in common law.*/ replace civstat=2 if MARSTAT<=2 & (LIVARR12==1|LIVARR12==7|LIVARR12==8|LIVARR12==9) replace civstat=2 if MARSTAT<=2 & LIVARR12==11 & HSDSIZEC==2 gen cohab=-9 gen citizen=-8 replace citizen=1 if YRLNDIMM==97 replace citizen=0 if YRLNDIMM==13 #delim ; gen empstat = cond(LFSGSS==1, 1, cond(LFSGSS==2, 2, cond(LFSGSS==3&LFSHSD12<4, 1, cond(LFSGSS==3&LFSHSD12>3&LFSHSD12<7, 2, cond(LFSGSS==3&LFSHSD12==10, 1, cond(LFSGSS==3&LFSHSD12==11, 2, cond(LFSGSS==3&LFSHSD12==98, 3,/**/ cond(ACT7DAYS==1&LFSGSS>5, 3, -8)))))))); replace empstat=4 if empstat==-8 & (ACT7DAYS==3|ACT7DAYS==4|ACT7DAYS>6) replace empstat=4 if empstat==-8 & ACT7DAYS==2 & LFSGSS==5 replace empstat=4 if empstat==-8 & ACT7DAYS==5 replace empstat=3 if (empstat==-8|empstat==4)& DVPAID>0 recode empstat (1/3=1)(4=0), gen(emp) replace emp=1 if empstat==3 gen unemp=0 replace unemp=1 if ACT7DAYS==2 replace unemp=-8 if LFSGSS>4 & (ACT7DAYS==8|ACT7DAYS==9) /*it is difficult to tell if respondent who don't know or didn't state and did not have hours of regular employment are unemployed*/ gen student=0 replace student=1 if ACT7DAYS==3 gen retired=0 replace retired=1 if ACT7DAYS==5 replace retired=1 if age>=60 &(ACT7DAYS==8|ACT7DAYS==9) gen empsp=-8 replace empsp=-7 if civstat==2 replace empsp=1 if LFSHSD12==1|LFSHSD12==4|LFSHSD12==7 replace empsp=2 if LFSHSD12==2|LFSHSD12==5|LFSHSD12==8 replace empsp=4 if LFSHSD12==3|LFSHSD12==6|LFSHSD12==9 replace empsp=3 if LFSHSD12==98 & ACT7DAYS_PR==1 recode WKWEHR_C (99.7=-7)(99.8/99.9=-8), gen(workhrs) replace workhrs=-7 if ACT7DAYS==2 & LFSGSS==5 replace empstat=4 if empstat==3 & workhrs==-7 recode INCM (1=0)(2=2500)(3=7500)(4=12500)(5=17500)(6=25000)(7=35000)(8=45000)(9=55000)(10=70000)(11=90000)(12=100000), gen(monthlyinc) gen empinclm=-5 replace empinclm=monthlyinc/12 if INCM<98 replace empinclm=-8 if INCM>=98 drop monthlyinc recode NAICS2007_C16 (97=-7)(98/99=-8), gen(occupo) label values occupo NAICS2007_C16 /*OCCUP=1 if NAICS2007_C16=10; OCCUP=2 if NAICS2007_C16=8; OCCUP=3 if NAICS2007_C16=9; OCCUP=4 if NAICS2007_C16=16; OCCUP=5 if NAICS2007_C16=11; OCCUP=6 if NAICS2007_C16=12; OCCUP=7,8,9 and 10: COULD NOT BE CREATED; OCCUP=11 if NAICS2007_C16=13, 14, or 15; OCCUP=12 if NAICS2007_C16=1 or 2; OCCUP=13 if NAICS2007_C16=3, 4, 5, 6, 7; OCCUP=14: COULD NOT BE CREATED; OCCUP=-7 if NAICS2007_C16=missing.*/ #delim ; gen isco1 = cond(NAICS2007_C16==10, 1, cond(NAICS2007_C16==8, 2, cond(NAICS2007_C16==9, 3, cond(NAICS2007_C16==16, 4, cond(NAICS2007_C16==11, 5, cond(NAICS2007_C16==12, 2, cond(NAICS2007_C16==13, 5, cond(NAICS2007_C16==14, 5, cond(NAICS2007_C16==15, 5, cond(NAICS2007_C16==1, 6, cond(NAICS2007_C16==2, 6, cond(NAICS2007_C16==3, 8, cond(NAICS2007_C16==4, 9, cond(NAICS2007_C16==5, 8, cond(NAICS2007_C16==6, 7, cond(NAICS2007_C16==7, 7, cond(NAICS2007_C16==97, -7, cond(NAICS2007_C16>97, -8, -8)))))))))))))))))); gen sector=-9 recode EDU10 (98/99=-8), gen(educa) label values educa EDU10 #delim ; gen edcat = cond(EDU10==10|EDU10==9|(EDU10==98&EOR_Q110==2), 1, cond(EDU10==8|(EDU10==98&EOR_Q110==2), 2, cond(EDU10>=1 & EDU10<=7, 3, -8))); recode GTU_Q110 (1/2=2)(3/4=1)(5/6=0)(8/9=-8),gen(rushed) recode SRH_Q110 (1/2=3)(3=2)(4=1)(5=0)(8/9=-8), gen(health) gen carer=-9 gen disab=0 replace disab=1 if HAL_Q410==3|SPA_Q410_C10==1 save "C:\...badcase_activity.dta", replace ********************************* /*CREATING ACTIVITY VARIABLES*/ ********************************** use "C:\...badcase_activity.dta", clear sort RECID gen av1=0 replace av1=1 if PLACE!=1 & (ACTCODE==11|ACTCODE==21|ACTCODE==40|ACTCODE==50|ACTCODE==60|ACTCODE==70|ACTCODE==80.3|ACTCODE==80.9) replace av1=av1*DURATION gen av2=0 replace av2=1 if PLACE==1 & (ACTCODE==11|ACTCODE==21|ACTCODE==40|ACTCODE==50|ACTCODE==60|ACTCODE==70|ACTCODE==80.3|ACTCODE==80.9|ACTCODE==22) replace av2=av2*DURATION gen av3=0 replace av3=1 if ACTCODE==12|ACTCODE==23|ACTCODE==80.1|ACTCODE==80.2|ACTCODE==832|ACTCODE==842 replace av3=av3*DURATION gen av4=0 replace av4=1 if ACTCODE==500|ACTCODE==511|ACTCODE==512|ACTCODE==520|ACTCODE==540|ACTCODE==550|ACTCODE==560.1|ACTCODE==560.2|ACTCODE==580.1|ACTCODE==580.9 replace av4=av4*DURATION gen av5=0 replace av5=1 if ACTCODE==30|ACTCODE==90|ACTCODE==590 replace av5=av5*DURATION gen av6=0 replace av6=1 if ACTCODE==101|ACTCODE==102|ACTCODE==110|ACTCODE==181.2 replace av6=av6*DURATION gen av7=0 replace av7=1 if ACTCODE==120|ACTCODE==130|ACTCODE==140 replace av7=av7*DURATION gen av8=0 replace av8=1 if ACTCODE==151|ACTCODE==161|ACTCODE==162|ACTCODE==163|ACTCODE==164|ACTCODE==171.2|ACTCODE==172|ACTCODE==173|ACTCODE==181.1|ACTCODE==181.3|ACTCODE==182|ACTCODE==183|ACTCODE==184|ACTCODE==185|ACTCODE==186|ACTCODE==271.1|ACTCODE==271.2|ACTCODE==271.3|ACTCODE==272.1|ACTCODE==272|ACTCODE==272.2|ACTCODE==282.1|ACTCODE==282.2|ACTCODE==282.9|ACTCODE==675.1|ACTCODE==675.2|ACTCODE==675.3|ACTCODE==675.4|ACTCODE==675.9 replace av8=av8*DURATION gen av9=0 replace av9=1 if ACTCODE==171.1 replace av9=av9*DURATION gen av10=0 replace av10=1 if ACTCODE==301|ACTCODE==302.1|ACTCODE==302.2|ACTCODE==302.3|ACTCODE==302.4|ACTCODE==302.9|ACTCODE==304|ACTCODE==310.1|ACTCODE==310.2|ACTCODE==310.3|ACTCODE==331|ACTCODE==332.1|ACTCODE==350.1|ACTCODE==350.2|ACTCODE==350.3|ACTCODE==350.9|ACTCODE==361|ACTCODE==362|ACTCODE==370|ACTCODE==380.1|ACTCODE==380.2|ACTCODE==380.3|ACTCODE==380.4|ACTCODE==380.9 replace av10=av10*DURATION gen av11=0 replace av11=1 if ACTCODE==200.1|ACTCODE==200.2|ACTCODE==200.3|ACTCODE==211|ACTCODE==212|ACTCODE==213|ACTCODE==220|ACTCODE==230.1|ACTCODE==230.2|ACTCODE==240|ACTCODE==250.1|ACTCODE==250.2|ACTCODE==260|ACTCODE==281.1|ACTCODE==281.2|ACTCODE==281.8|ACTCODE==281.9|ACTCODE==673.1|ACTCODE==673.2|ACTCODE==673.3|ACTCODE==673.4|ACTCODE==673.5|ACTCODE==673.9 replace av11=av11*DURATION gen av12=0 replace av12=1 if ACTCODE==190|ACTCODE==291|ACTCODE==292|ACTCODE==390|ACTCODE==491|ACTCODE==492 replace av12=av12*DURATION gen av13=0 replace av13=1 if ACTCODE==400|ACTCODE==480|ACTCODE==410.1 replace av13=av13*DURATION gen av14=0 replace av14=1 if ACTCODE==320|ACTCODE==340.1|ACTCODE==340.2|ACTCODE==410.2|ACTCODE==410.3 replace av14=av14*DURATION gen av15=0 replace av15=1 if ACTCODE==430|ACTCODE==431|ACTCODE==642|ACTCODE==661|ACTCODE==754 replace av15=av15*DURATION gen av16=0 replace av16=1 if ACTCODE==450|ACTCODE==460 replace av16=av16*DURATION gen av17=0 replace av17=1 if ACTCODE==691|ACTCODE==692|ACTCODE==791|ACTCODE==792|ACTCODE==793|ACTCODE==871|ACTCODE==872|ACTCODE==873|ACTCODE==891|ACTCODE==892|ACTCODE==893|ACTCODE==894|ACTCODE==990 replace av17=av17*DURATION gen av18=0 replace av18=1 if ACTCODE==332.2|ACTCODE==712|ACTCODE==713|ACTCODE==741|ACTCODE==742|ACTCODE==743|ACTCODE==780.2|ACTCODE==814 replace av18=av18*DURATION gen av19=0 replace av19=1 if ACTCODE==800|ACTCODE==801.1|ACTCODE==801.2|ACTCODE==801.3|ACTCODE==801.4|ACTCODE==801.5|ACTCODE==801.6|ACTCODE==801.7|ACTCODE==802.1|ACTCODE==802.2|ACTCODE==803.1|ACTCODE==803.2|ACTCODE==804.1|ACTCODE==804.2|ACTCODE==805.1|ACTCODE==805.2|ACTCODE==805.3|ACTCODE==806.1|ACTCODE==806.2|ACTCODE==807.1|ACTCODE==807.2|ACTCODE==807.3|ACTCODE==807.4|ACTCODE==808|ACTCODE==809|ACTCODE==810.1|ACTCODE==810.9|ACTCODE==811|ACTCODE==812|ACTCODE==813|ACTCODE==815|ACTCODE==821.2|ACTCODE==822 replace av19=av19*DURATION gen av20=0 replace av20=1 if ACTCODE==701|ACTCODE==702|ACTCODE==780.1 replace av20=av20*DURATION gen av21=0 replace av21=1 if ACTCODE==816|ACTCODE==821.1|ACTCODE==821.3 replace av21=av21*DURATION gen av22=0 replace av22=1 if ACTCODE==411|ACTCODE==640|ACTCODE==680.2 replace av22=av22*DURATION gen av23=0 replace av23=1 if ACTCODE==600|ACTCODE==610|ACTCODE==620|ACTCODE==630|ACTCODE==651|ACTCODE==652|ACTCODE==660.1|ACTCODE==660.2|ACTCODE==660.3|ACTCODE==660.4|ACTCODE==660.5|ACTCODE==660.9|ACTCODE==671.1|ACTCODE==671.2|ACTCODE==672|ACTCODE==674|ACTCODE==676|ACTCODE==677|ACTCODE==678|ACTCODE==680.1 replace av23=av23*DURATION gen av24=0 replace av24=1 if ACTCODE==711|ACTCODE==720|ACTCODE==730 replace av24=av24*DURATION gen av25=0 replace av25=1 if ACTCODE==770|ACTCODE==850.2|ACTCODE==862.2 replace av25=av25*DURATION gen av26=-9 gen av27=0 replace av27=1 if ACTCODE==760 replace av27=av27*DURATION gen av28=0 replace av28=1 if ACTCODE==303|ACTCODE==440 replace av28=av28*DURATION gen av29=0 replace av29=1 if PLACE!=1 & (ACTCODE==751|ACTCODE==752|ACTCODE==753) replace av29=av29*DURATION gen av30=0 replace av30=1 if ACTCODE==900.1|ACTCODE==900.2 replace av30=av30*DURATION gen av31=0 replace av31=1 if ACTCODE==911|ACTCODE==912|ACTCODE==913|ACTCODE==914.1|ACTCODE==914.9 replace av31=av31*DURATION gen av32=0 replace av32=1 if ACTCODE==920 replace av32=av32*DURATION gen av33=0 replace av33=1 if ACTCODE==530.1|ACTCODE==530.2 replace av33=av33*DURATION gen av34=0 replace av34=1 if ACTCODE==931 replace av34=av34*DURATION gen av35=0 replace av35=1 if ACTCODE==932.1|ACTCODE==932.2|ACTCODE==940.1|ACTCODE==940.2|ACTCODE==961 replace av35=av35*DURATION gen av36=0 replace av36=1 if ACTCODE==470 replace av36=av36*DURATION gen av37=0 replace av37=1 if ACTCODE==950|ACTCODE==951.1|ACTCODE==951.2|ACTCODE==951.3 replace av37=av37*DURATION gen av38=0 replace av38=1 if PLACE==1 & (ACTCODE==751|ACTCODE==752|ACTCODE==753) replace av38=av38*DURATION gen av39=0 replace av39=1 if ACTCODE==152|ACTCODE==841 replace av39=av39*DURATION gen av40=0 replace av40=1 if ACTCODE==831|ACTCODE==850.1|ACTCODE==861|ACTCODE==862.1|ACTCODE==863|ACTCODE==864|ACTCODE==865|ACTCODE==866|ACTCODE==867.1|ACTCODE==867.9|ACTCODE==880|ACTCODE==962|ACTCODE==980.1|ACTCODE==980.9 replace av40=av40*DURATION gen av41=0 replace av41=1 if ACTCODE==2 replace av41=av41*DURATION /*CREATING MAIN ACTIVITIES*/ gen main1=-9 gen main2=0 replace main2=1 if ACTCODE==450|ACTCODE==460 replace main2=main2*DURATION gen main3=-9 gen main4=0 replace main4=1 if ACTCODE==400|ACTCODE==410.1|ACTCODE==480 replace main4=main4*DURATION gen main5=0 replace main5=DURATION if inlist(ACTCODE, 50, 540) replace main5=0 if (PLACE==1|PLACE==3|PLACE==4) & inlist(ACTCODE, 50, 540) gen main6=0 replace main6=DURATION if ACTCODE==430|ACTCODE==431|ACTCODE==642|ACTCODE==661|ACTCODE==754 replace main6=DURATION if (PLACE==1|PLACE==3) & inlist(ACTCODE, 50, 540, 70) gen main7=0 replace main7=1 if PLACE!=1 & (ACTCODE==11|ACTCODE==21) replace main7=main7*DURATION gen main8=0 replace main8=1 if PLACE==1 & (ACTCODE==11|ACTCODE==12|ACTCODE==21|ACTCODE==23|ACTCODE==80.9) replace main8=main8*DURATION gen main9=0 replace main9=1 if PLACE!=1 & (ACTCODE==12|ACTCODE==23) replace main9=main9*DURATION gen main10=0 replace main10=1 if ACTCODE==80.1|ACTCODE==80.2|ACTCODE==832|ACTCODE==842 replace main10=main10*DURATION gen main11=0 replace main11=1 if ACTCODE==30 replace main11=main11*DURATION gen main12=0 replace main12=DURATION if ACTCODE==70 replace main12=0 if PLACE==1|PLACE==3 gen main13=0 replace main13=1 if ACTCODE==40|ACTCODE==60|ACTCODE==80.3|(PLACE!=1&ACTCODE==80.9) replace main13=main13*DURATION gen main14=0 replace main14=1 if ACTCODE==22 replace main14=main14*DURATION gen main15=0 replace main15=1 if ACTCODE==500|ACTCODE==550 replace main15=main15*DURATION gen main16=0 replace main16=1 if ACTCODE==530.1|ACTCODE==530.2 replace main16=main16*DURATION gen main17=0 replace main17=1 if ACTCODE==511|ACTCODE==512|ACTCODE==520|ACTCODE==560.1|ACTCODE==560.2|ACTCODE==580.1|ACTCODE==580.9 replace main17=main17*DURATION gen main18=0 replace main18=1 if ACTCODE==101|ACTCODE==102|ACTCODE==181.2 replace main18=main18*DURATION gen main19=0 replace main19=1 if ACTCODE==110 replace main19=main19*DURATION gen main20=0 replace main20=1 if ACTCODE==120|ACTCODE==130 replace main20=main20*DURATION gen main21=0 replace main21=1 if ACTCODE==140|ACTCODE==151|ACTCODE==152 replace main21=main21*DURATION gen main22=0 replace main22=1 if ACTCODE==161|ACTCODE==162|ACTCODE==163|ACTCODE==164|ACTCODE==171.2|ACTCODE==182 replace main22=main22*DURATION gen main23=0 replace main23=1 if ACTCODE==181.1|ACTCODE==181.3|ACTCODE==183|ACTCODE==184|ACTCODE==185|ACTCODE==186 replace main23=main23*DURATION gen main24=0 replace main24=1 if ACTCODE==301|ACTCODE==302.1|ACTCODE==302.2|ACTCODE==302.3|ACTCODE==302.4|ACTCODE==302.9|ACTCODE==310.1|ACTCODE==310.2|ACTCODE==310.3|ACTCODE==380.1|ACTCODE==380.3|ACTCODE==380.4|ACTCODE==380.9 replace main24=main24*DURATION gen main25=0 replace main25=1 if ACTCODE==410.2|ACTCODE==410.3|ACTCODE==320|ACTCODE==340.1|ACTCODE==340.2 replace main25=main25*DURATION gen main26=0 replace main26=1 if ACTCODE==331|ACTCODE==332.1|ACTCODE==304|ACTCODE==350.1|ACTCODE==350.2|ACTCODE==350.3|ACTCODE==350.9|ACTCODE==361|ACTCODE==362|ACTCODE==370|ACTCODE==380.2 replace main26=main26*DURATION gen main27=0 replace main27=1 if ACTCODE==172 replace main27=main27*DURATION gen main28=0 replace main28=1 if ACTCODE==200.1|ACTCODE==200.2|ACTCODE==200.3|ACTCODE==211|ACTCODE==212|ACTCODE==213|ACTCODE==250.1|ACTCODE==250.2|ACTCODE==673.1|ACTCODE==673.2 replace main28=main28*DURATION gen main29=0 replace main29=1 if ACTCODE==220|ACTCODE==281.8|ACTCODE==673.3 replace main29=main29*DURATION gen main30=0 replace main30=1 if ACTCODE==230.1|ACTCODE==230.2|ACTCODE==240|ACTCODE==673.5 replace main30=main30*DURATION gen main31=0 replace main31=1 if ACTCODE==260|ACTCODE==281.1|ACTCODE==281.2|ACTCODE==281.9|ACTCODE==673.4|ACTCODE==673.9 replace main31=main31*DURATION gen main32=0 replace main32=1 if ACTCODE==271.1|ACTCODE==271.2|ACTCODE==271.3|ACTCODE==272.1|ACTCODE==272|ACTCODE==272.2|ACTCODE==282.1|ACTCODE==282.2|ACTCODE==282.9|ACTCODE==675.1|ACTCODE==675.2|ACTCODE==675.3|ACTCODE==675.4|ACTCODE==675.9 replace main32=main32*DURATION gen main33=0 replace main33=1 if ACTCODE==600|ACTCODE==610|ACTCODE==620|ACTCODE==630|ACTCODE==651|ACTCODE==652|ACTCODE==660.1|ACTCODE==660.2|ACTCODE==660.3|ACTCODE==660.4|ACTCODE==660.5|ACTCODE==660.9|ACTCODE==671.1|ACTCODE==671.2|ACTCODE==672|ACTCODE==674|ACTCODE==676|ACTCODE==677|ACTCODE==678|ACTCODE==680.1 replace main33=main33*DURATION gen main34=0 replace main34=1 if ACTCODE==411|ACTCODE==640|ACTCODE==680.2 replace main34=main34*DURATION gen main35=0 replace main35=1 if ACTCODE==780.2 replace main35=main35*DURATION gen main36=0 replace main36=1 if ACTCODE==701|ACTCODE==702|ACTCODE==780.1 replace main36=main36*DURATION gen main37=0 replace main37=1 if ACTCODE==711|ACTCODE==720|ACTCODE==730 replace main37=main37*DURATION gen main38=0 replace main38=1 if ACTCODE==332.2|ACTCODE==712|ACTCODE==713|ACTCODE==741|ACTCODE==742|ACTCODE==743 replace main38=main38*DURATION gen main39=0 replace main39=DURATION if ACTCODE==303|ACTCODE==440 replace main39=DURATION if PLACE==4 & inlist(ACTCODE, 50, 540) gen main40=0 replace main40=1 if ACTCODE==760|ACTCODE==770|ACTCODE==850.2|ACTCODE==862.2 replace main40=main40*DURATION gen main41=0 replace main41=1 if ACTCODE==2 & PLACE>1 & PLACE<12 replace main41=main41*DURATION gen main42=0 replace main42=1 if ACTCODE==800|ACTCODE==801.1|ACTCODE==801.2|ACTCODE==801.3|ACTCODE==801.4|ACTCODE==801.5|ACTCODE==801.6|ACTCODE==801.7|ACTCODE==802.1|ACTCODE==802.2|ACTCODE==803.1|ACTCODE==803.2|ACTCODE==804.1|ACTCODE==804.2|ACTCODE==805.1|ACTCODE==805.2|ACTCODE==805.3|ACTCODE==806.1|ACTCODE==806.2|ACTCODE==807.1|ACTCODE==807.2|ACTCODE==807.3|ACTCODE==807.4|ACTCODE==808|ACTCODE==809|ACTCODE==810.1|ACTCODE==810.9|ACTCODE==813|ACTCODE==815|ACTCODE==821.2 replace main42=main42*DURATION gen main43=0 replace main43=1 if ACTCODE==821.1|ACTCODE==821.3 replace main43=main43*DURATION gen main44=0 replace main44=1 if ACTCODE==822 replace main44=main44*DURATION gen main45=0 replace main45=1 if ACTCODE==814|ACTCODE==816 replace main45=main45*DURATION gen main46=0 replace main46=1 if ACTCODE==171.1|ACTCODE==173|ACTCODE==811|ACTCODE==812 replace main46=main46*DURATION gen main47=-9 gen main48=0 replace main48=1 if ACTCODE==751|ACTCODE==752|ACTCODE==753 replace main48=main48*DURATION gen main49=0 replace main49=1 if ACTCODE==950|ACTCODE==951.1|ACTCODE==951.2|ACTCODE==951.3 replace main49=main49*DURATION gen main50=0 replace main50=1 if ACTCODE==861 replace main50=main50*DURATION gen main51=0 replace main51=1 if ACTCODE==880|ACTCODE==980.9 replace main51=main51*DURATION gen main52=0 replace main52=1 if ACTCODE==831|ACTCODE==850.1 replace main52=main52*DURATION gen main53=0 replace main53=1 if ACTCODE==962 replace main53=main53*DURATION gen main54=0 replace main54=1 if ACTCODE==841 replace main54=main54*DURATION gen main55=0 replace main55=1 if ACTCODE==470 replace main55=main55*DURATION gen main56=0 replace main56=1 if ACTCODE==931|ACTCODE==932.1|ACTCODE==932.2|ACTCODE==940.1|ACTCODE==940.2|ACTCODE==961 replace main56=main56*DURATION gen main57=0 replace main57=1 if ACTCODE==920 replace main57=main57*DURATION gen main58=0 replace main58=1 if ACTCODE==900.1|ACTCODE==900.2 replace main58=main58*DURATION gen main59=0 replace main59=1 if ACTCODE==911|ACTCODE==912|ACTCODE==913|ACTCODE==914.1|ACTCODE==914.9 replace main59=main59*DURATION gen main60=0 replace main60=1 if ACTCODE==862.1 replace main60=main60*DURATION gen main61=0 replace main61=1 if ACTCODE==863|ACTCODE==864|ACTCODE==865|ACTCODE==866|ACTCODE==867.1|ACTCODE==867.9|ACTCODE==980.1 replace main61=main61*DURATION gen main62=0 replace main62=1 if ACTCODE==2 & (PLACE>=12 & PLACE<=21) replace main62=main62*DURATION gen main63=0 replace main63=1 if ACTCODE==90 replace main63=main63*DURATION gen main64=0 replace main64=1 if ACTCODE==590 replace main64=main64*DURATION gen main65=0 replace main65=1 if ACTCODE==691|ACTCODE==692 replace main65=main65*DURATION gen main66=0 replace main66=1 if ACTCODE==291|ACTCODE==292 replace main66=main66*DURATION gen main67=0 replace main67=1 if ACTCODE==190|ACTCODE==390|ACTCODE==491|ACTCODE==492 replace main67=main67*DURATION gen main68=0 replace main68=1 if ACTCODE==791|ACTCODE==792|ACTCODE==793|ACTCODE==871|ACTCODE==872|ACTCODE==873|ACTCODE==891|ACTCODE==892|ACTCODE==893|ACTCODE==894|ACTCODE==990 replace main68=main68*DURATION gen main69=0 replace main69=1 if ACTCODE==2 & (PLACE==1|PLACE>21) replace main69=main69*DURATION ********************************************* ** SEC ACTIVITIES ** ********************************************* gen sec1=-9 gen sec2=-9 replace sec2=SACT1DUR if SACT1==33 & SACT1DUR<1440 replace sec2=SACT2DUR if SACT2==33 & SACT2DUR<1440 replace sec2=SACT3DUR if SACT3==33 & SACT3DUR<1440 gen sec3=-9 gen sec4=-9 replace sec4=SACT1DUR if SACT1==27 & SACT1DUR<1440 replace sec4=SACT2DUR if SACT2==27 & SACT2DUR<1440 replace sec4=SACT3DUR if SACT3==27 & SACT3DUR<1440 gen sec5=-9 replace sec5=SACT1DUR if SACT1==14 & SACT1DUR<1440 & (PLACE==2|PLACE==8) replace sec5=SACT2DUR if SACT2==14 & SACT2DUR<1440 & (PLACE==2|PLACE==8) replace sec5=SACT3DUR if SACT3==14 & SACT3DUR<1440 & (PLACE==2|PLACE==8) gen sec6=-9 replace sec6=SACT1DUR if SACT1==14 & SACT1DUR<1440 & ACTCODE==752 & (PLACE!=2|PLACE!=4|PLACE!=8) replace sec6=SACT2DUR if SACT2==14 & SACT2DUR<1440 & ACTCODE==752 & (PLACE!=2|PLACE!=4|PLACE!=8) replace sec6=SACT3DUR if SACT3==14 & SACT3DUR<1440 & ACTCODE==752 & (PLACE!=2|PLACE!=4|PLACE!=8) gen sec7=-9 replace sec7=SACT1DUR if SACT1==24 & SACT1DUR<1440 & (PLACE==2) replace sec7=SACT2DUR if SACT2==24 & SACT2DUR<1440 & (PLACE==2) replace sec7=SACT3DUR if SACT3==24 & SACT3DUR<1440 & (PLACE==2) gen sec8=-9 gen sec9=-9 gen sec10=-9 gen sec11=-9 gen sec12=-9 gen sec13=-9 gen sec14=-9 gen sec15=-9 replace sec15=SACT1DUR if SACT1==24 & SACT1DUR<1440 & (PLACE==8) replace sec15=SACT2DUR if SACT2==24 & SACT2DUR<1440 & (PLACE==8) replace sec15=SACT3DUR if SACT3==24 & SACT3DUR<1440 & (PLACE==8) gen sec16=-9 gen sec17=-9 gen sec18=-9 gen sec19=-9 gen sec20=-9 replace sec20=SACT1DUR if SACT1==15 & SACT1DUR<1440 replace sec20=SACT2DUR if SACT2==15 & SACT2DUR<1440 replace sec20=SACT3DUR if SACT3==15 & SACT3DUR<1440 gen sec21=-9 gen sec22=-9 gen sec23=-9 replace sec23=SACT1DUR if SACT1==30 & SACT1DUR<1440 replace sec23=SACT2DUR if SACT2==30 & SACT2DUR<1440 replace sec23=SACT3DUR if SACT3==30 & SACT3DUR<1440 gen sec24=-9 replace sec24=SACT1DUR if SACT1==31 & SACT1DUR<1440 replace sec24=SACT2DUR if SACT2==31 & SACT2DUR<1440 replace sec24=SACT3DUR if SACT3==31 & SACT3DUR<1440 gen sec25=-9 gen sec26=-9 gen sec27=-9 replace sec27=SACT1DUR if SACT1==26 & SACT1DUR<1440 replace sec27=SACT2DUR if SACT2==26 & SACT2DUR<1440 replace sec27=SACT3DUR if SACT3==26 & SACT3DUR<1440 gen sec28=-9 replace sec28=SACT1DUR if SACT1==17 & SACT1DUR<1440 replace sec28=SACT2DUR if SACT2==17 & SACT2DUR<1440 replace sec28=SACT3DUR if SACT3==17 & SACT3DUR<1440 gen sec29=-9 gen sec30=-9 gen sec31=-9 gen sec32=-9 replace sec32=SACT1DUR if SACT1==23 & SACT1DUR<1440 replace sec32=SACT2DUR if SACT2==23 & SACT2DUR<1440 replace sec32=SACT3DUR if SACT3==23 & SACT3DUR<1440 gen sec33=-9 gen sec34=-9 replace sec34=SACT1DUR if SACT1==34 & SACT1DUR<1440 replace sec34=SACT2DUR if SACT2==34 & SACT2DUR<1440 replace sec34=SACT3DUR if SACT3==34 & SACT3DUR<1440 gen sec35=-9 gen sec36=-9 gen sec37=-9 gen sec38=-9 gen sec39=-9 replace sec39=SACT1DUR if SACT1==14 & SACT1DUR<1440 & PLACE==4 replace sec39=SACT2DUR if SACT2==14 & SACT2DUR<1440 & PLACE==4 replace sec39=SACT3DUR if SACT3==14 & SACT3DUR<1440 & PLACE==4 gen sec40=-9 gen sec41=-9 gen sec42=-9 replace sec42=SACT1DUR if SACT1==32 & SACT1DUR<1440 replace sec42=SACT2DUR if SACT2==32 & SACT2DUR<1440 replace sec42=SACT3DUR if SACT3==32 & SACT3DUR<1440 gen sec43=-9 gen sec44=-9 gen sec45=-9 gen sec46=-9 gen sec47=-9 gen sec48=-9 replace sec48=SACT1DUR if SACT1==36 & SACT1DUR<1440 replace sec48=SACT2DUR if SACT2==36 & SACT2DUR<1440 replace sec48=SACT3DUR if SACT3==36 & SACT3DUR<1440 gen sec49=-9 replace sec49=SACT1DUR if SACT1==11 & SACT1DUR<1440 replace sec49=SACT2DUR if SACT2==11 & SACT2DUR<1440 replace sec49=SACT3DUR if SACT3==11 & SACT3DUR<1440 replace sec49=SACT1DUR if SACT1==19 & SACT1DUR<1440 replace sec49=SACT2DUR if SACT2==19 & SACT2DUR<1440 replace sec49=SACT3DUR if SACT3==19 & SACT3DUR<1440 replace sec49=SACT1DUR if SACT1==22 & SACT1DUR<1440 replace sec49=SACT2DUR if SACT2==22 & SACT2DUR<1440 replace sec49=SACT3DUR if SACT3==22 & SACT3DUR<1440 gen sec50=-9 replace sec50=SACT1DUR if SACT1==28 & SACT1DUR<1440 replace sec50=SACT2DUR if SACT2==28 & SACT2DUR<1440 replace sec50=SACT3DUR if SACT3==28 & SACT3DUR<1440 gen sec51=-9 gen sec52=-9 gen sec53=-9 gen sec54=-9 replace sec54=SACT1DUR if SACT1==35 & SACT1DUR<1440 replace sec54=SACT2DUR if SACT2==35 & SACT2DUR<1440 replace sec54=SACT3DUR if SACT3==35 & SACT3DUR<1440 gen sec55=-9 replace sec55=SACT1DUR if SACT1==29 & SACT1DUR<1440 replace sec55=SACT2DUR if SACT2==29 & SACT2DUR<1440 replace sec55=SACT3DUR if SACT3==29 & SACT3DUR<1440 gen sec56=-9 replace sec56=SACT1DUR if SACT1==16 & SACT1DUR<1440 replace sec56=SACT2DUR if SACT2==16 & SACT2DUR<1440 replace sec56=SACT3DUR if SACT3==16 & SACT3DUR<1440 gen sec57=-9 replace sec57=SACT1DUR if SACT1==18 & SACT1DUR<1440 replace sec57=SACT2DUR if SACT2==18 & SACT2DUR<1440 replace sec57=SACT3DUR if SACT3==18 & SACT3DUR<1440 gen sec58=-9 replace sec58=SACT1DUR if SACT1==12 & SACT1DUR<1440 replace sec58=SACT2DUR if SACT2==12 & SACT2DUR<1440 replace sec58=SACT3DUR if SACT3==12 & SACT3DUR<1440 gen sec59=-9 replace sec59=SACT1DUR if SACT1==13 & SACT1DUR<1440 replace sec59=SACT2DUR if SACT2==13 & SACT2DUR<1440 replace sec59=SACT3DUR if SACT3==13 & SACT3DUR<1440 gen sec60=-9 gen sec61=-9 replace sec61=SACT1DUR if SACT1==20 & SACT1DUR<1440 replace sec61=SACT2DUR if SACT2==20 & SACT2DUR<1440 replace sec61=SACT3DUR if SACT3==20 & SACT3DUR<1440 replace sec61=SACT1DUR if SACT1==21 & SACT1DUR<1440 replace sec61=SACT2DUR if SACT2==21 & SACT2DUR<1440 replace sec61=SACT3DUR if SACT3==21 & SACT3DUR<1440 gen sec62=-9 gen sec63=-9 gen sec64=-9 gen sec65=-9 gen sec66=-9 gen sec67=-9 gen sec68=-9 gen sec69=-9 save "C:\...badcase_activity.dta", replace ********************* ****FIXINGS BUGS IN CADADA 2010 ORIGINAL FILE with duration of episodes=0 min **************************************************** save "C:\..badcase_acticity.dta", replace sort RECID *gen subpop=0 *replace subpop=1 if DURATION==0 *by RECID: egen subpop_alt=sum(subpop) *drop subpop subpop_alt drop if DURATION==0 /*there were 176 observations in total in the episode file with duration of zero min*/ gen epnum=1 sort persid EPINO by persid: replace epnum=sum(epnum) by persid: egen totepnum=max(epnum) save "C:\...badcase_activity.dta", replace ********************* ****CREATING ALTERNATIVE ACTIVITIES for de-merging **************************************************** forval i=1/69{ by RECID, sort: egen main`i'_alt=sum(main`i') } ************go to line 1021 if this is your secound round (after imputation)******** *******************continue if it is the first round************* forval i=1/69{ replace main`i'_alt=0 if main`i'_alt<0 } forval i=1/69{ replace main`i'_alt=-9 if main`i'==-9 } **************the following lines are because there were mistakes in av8 and main32******* drop main32* av8* gen main32=0 replace main32=1 if ACTCODE==271.1|ACTCODE==271.2|ACTCODE==271.3|ACTCODE==272.1|ACTCODE==272|ACTCODE==272.2|ACTCODE==282.1|ACTCODE==282.2|ACTCODE==282.9|ACTCODE==675.1|ACTCODE==675.2|ACTCODE==675.3|ACTCODE==675.4|ACTCODE==675.9 replace main32=main32*DURATION gen av8=0 replace av8=1 if ACTCODE==151|ACTCODE==161|ACTCODE==162|ACTCODE==163|ACTCODE==164|ACTCODE==171.2|ACTCODE==172|ACTCODE==173|ACTCODE==181.1|ACTCODE==181.3|ACTCODE==182|ACTCODE==183|ACTCODE==184|ACTCODE==185|ACTCODE==186|ACTCODE==271.1|ACTCODE==271.2|ACTCODE==271.3|ACTCODE==272.1|ACTCODE==272|ACTCODE==272.2|ACTCODE==282.1|ACTCODE==282.2|ACTCODE==282.9|ACTCODE==675.1|ACTCODE==675.2|ACTCODE==675.3|ACTCODE==675.4|ACTCODE==675.9 replace av8=av8*DURATION by RECID: egen main32_alt=sum(main32) by RECID: egen av8_alt=sum(av8) /*these above lines are because 1 observation was coded with activity code 272, which does not exist, only 272.1 and 272.2 were in GSS 24*/ drop main41* main62* main69* gen main41=0 replace main41=1 if ACTCODE==2 & PLACE>1 & PLACE<12 replace main41=main41*DURATION gen main62=0 replace main62=1 if ACTCODE==2 & (PLACE>=12 & PLACE<=21) replace main62=main62*DURATION gen main69=0 replace main69=1 if ACTCODE==2 & (PLACE==1|PLACE>21) replace main69=main69*DURATION by RECID, sort: egen main41_alt=sum(main41) by RECID, sort: egen main62_alt=sum(main62) by RECID, sort: egen main69_alt=sum(main69) replace av2=DURATION if ACTCODE==22 drop av2_alt by RECID: egen av2_alt=sum(av2) replace av8=DURATION if ACTCODE==172 drop av8_alt by RECID: egen av8_alt=sum(av8) ********************* forval i=1/41{ by RECID: egen av`i'_alt=sum(av`i') } forval i=1/41{ replace av`i'_alt=0 if av`i'_alt<0 } forval i=1/41{ replace av`i'_alt=-9 if av`i'==-9 } ************ if this is the second round go to line 1051******************* **************************************** *** Creating some of the HEF files ***** **************************************** gen time=DURATION destring STARTIME, gen(clockst) replace clockst=clockst/100 format clockst %9.2fc gen start=0 by RECID: gen end=sum(time) replace start=end-time *drop main gen main=-5 forval i=1/69{ replace main=`i' if main`i'>0 } ********************go to line 1343 if it is your second round******** gen av=-5 forval i=1/41{ replace av=`i' if av`i'>0 } forval i=1/41{ replace av=`i' if av`i'<0 & av<0 } /*there were few of the activities that were -9 in the original av's*/ gen sec=-5 forval i=1/69{ replace sec=`i' if sec`i'>0 } recode sec (-5=-9) recode PLACE (1/8=1)(10/11=1)(9=2)(14=2)(17=2)(12/13=3)(15/16=3)(18/20=3)(21=-8)(97/99=-8), gen(inout) recode PLACE (1=1)(2=3)(3=2)(4=6)(5=7)(6=5)(7=5)(8=4)(9=9)(10=5)(11=9)(12/21=8)(97/99=-8), gen(eloc) ********************************************* ************* Recoding inout and eloc according to the activity code ********************************************* replace inout=1 if inout==-8 & (ACTCODE==11|ACTCODE==40|ACTCODE==60|ACTCODE==102|ACTCODE==181.1|ACTCODE==185|ACTCODE==240|ACTCODE==272.1|ACTCODE==272.2|ACTCODE==281.1|ACTCODE==281.2|ACTCODE==281.8|ACTCODE==281.9|ACTCODE==282.9|ACTCODE==302.4|ACTCODE==302.9|ACTCODE==310.1|ACTCODE==320|ACTCODE==331|ACTCODE==332.1|ACTCODE==340.1|ACTCODE==350.9|ACTCODE==361|ACTCODE==362|ACTCODE==370|ACTCODE==380.2|ACTCODE==380.4|ACTCODE==400|ACTCODE==430|ACTCODE==480|ACTCODE==520|ACTCODE==540|ACTCODE==560.1|ACTCODE==610|ACTCODE==640|ACTCODE==652|ACTCODE==660.9|ACTCODE==671.1|ACTCODE==672|ACTCODE==675.2|ACTCODE==730|ACTCODE==753|ACTCODE==754|ACTCODE==770|ACTCODE==806.2|ACTCODE==850.1|ACTCODE==850.2|ACTCODE==861|ACTCODE==862.1|ACTCODE==863|ACTCODE==911|ACTCODE==951.1|ACTCODE==961) replace inout=2 if inout==-8 & (ACTCODE==130|ACTCODE==190|ACTCODE==712|ACTCODE==713|ACTCODE==804.1|ACTCODE==810.9|ACTCODE==811|ACTCODE==813) replace inout=3 if inout==-8 & (ACTCODE==871|ACTCODE==872|ACTCODE==873) replace eloc=1 if eloc==-8 & (ACTCODE==102|ACTCODE==130|ACTCODE==181.1|ACTCODE==185|ACTCODE==240|ACTCODE==272.1|ACTCODE==272.2|ACTCODE==400|ACTCODE==430|ACTCODE==480|ACTCODE==991|ACTCODE==951.1|ACTCODE==961) replace eloc=2 if eloc==-8 & (ACTCODE==672|ACTCODE==675.2) replace eloc=3 if eloc==-8 & (ACTCODE==11|ACTCODE==40|ACTCODE==60) replace eloc=4 if eloc==-8 & (ACTCODE==540|ACTCODE==560.1) replace eloc=5 if eloc==-8 & (ACTCODE==302.4|ACTCODE==302.9|ACTCODE==304|ACTCODE==310.1|ACTCODE==320|ACTCODE==331|ACTCODE==332.1|ACTCODE==340.1|ACTCODE==350.9|ACTCODE==361|ACTCODE==362|ACTCODE==370|ACTCODE==380.4) replace eloc=6 if eloc==-8 & (ACTCODE==303) replace eloc=7 if eloc==-8 & (ACTCODE==640) replace eloc=8 if ACTCODE==90|ACTCODE==190|ACTCODE==291|ACTCODE==292|ACTCODE==390|ACTCODE==491|ACTCODE==492|ACTCODE==692|ACTCODE==691|ACTCODE==674|ACTCODE==590|ACTCODE==791|ACTCODE==792|ACTCODE==793|ACTCODE==804.2|ACTCODE==805.2|ACTCODE==809.0|ACTCODE==813|ACTCODE==815|ACTCODE==822|ACTCODE==821.1|ACTCODE==821.2|ACTCODE==821.3|ACTCODE==871|ACTCODE==872|ACTCODE==873|ACTCODE==891|ACTCODE==894|ACTCODE==990 /*all travel should be recoded as eloc==8 for travelling activities*/ replace eloc=9 if eloc==-8 & (ACTCODE==281.1|ACTCODE==281.2|ACTCODE==281.8|ACTCODE==281.9|ACTCODE==282.9|ACTCODE==380.2|ACTCODE==520|ACTCODE==610|ACTCODE==652|ACTCODE==660.9|ACTCODE==702|ACTCODE==711|ACTCODE==712|ACTCODE==713|ACTCODE==730|ACTCODE==770|ACTCODE==701|ACTCODE==780.2|ACTCODE==804.1|ACTCODE==806.2|ACTCODE==810.9|ACTCODE==811|ACTCODE==850.1|ACTCODE==850.2) replace inout=1 if inout==-8 & ACTCODE==304 & eloc==5 replace inout=1 if inout==-8 & ACTCODE==303 & eloc==6 replace inout=1 if inout==-8 & ACTCODE==22 /*because the three instances were also surrounded by travel activity codes*/ replace eloc=9 if eloc==-8 & ACTCODE==22 replace inout=2 if inout==-8 & ACTCODE==30 /*because the three instances were also surrounded by work codes and were short*/ replace eloc=8 if eloc==-8 & ACTCODE==30 replace inout=2 if inout==-8 & ACTCODE==90 /*because because 54 observations were together with eloc==9 for being not in a public transportation or vehicle travel, and four instances with eloc==-8 were also surrounded by travel by transport activity codes*/ replace inout=3 if inout==-8 & eloc==-8 & ACTCODE==90 & RECID==3474 /*because one observation was in tandem with another travel in the morning by subway*/ replace inout=2 if inout==-8 & ACTCODE==172 /*because the two observations happened after work and were short*/ replace eloc=9 if eloc==-8 & ACTCODE==172 replace inout=1 if inout==-8 & ACTCODE==671.2 /*animal pet care, because the activity right next to it was at the respondent house, there is only one observation*/ replace eloc=1 if eloc==-8 & ACTCODE==671.2 * ICT * gen ict=0 replace ict=1 if inlist(ACTCODE, 80.1, 181.2, 302.3, 310.3, 530.2, 862.1, 862.2, 863, 864, 865, 866, 867.1, 867.9, 940.2, 951.2, 951.3, 980.1, 980.9) forval i=1/3{ replace ict=1 if inlist(SACT`i', 20, 21, 22) } *MTRAV* recode PLACE (1/11=-7)(12/13=1)(14=3)(15/16=2)(17=4)(18=2)(19=1)(20=2)(21=5)(97/99=-8), gen(mtrav) replace mtrav=1 if inlist(ACTCODE, 871, 872)& (PLACE!=14|PLACE!=17) replace mtrav=3 if inlist(ACTCODE, 871, 872) & PLACE==14 replace mtrav=4 if inlist(ACTCODE, 871, 872) & PLACE==17 replace mtrav=2 if inlist(ACTCODE, 873) & PLACE!=14 replace mtrav=3 if ACTCODE==873 & PLACE==14 replace mtrav=3 if inlist(ACTCODE, 821.1, 821.2, 821.3) replace inout=2 if inout==1 & mtrav==3 & PLACE==10 & ACTCODE==821.1 replace inout=2 if inout==1 & mtrav==3 & PLACE==4 & ACTCODE==821.1 & inlist(RECID, 807, 1352) replace mtrav=4 if inlist(ACTCODE, 804.2, 805.2, 809, 813, 815, 822) replace inout=2 if mtrav==4 & inout==1 & inlist(ACTCODE, 805.2, 813, 815) replace inout=2 if mtrav==4 & inout==1 & ACTCODE==809 replace mtrav=5 if main62>0 replace mtrav=5 if eloc==8 & mtrav==-8 replace mtrav=-7 if eloc>0 & eloc<8 replace mtrav=-7 if eloc==9 recode ALONE (1=1)(2=0)(7/9=-8),gen(alone) replace alone=1 if alone==-8 & inlist(ACTCODE, 400, 450, 460, 480) recode CHILDHSD (1=1)(2=0)(7/9=-8),gen(child) replace child=1 if NHSDCL15==1 replace child=0 if inlist(ACTCODE, 400, 450, 460, 480) replace child=0 if (NHSDCL15==2) & child==-8 recode SPOUSE (1=1)(2=0)(7/9=-8),gen(sppart) replace sppart=0 if inlist(ACTCODE, 400, 450, 460, 480) recode PARHSD (1=1)(2=0)(7/9=-8),gen(oad) replace oad=1 if MEMBHSD==1|NHSDPAR==1|NHSDC15P==1|OTHFAM==1|FRIENDS==1|OTHERS==1 replace oad=0 if (MEMBHSD==2|NHSDPAR==2|NHSDC15P==2|OTHFAM==2|FRIENDS==2|OTHERS==2) & oad==-8 replace oad=0 if inlist(ACTCODE, 400, 450, 460, 480) save "C:\...badcase_activity.dta", replace **************** fixing location vars replace eloc=1 if eloc==-8 & inlist(main, 1, 3) replace inout=1 if inout==-8 & (eloc==1|eloc==6) replace mtrav=-7 if eloc==1 & inlist(main, 1, 3) replace eloc=2 if eloc==-8 & inlist(RECID, 4122, 4602, 6099, 7471, 10805) replace mtrav=-7 if eloc==2 & inlist(RECID, 4122, 4602, 6099, 7471, 10805) replace eloc=6 if eloc==-8 & inlist(main, 6) replace mtrav=-7 if eloc==6 & inlist(main, 6) replace eloc=9 if eloc==-8 & inlist(main, 33, 50, 51, 59, 60, 61) replace mtrav=-7 if eloc==9 & inlist(main, 33, 50, 51, 59, 60, 61) ****************************************************************** **** BADCASES WITH ACTIVITY AND BACKGROUND VARIABLES ************* ****************************************************************** sort RECID merge m:m RECID using "C:\...badcase_activity.dta" drop _merge save "C:\...badcase_activity.dta", replace use "C:\...badcase_activity.dta", clear *no age or gender gen loss_age_sex=1 if sex<0|age<0 replace loss_age_sex=0 if loss_age_sex==. *91+ missing minutes of activity gen missing_91=1 if av41_alt>90 replace missing_91=0 if missing_91==. *Missing day gen missing_day=1 if day==-8 replace missing_day=0 if missing_day==. *2 or more basic activities missing: (1) sleep or rest, (2) eating or drinking *(3) personal care (4) trave/exercise (5) other care:child care or adult care *drop cat_sleep cat1_sleep cat_eat cat2_eat cat_personal cat3_personal cat_travel cat4_travel gen cat_sleep=0 replace cat_sleep=1 if inlist(ACTCODE, 450, 460, 470) replace cat_sleep=1 if inlist(main, 2, 3) replace cat_sleep=1 if SACT1==29|SACT1==33|SACT2==29|SACT2==33|SACT3==29|SACT3==33 by RECID, sort: egen cat1_sleep=max(cat_sleep) gen cat_eat=0 replace cat_eat=1 if inlist(ACTCODE, 50, 540, 430, 431, 642, 661, 754, 70, 752, 303, 440, 101, 102) replace cat_eat=1 if SACT1==14|SACT2==14|SACT3==14 by RECID, sort: egen cat2_eat=max(cat_eat) gen cat_personal=0 replace cat_personal=1 if inlist(ACTCODE, 400, 410.1, 410.2, 410.3, 480, 320, 340.1, 340.2) replace cat_personal=1 if inlist(main, 2, 3) replace cat_personal=1 if SACT1==27|SACT2==27|SACT3==27 by RECID, sort: egen cat3_personal=max(cat_personal) gen cat_travel=0 replace cat_travel=1 if inlist(ACTCODE, 90, 590, 691, 692, 291, 292, 190, 390, 491, 492, 791, 792, 793, 871, 872, 873, 891, 892, 893, 894, 990, 821.1, 821.3, 171.1) replace cat_travel=1 if inout==3|eloc==8 replace cat_travel=1 if SACT1==31|SACT2==31|SACT3==31 by RECID, sort: egen cat4_travel=max(cat_travel) gen cat5_care=0 *replace cat5_care=1 if carer==1 /*in Canada 2010, there are no observations that could be coded for carer*/ gen athome=0 replace athome=DURATION if inlist(eloc, 1, 2) by RECID, sort: egen tot_athome=max(athome) *use "C:\Users\Miraiko\Documents\2015 work\CTUR\2010\CANADA2010HAF_HEF_x.dta", clear *collapse (sum) cat1_sleep cat2_eat cat3_personal cat4_travel cat5_care athome, by(RECID) *save badcase_activity.dta *use "C:\Users\Miraiko\Documents\2015 work\CTUR\2010\badcase_activity.dta", clear *sort RECID *merge m:m RECID using "C:\Users\Miraiko\Documents\2015 work\CTUR\2010\CANADA2010HAF_HEF_x.dta" *sort RECID EPINO *drop _merge *drop loss_act_int tot_athome loss_basic_act tot_loss_basic_act gen loss_act_int=4-cat1_sleep-cat2_eat-cat3_personal-cat4_travel gen loss_basic_act=0 if loss_act_int<2 replace loss_basic_act=0 if loss_act_int==2 & totepnum>=15 *replace loss_basic_act=0 if cat5_care==1 replace loss_basic_act=0 if cat3_personal==0 & cat5_care==0 & cat1_sleep==1 & cat4_travel==1 replace loss_basic_act=0 if loss_act_int==2 & tot_athome>=1000 & totepnum>=12 replace loss_basic_act=1 if loss_basic_act==. by RECID, sort: egen tot_loss_basic_act=max(loss_basic_act) *WE COMPUTE THE "BADCASE" VARIABLE replace badcase=0 if loss_age_sex==0 & missing_day==0 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=1 if loss_age_sex==1 & missing_day==0 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=2 if loss_age_sex==0 & missing_day==1 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=3 if loss_age_sex==0 & missing_day==0 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=4 if loss_age_sex==0 & missing_day==0 & missing_91==0 & totepnum<7 & tot_loss_basic_act==0 replace badcase=5 if loss_age_sex==0 & missing_day==0 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=6 if loss_age_sex==1 & missing_day==1 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=7 if loss_age_sex==1 & missing_day==0 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=8 if loss_age_sex==1 & missing_day==0 & missing_91==0 & totepnum<7 & tot_loss_basic_act==0 replace badcase=9 if loss_age_sex==1 & missing_day==0 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=10 if loss_age_sex==0 & missing_day==1 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=11 if loss_age_sex==0 & missing_day==1 & missing_91==0 & totepnum<7 & tot_loss_basic_act==0 replace badcase=12 if loss_age_sex==0 & missing_day==1 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=13 if loss_age_sex==0 & missing_day==0 & missing_91==1 & totepnum<7 & tot_loss_basic_act==0 replace badcase=14 if loss_age_sex==0 & missing_day==0 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=15 if loss_age_sex==0 & missing_day==0 & missing_91==0 & totepnum<7 & tot_loss_basic_act==1 replace badcase=16 if loss_age_sex==1 & missing_day==1 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==0 replace badcase=17 if loss_age_sex==1 & missing_day==1 & missing_91==0 & totepnum<7 & tot_loss_basic_act==0 replace badcase=18 if loss_age_sex==1 & missing_day==1 & missing_91==0 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=19 if loss_age_sex==1 & missing_day==0 & missing_91==1 & totepnum<7 & tot_loss_basic_act==0 replace badcase=20 if loss_age_sex==1 & missing_day==0 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=21 if loss_age_sex==1 & missing_day==0 & missing_91==0 & totepnum<7 & tot_loss_basic_act==1 replace badcase=22 if loss_age_sex==0 & missing_day==1 & missing_91==1 & totepnum<7 & tot_loss_basic_act==0 replace badcase=23 if loss_age_sex==0 & missing_day==1 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=24 if loss_age_sex==0 & missing_day==1 & missing_91==0 & totepnum<7 & tot_loss_basic_act==1 replace badcase=25 if loss_age_sex==0 & missing_day==0 & missing_91==1 & totepnum<7 & tot_loss_basic_act==1 replace badcase=26 if loss_age_sex==1 & missing_day==1 & missing_91==1 & totepnum<7 & tot_loss_basic_act==0 replace badcase=27 if loss_age_sex==1 & missing_day==1 & missing_91==1 & totepnum>=7 & tot_loss_basic_act==1 replace badcase=28 if loss_age_sex==1 & missing_day==1 & missing_91==0 & totepnum<7 & tot_loss_basic_act==1 replace badcase=29 if loss_age_sex==1 & missing_day==0 & missing_91==1 & totepnum<7 & tot_loss_basic_act==1 replace badcase=30 if loss_age_sex==0 & missing_day==1 & missing_91==1 & totepnum<7 & tot_loss_basic_act==1 replace badcase=31 if loss_age_sex==1 & missing_day==1 & missing_91==1 & totepnum<7 & tot_loss_basic_act==1 *****************************BUGs****** replace persid=persid-1 if persid>13132 /*in the original data RECID 13132 does not exist*/ **************************************************************** ***************************Imputing activities****** replace main47=DURATION if ACTCODE==172 & inout==2 recode main47 (-9=0) replace main27=0 if ACTCODE==172 & inout==2 forval i=1/41{ drop av`i'_alt } forval i=1/69{ drop main`i'_alt } replace main3=DURATION if main69>0 & inlist(RECID, 2718, 3090, 4826, 13095) replace main69=0 if main69>0 & inlist(RECID, 2718, 3090, 4826, 13095) recode main3 (-9=0) replace main1=0 if main69>0 & inlist(RECID, 3053, 7003) recode main1 (-9=0) replace main1=DURATION if main69>0 & RECID==7462 replace main69=0 if main69>0 & RECID==7462 ********* go to line 966****************** ****************************************************************** **************************************** ******PSEUDO WEIGHTS**************************final weights are created in .haf -----> these are just for enabling ordering **************************************** gen ocombwt=WGHT_PER /*original person weight*/ egen count=count(badcase) egen countp_bis=count(badcase) if badcase==0 egen countp=min(countp_bis) sort sex age day egen daywt=group(sex age day) if badcase==0 egen ngroupsd=max(daywt) if badcase==0 by sex age day: egen daycount2=count(daywt) if badcase==0 sort sex age egen weekwt=group(sex age) if badcase==0 egen ngroupsp=max(weekwt) if badcase==0 by sex age: egen wkcount2=count(weekwt) if badcase==0 generate propwt=((wkcount2/7)/daycount2) replace propwt=0 if badcase!=0 replace propwt=propwt*(count/countp) egen mean_weight=mean(propwt) replace propwt=propwt/mean_weight save "C:\...badcase_activity.dta", replace *********************************** ******** CREATING HAF*************** ************************************* use "C:\...badcase_activity.dta", clear save "C:\...ca2010haf.dta", replace ****** see BUGS section below to create sppart_alt var first******* #delimit; order RECID country survey swave msamp hldid persid id parntid1 parntid2 partid day month year diary badcase hhtype hhldsize nchild agekidx agekid2 incorig income ownhome urban computer vehicle sex age famstat singpar relrefp civstat cohab citizen empstat emp unemp student retired empsp workhrs empinclm occupo isco1 sector educa edcat rushed health carer disab main1_alt main2_alt main3_alt main4_alt main5_alt main6_alt main7_alt main8_alt main9_alt main10_alt main11_alt main12_alt main13_alt main14_alt main15_alt main16_alt main17_alt main18_alt main19_alt main20_alt main21_alt main22_alt main23_alt main24_alt main25_alt main26_alt main27_alt main28_alt main29_alt main30_alt main31_alt main32_alt main33_alt main34_alt main35_alt main36_alt main37_alt main38_alt main39_alt main40_alt main41_alt main42_alt main43_alt main44_alt main45_alt main46_alt main47_alt main48_alt main49_alt main50_alt main51_alt main52_alt main53_alt main54_alt main55_alt main56_alt main57_alt main58_alt main59_alt main60_alt main61_alt main62_alt main63_alt main64_alt main65_alt main66_alt main67_alt main68_alt main69_alt av1_alt av2_alt av3_alt av4_alt av5_alt av6_alt av7_alt av8_alt av9_alt av10_alt av11_alt av12_alt av13_alt av14_alt av15_alt av16_alt av17_alt av18_alt av19_alt av20_alt av21_alt av22_alt av23_alt av24_alt av25_alt av26_alt av27_alt av28_alt av29_alt av30_alt av31_alt av32_alt av33_alt av34_alt av35_alt av36_alt av37_alt av38_alt av39_alt av40_alt av41_alt sppart_alt ocombwt propwt; #delimit; keep RECID country survey swave msamp hldid persid id parntid1 parntid2 partid day month year diary badcase hhtype hhldsize nchild agekidx agekid2 incorig income ownhome urban computer vehicle sex age famstat singpar relrefp civstat cohab citizen empstat emp unemp student retired empsp workhrs empinclm occupo isco1 sector educa edcat rushed health carer disab main1_alt main2_alt main3_alt main4_alt main5_alt main6_alt main7_alt main8_alt main9_alt main10_alt main11_alt main12_alt main13_alt main14_alt main15_alt main16_alt main17_alt main18_alt main19_alt main20_alt main21_alt main22_alt main23_alt main24_alt main25_alt main26_alt main27_alt main28_alt main29_alt main30_alt main31_alt main32_alt main33_alt main34_alt main35_alt main36_alt main37_alt main38_alt main39_alt main40_alt main41_alt main42_alt main43_alt main44_alt main45_alt main46_alt main47_alt main48_alt main49_alt main50_alt main51_alt main52_alt main53_alt main54_alt main55_alt main56_alt main57_alt main58_alt main59_alt main60_alt main61_alt main62_alt main63_alt main64_alt main65_alt main66_alt main67_alt main68_alt main69_alt av1_alt av2_alt av3_alt av4_alt av5_alt av6_alt av7_alt av8_alt av9_alt av10_alt av11_alt av12_alt av13_alt av14_alt av15_alt av16_alt av17_alt av18_alt av19_alt av20_alt av21_alt av22_alt av23_alt av24_alt av25_alt av26_alt av27_alt av28_alt av29_alt av30_alt av31_alt av32_alt av33_alt av34_alt av35_alt av36_alt av37_alt av38_alt av39_alt av40_alt av41_alt sppart_alt ocombwt propwt; save "C:\...ca2010haf.dta", replace **************************************** *************BUGS******************* **************************************** *sppart for HAF gen sppart_haf=sppart*DURATION if sppart>=0 sort RECID by RECID: egen sppart_alt=sum(sppart_haf) **********after the keep command------>************** duplicates drop save "C:\...ca2010haf.dta", replace use "C:\...ca2010haf.dta", clear drop RECID forval i=1/69{ rename main`i'_alt main`i' } forval i=1/41{ rename av`i'_alt av`i' } rename sppart_alt sppart ************************checking for sum=1440*********** sort persid forval i=1/41{ gen av`i'_alt=av`i' if av`i'>=0 replace av`i'_alt=0 if av`i'_alt==. } forval i=1/69{ gen main`i'_alt=main`i' if main`i'>=0 replace main`i'_alt=0 if main`i'_alt==. } egen main_sum=rowtotal(main1_alt - main69_alt) egen av_sum=rowtotal(av1_alt - av41_alt) forval i=1/41{ drop av`i'_alt } forval i=1/69{ drop main`i'_alt } drop main_sum av_sum save "C:\...ca2010haf.dta", replace **************************************** ****** FINAL WEIGHTS************************** **************************************** drop propwt egen count=count(badcase) egen countp_bis=count(badcase) if badcase==0 egen countp=min(countp_bis) sort sex age day egen daywt=group(sex age day) if badcase==0 egen ngroupsd=max(daywt) if badcase==0 by sex age day: egen daycount2=count(daywt) if badcase==0 sort sex age egen weekwt=group(sex age) if badcase==0 egen ngroupsp=max(weekwt) if badcase==0 by sex age: egen wkcount2=count(weekwt) if badcase==0 generate propwt=((wkcount2/7)/daycount2) replace propwt=0 if badcase!=0 replace propwt=propwt*(count/countp) egen mean_weight=mean(propwt) replace propwt=propwt/mean_weight drop count countp_bis countp daywt ngroupsd daycount2 weekwt ngroupsp wkcount2 mean_weight save "C:\...ca2010haf.dta", replace ********************************************** ***********CREATING HEF ********************** ********************************************** use "C:\...badcase_activity.dta", clear save "C:\...ca2010hef.dta", replace use "C:\...ca2010hef.dta", clear #delimit; order country survey swave msamp hldid persid id day cday month year diary badcase sex age time clockst start end epnum main sec av inout eloc ict mtrav alone child sppart oad; #delimit; keep country survey swave msamp hldid persid id day cday month year diary badcase sex age time clockst start end epnum main sec av inout eloc ict mtrav alone child sppart oad; sort persid start save "C:\...ca2010hef.dta", replace ********************************************** ***********CREATING HSF ********************** ********************************************** use "C:\...ca2010haf.dta", clear save "C:\...ca2010hsf.dta", replace use "C:\...ca2010hsf.dta", clear *forval i=1/69{ *recode main`i' (-9=0) *} egen sleep=rowtotal(main2 main3) egen eatdrink=rowtotal(main5 main6) egen selfcare=rowtotal(main1 main4) egen paidwork=rowtotal(main7 - main14) egen educatn=rowtotal(main15 - main17) egen foodprep=rowtotal(main18 main19) egen cleanetc=rowtotal(main20 main21 main23) egen maintain=rowtotal(main22) egen shopserv=rowtotal(main24 - main26) egen garden=rowtotal(main46) egen petcare=rowtotal(main27 main47) egen eldcare=rowtotal(main32) egen pkidcare=rowtotal(main28 main31) egen ikidcare=rowtotal(main29 main30) egen religion=rowtotal(main34) egen volorgwk=rowtotal(main33) egen commute=rowtotal(main63 main64) egen travel=rowtotal(main62 main65 - main68) egen sportex=rowtotal(main42 - main44) egen tvradio=rowtotal(main57 - main59) egen read=rowtotal(main56) egen compint=rowtotal(main60 main61) egen goout=rowtotal(main35 - main41 main45) egen leisure=rowtotal(main48 - main55) egen missing=rowtotal(main69) ***********should add up to 1440***** egen act_total=rowtotal(sleep - missing) sum act_total drop act_total ************************************* egen restrnt=rowtotal(main39) egen eatatwrk=rowtotal(main5) egen compgame=rowtotal(main60) egen caretrav=rowtotal(main66) #delim; order country survey msamp hldid persid id day month year hhldsize nchild agekidx income urban sex age civstat empstat workhrs empinclm edcat sleep eatdrink selfcare paidwork educatn foodprep cleanetc maintain shopserv garden petcare eldcare pkidcare ikidcare religion volorgwk commute travel sportex tvradio read compint goout leisure missing restrnt eatatwrk compgame caretrav sppart propwt; #delim; keep country survey msamp hldid persid id day month year hhldsize nchild agekidx income urban sex age civstat empstat workhrs empinclm edcat sleep eatdrink selfcare paidwork educatn foodprep cleanetc maintain shopserv garden petcare eldcare pkidcare ikidcare religion volorgwk commute travel sportex tvradio read compint goout leisure missing restrnt eatatwrk compgame caretrav sppart propwt; save "C:\...ca2010hsf.dta", replace ***************************************************** ****SOME OTHER BUGS (do not use)********************* ****************************************************** use "C:\...ca2010haf.dta", clear sum av26 replace av26=0 if av26<0 ********** sort persid forval i=1/41{ drop av`i'_alt } forval i=1/69{ drop main`i'_alt } drop main_sum av_sum main_total av_total sort persid forval i=1/41{ gen av`i'_alt=av`i' if av`i'>=0 } forval i=1/69{ gen main`i'_alt=main`i' if main`i'>=0 } egen main_sum=rowtotal(main1_alt - main69_alt) egen av_sum=rowtotal(av1_alt - av41_alt) egen main_total=total(main_sum), by(persid) egen av_total=total(av_sum), by(persid) *********** recode av26 (0=-9) save "C:\...ca2010haf.dta", replace