**MTUS-X***CANADIAN 2005** *** CANADIAN 2005*** *** EPISODE FILE AND THEN JOIN WITH THE MAIN FILE*** use "C:\Users\Test\Dropbox\2005\original\data\Data Files SPSS\C19PUMFE_NUM.DTA", clear renvars, upper sort RECID EPINO /*CREATING MAIN ACTIVITIES*/ gen main1=0 gen main2=0 replace main2=1 if ACTCODE==450|ACTCODE==460 replace main2=main2*DURATION gen main3=0 gen main4=0 replace main4=1 if ACTCODE==400|ACTCODE==410|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|ACTCODE==011|ACTCODE==021|ACTCODE==80) replace main7=main7*DURATION gen main8=0 replace main8=1 if PLACE==1 & (ACTCODE==11|ACTCODE==12|ACTCODE==21|ACTCODE==23|ACTCODE==80) 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==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=DURATION if ACTCODE==40|ACTCODE==60 replace main13=DURATION if PLACE!=1 & ACTCODE==80 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=DURATION if ACTCODE==530 gen main17=0 replace main17=1 if ACTCODE==511|ACTCODE==512|ACTCODE==520|ACTCODE==560|ACTCODE==580 replace main17=main17*DURATION gen main18=0 replace main18=1 if ACTCODE==101|ACTCODE==102 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|ACTCODE==182 replace main22=main22*DURATION gen main23=0 replace main23=1 if ACTCODE==181|ACTCODE==183|ACTCODE==184|ACTCODE==185|ACTCODE==186 replace main23=main23*DURATION gen main24=0 replace main24=1 if ACTCODE==301|ACTCODE==302|ACTCODE==310|ACTCODE==380 replace main24=main24*DURATION gen main25=0 replace main25=1 if ACTCODE==320|ACTCODE==340 replace main25=main25*DURATION gen main26=0 replace main26=1 if ACTCODE==331|ACTCODE==332|ACTCODE==304|ACTCODE==350|ACTCODE==361|ACTCODE==362|ACTCODE==370 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|ACTCODE==211|ACTCODE==212|ACTCODE==213|ACTCODE==250 replace main28=main28*DURATION gen main29=0 replace main29=1 if ACTCODE==220 replace main29=main29*DURATION gen main30=0 replace main30=1 if ACTCODE==230|ACTCODE==240 replace main30=main30*DURATION gen main31=0 replace main31=1 if ACTCODE==260|ACTCODE==281|ACTCODE==673 replace main31=main31*DURATION gen main32=0 replace main32=1 if ACTCODE==271|ACTCODE==272|ACTCODE==282|ACTCODE==675 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|ACTCODE==671|ACTCODE==672|ACTCODE==674|ACTCODE==676|ACTCODE==677|ACTCODE==678|ACTCODE==680 replace main33=main33*DURATION gen main34=0 replace main34=1 if ACTCODE==411|ACTCODE==640 replace main34=main34*DURATION gen main35=0 gen main36=0 replace main36=1 if ACTCODE==701|ACTCODE==702 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==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 replace main40=main40*DURATION gen main41=0 replace main41=DURATION if ACTCODE==2 & PLACE>1 & PLACE<12 gen main42=0 replace main42=1 if ACTCODE==800|ACTCODE==801|ACTCODE==802|ACTCODE==803|ACTCODE==804|ACTCODE==805|ACTCODE==806|ACTCODE==807|ACTCODE==808|ACTCODE==809|ACTCODE==810|ACTCODE==813|ACTCODE==815 replace main42=main42*DURATION gen main43=0 replace main43=1 if ACTCODE==821 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|ACTCODE==173|ACTCODE==811|ACTCODE==812 replace main46=main46*DURATION gen main47=0 gen main48=0 replace main48=1 if ACTCODE==751|ACTCODE==752|ACTCODE==753|ACTCODE==780 replace main48=main48*DURATION gen main49=0 replace main49=1 if ACTCODE==950|ACTCODE==951 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 replace main51=main51*DURATION gen main52=0 replace main52=1 if ACTCODE==831|ACTCODE==850 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|ACTCODE==940|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 replace main58=main58*DURATION gen main59=0 replace main59=1 if ACTCODE==911|ACTCODE==912|ACTCODE==913|ACTCODE==914 replace main59=main59*DURATION gen main60=0 replace main60=1 if ACTCODE==862 replace main60=main60*DURATION gen main61=0 replace main61=1 if ACTCODE==863|ACTCODE==864|ACTCODE==865|ACTCODE==866|ACTCODE==867 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 |ACTCODE==02|ACTCODE==002 replace main69=main69*DURATION drop if DURATION==0 gen main=. forval i=1/69{ replace main=`i' if main`i'>0 & main`i'!=. } *core 25 categories* gen core25 =. replace core25 = 1 if main==2 | main==3 replace core25 = 2 if main==5 | main==6 replace core25 = 3 if main==1 | main==4 replace core25 = 4 if main==7 | main==8 | main==9 | main==10 | main==11 | /// main==12 | main==13 | main==14 replace core25 = 5 if main==15 | main==16 | main==17 replace core25 = 6 if main==18 | main==19 replace core25 = 7 if main==20 | main==21 | main==23 replace core25 = 8 if main==22 replace core25 = 9 if main==24 | main==25 | main==26 replace core25 = 10 if main==46 replace core25 = 11 if main==27 | main==47 replace core25 = 12 if main==32 replace core25 = 13 if main==28 | main==31 replace core25 = 14 if main==29 | main==30 replace core25 = 15 if main==34 replace core25 = 16 if main==33 replace core25 = 17 if main==63 | main==64 replace core25 = 18 if main==62 | main==65 | main==66 | main==67 | /// main==68 replace core25 = 19 if main==42 | main==43 | main==44 replace core25 = 20 if main==57 | main==58 | main==59 replace core25 = 21 if main==56 replace core25 = 22 if main==60 | main==61 replace core25 = 23 if main==35 | main==36 | main==37 | main==38 | /// main==39 | main==40 | main==41 | main==45 replace core25 = 24 if main==48 | main==49 | main==50 | main==51 | /// main==52 | main==53 | main==54 | main==55 replace core25 = 25 if main==69 *av41* gen av = . replace av = 1 if main==5 | main==7 | main==10 | main==12 | main==13 //location variable includes workplace and school together replace av = 2 if main==8 | main==14 replace av = 3 if main==9 replace av = 4 if main==15 | main==17 replace av = 5 if main==11 | main==63 | main==64 replace av = 6 if main==18 | main==19 replace av = 7 if main==20 | main==21 replace av = 8 if main==22 | main==23 | main==27 | main==32 replace av = 9 if main==46 replace av = 10 if main==24 | main==26 replace av = 11 if main==28 | main==29 | main==30 | main==31 replace av = 12 if main==66 | main==67 replace av = 13 if main==1 | main==4 replace av = 14 if main==25 replace av = 15 if main==6 replace av = 16 if main==2 | main==3 replace av = 17 if main==62 | main==65 | main==68 replace av = 18 if main==35 | main==38 | main==45 replace av = 19 if main==42 | main==44 replace av = 20 if main==36 replace av = 21 if main==43 | main==47 replace av = 22 if main==34 replace av = 23 if main==33 replace av = 24 if main==37 replace av = 25 if main==40 replace av = 27 if main==39 replace av = 29 if main==48 replace av = 30 if main==58 replace av = 31 if main==59 replace av = 32 if main==57 replace av = 33 if main==16 replace av = 34 if main==56 replace av = 36 if main==55 replace av = 37 if main==49 replace av = 38 if main==50 replace av = 39 if main==51 | main==52 | main==53 replace av = 40 if main==54 | main==60 | main==61 replace av = 41 if main==41 | main==69 **** BADCASE*** ** INOUT*** gen inout=-8 replace inout=1 if PLACE==1|PLACE==2|PLACE==3|PLACE==4|PLACE==5|PLACE==6|PLACE==7|PLACE==8|PLACE==10|PLACE==11 replace inout=2 if PLACE==9|PLACE==14|PLACE==17 replace inout=3 if PLACE==12|PLACE==13|PLACE==15|PLACE==16|PLACE==18|PLACE==19|PLACE==20|PLACE==21 * ICT * gen ict=-9 ** ELOC** gen eloc=-8 replace eloc =1 if PLACE==1 replace eloc =2 if PLACE==3 replace eloc =3 if PLACE==2 replace eloc =4 if PLACE==8 replace eloc =5 if PLACE==6| PLACE==7 replace eloc =6 if PLACE==4 replace eloc =7 if PLACE==5 replace eloc =8 if PLACE==12| PLACE==13|PLACE==14|PLACE==15|PLACE==16|PLACE==17|PLACE==18|PLACE==19|PLACE==20|PLACE==21 replace eloc =9 if PLACE==9| PLACE==10|PLACE==11 *MTRAV* gen mtrav=-8 replace mtrav=1 if PLACE==12| PLACE==13|PLACE==19 replace mtrav=2 if PLACE==15| PLACE==16|PLACE==18|PLACE==20 replace mtrav=3 if PLACE==14 replace mtrav=4 if PLACE==17 replace mtrav=5 if PLACE==21 *** ALONE*** recode ALONE (1=1)(2=0)(7/9=-8),gen(alone) ***CHILDHSD*** recode CHILDHSD (1=1)(2=0)(7/9=-8),gen(child) *** SPOUSE** recode SPOUSE (1=1)(2=0)(7/9=-8),gen(sppart) ** OAD** 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 sort RECID EPINO *destring STARTIME, gen(clockst) gen clockst=STARTIME replace clockst=clockst/100 format clockst %9.2fc rename STARMIN startmin rename ENDMIN endmin gen sec=-9 *** error in the data******* sort RECID startmin by RECID : egen number = min(startmin) gen new_START = startmin- number gen new_END = endmin -number drop startmin endmin rename new_START start rename new_END end rename EPINO epino save "C:\Users\Test\Dropbox\2005\MTUS-X\episode.dta", replace *********************************************************************************************************************************************************************************** *********************************************************************************************************************************************************************************** *********************************************************************************************************************************************************************************** *********************************************************************************************************************************************************************************** **** CANADIAN 2005***** *** BACKGROUND VARIABLES*** clear all use "C:\Users\Test\Dropbox\2005\original\data\Data Files SPSS\C19PUMFM_NUM.DTA" renvars, upper sort RECID merge 1:m RECID using "C:\Users\Test\Dropbox\2005\MTUS-X\episode.dta" drop DURSOC* drop EPI* drop ENJOYS* drop WTBS* drop WTCBS_* drop WTSBS_* gen str2 country="CA" gen survey=2005 gen swave=0 gen msamp=0 gen hldid=0 gen persid=RECID gen id=1 gen parntid1=-9 gen parntid2=-9 gen partid=-9 ** day** gen day=DDAY label variable day "Day of week diary kept" label values day DDAY tab day *** CDAY*** gen cday=-9 *** MONTH** gen month=-9 *** YEAR*** gen year=2005 *** DIARY** gen diary=1 **HHTYPE** gen hhtype=. replace hhtype=1 if LIVARR12==1 replace hhtype=1 if LIVARR12==12 & HSDSIZEC==1 replace hhtype=2 if LIVARR12==2 & HSDSIZEC==2 replace hhtype=2 if MARSTAT<=2 & HSDSIZEC==2 & LIVARR12==12 replace hhtype=3 if (LIVARR12==3|LIVARR12==4|LIVARR12==5|LIVARR12==6) & HSDSIZEC>2 replace hhtype=3 if MARSTAT<=2 & HSDSIZEC>2 & (LIVARR12==12|LIVARR12==11|LIVARR12==10) replace hhtype=4 if (LIVARR12==12 & HSDSIZEC!=1) |LIVARR12==7|LIVARR12==8|LIVARR12==9 replace hhtype=4 if LIVARR12==12|LIVARR12==11|LIVARR12==10 *** hhldsize*** gen hhldsize=HSDSIZEC ****** NCHILD**** gen nchild=0 *replace nchild=1 if CHH0014C==1 & CHRINHSDC==1 replace nchild=1 if CHR0014C==1 & CHRINHSDC==1 *replace nchild=2 if CHH0014C==2 & CHRINHSDC==2 replace nchild=2 if CHR0014C==2 & CHRINHSDC==2 *replace nchild=3 if CHH0014C==3 & CHRINHSDC==3 replace nchild=3 if CHR0014C==3 & CHRINHSDC==3 *replace nchild=4 if CHH0014C==3 & CHRINHSDC==4 replace nchild=4 if CHR0014C==3 & CHRINHSDC==4 replace nchild=nchild+1 if nchild==0 & AGECHRYC<18 *replace nchild=nchild+1 if nchild==0 & AGEHSDYC<18 replace nchild=nchild+1 if AGEGR5==1 *** agekidx*** 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=1 if AGECHRYC<=4 replace agekidx=2 if AGECHRYC>4 & AGECHRYC<13 replace agekidx=3 if AGECHRYC>12 & AGECHRYC<18 replace agekidx=4 if CHRINHSDC>0 & AGECHRYC==97/*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*/ replace agekidx=4 if nchild==1 & AGEGR5==1 recode agekidx (-5=-7) *** AGEKID2*** gen agekid2=-5 replace agekid2=AGECHRYC if AGECHRYC<18 replace agekid2=AGECHRYC if AGECHRYC>17 & AGECHRYC<=25 replace agekid2=AGECHRYC if CHRINHSDC>0 & AGECHRYC==97 recode agekid2(-5=-7) replace agekid2=60 if agekid2>60 replace agekid2=16 if nchild==1 & AGEGR5==1 ** INCOME*** gen incorig=.5 replace incorig=INCMHSD label values incorig INCMHSD recode incorig (98=-8)(99=-8) xtile quart = incorig if incorig>=0, nq(10) recode quart (1/2=1)(3/4=2)(5/6=3)(8/9=4), gen(income) recode income (.=-8) drop quart **OWNHOME** gen ownhome=. replace ownhome=1 if DWELLOWN==1 replace ownhome=2 if DWELLOWN==2 recode ownhome (.=-8) **URBAN** recode LUC_RST (1=1)(2/3=2), gen(urban) ** 1=Larger Urban Centres(CMA/CA) **2 = Rural and Small Town(non-CMA/CA) and Prince-Edward-Island ** **COMPUTER*** gen computer=-9 ***VEHICLE*** recode ACV_Q100 (1=3)(2=0)(7/9=.),gen(vehicle) recode vehicle (.=-8) **SEX** recode SEX (1=1)(2=2), gen(sex) **AGE** 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) **FAMSTAT** 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 **SINGPAR** gen singpar=0 replace singpar=1 if LIVARR12==7|LIVARR12==8|LIVARR12==9 ** RELREFP** gen relrefp=1 /*only the respondent completed the diary*/ *** CIVSTAT** gen civstat=. replace civstat=1 if MARSTAT==1|MARSTAT==2 replace civstat=2 if MARSTAT==3|MARSTAT==4|MARSTAT==5|MARSTAT==6 replace civstat=-8 if MARSTAT==9|MARSTAT==8 ** COHAB** gen cohab=-9 **CITIZEN** gen citizen=-8 replace citizen=1 if YRARRI==97 replace citizen=0 if YRARRI==10 ** This question is derived from the following ***Range of years when the respondent came to live permanently in canadA/*** *** EMPSTAT** gen empstat=LFSGSS replace empstat=4 if LFSGSS==4|LFSGSS==5 replace empstat=-8 if LFSGSS==8|LFSGSS==9 *** EMP*** gen emp =MAR_Q133 replace emp=0 if MAR_Q133==2 replace emp=-7 if MAR_Q133==7 replace emp=-8 if MAR_Q133==8|MAR_Q133==9 **** UNEMP*** gen unemp=0 replace unemp=1 if ACT7DAYS==2|ACT7DAYS==3|ACT7DAYS==4|ACT7DAYS==5|ACT7DAYS==6 replace unemp=-8 if LFSGSS>4 & (ACT7DAYS==8|ACT7DAYS==9) *** STUDENT*** gen student=0 replace student=1 if ACT7DAYS==3 replace student=-8 if (ACT7DAYS==8|ACT7DAYS==9) ***RETIRED* gen retired=0 replace retired=1 if ACT7DAYS==5 replace retired=-8 if (ACT7DAYS==8|ACT7DAYS==9) ****EMPSP** gen empsp=-8 replace empsp=-7 if civstat==2|civstat==10|civstat==12 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 *** WORKHRS** gen workhrs=WKWEHR_C replace workhrs=-7 if WKWEHR_C==97 replace workhrs=-8 if WKWEHR_C==98|WKWEHR_C==99 ** ISCO1** #delim ; gen isco1 = cond(NAICS2002_C16==10, 1, cond(NAICS2002_C16==8, 2, cond(NAICS2002_C16==9, 3, cond(NAICS2002_C16==16, 4, cond(NAICS2002_C16==11, 5, cond(NAICS2002_C16==12, 2, cond(NAICS2002_C16==13, 5, cond(NAICS2002_C16==14, 5, cond(NAICS2002_C16==15, 5, cond(NAICS2002_C16==1, 6, cond(NAICS2002_C16==2, 6, cond(NAICS2002_C16==3, 8, cond(NAICS2002_C16==4, 9, cond(NAICS2002_C16==5, 8, cond(NAICS2002_C16==6, 7, cond(NAICS2002_C16==7, 7, cond(NAICS2002_C16==97, -7, cond(NAICS2002_C16>97, -8, -8)))))))))))))))))); ** OCCUPO** rename NAICS2002_C16 occupo replace occupo=-8 if occupo==98|occupo==99 replace occupo=-7 if occupo==97 ***SECTOR*** gen sector=-9 ***EDCAT*** recode EDU10 (98/99=-8), gen(educa) label values educa EDU10 gen edcat = . replace edcat=1 if EDU10==10| EDU10==9 replace edcat=2 if EDU10==8 replace edcat=3 if EDU10==4| EDU10==3| EDU10==2|EDU10==1| EDU10==7| EDU10==6| EDU10==5 replace edcat=-8 if EDU10==98| EDU10==99 *** RUSHED*** gen rushed= TCS_Q160 replace rushed =2 if TCS_Q160 ==1 replace rushed =0 if TCS_Q160 ==2 replace rushed =-8 if TCS_Q160 ==8|TCS_Q160 ==9 **HEALTH** gen health=HAL_Q110 replace health=3 if HAL_Q110==1|HAL_Q110==2 replace health=2 if HAL_Q110==3 replace health=1 if HAL_Q110==4 replace health=0 if HAL_Q110==5 replace health=-8 if HAL_Q110==8|HAL_Q110==9 ***CARER*** gen carer=-9 **DISAB** gen disab=0 replace disab=1 if ACTLIMIT==1|SPA_Q410_C10==1 forval i = 1/41 { gen av`i' = -5 } replace av1 = main5 + main7 + main10 + main12 + main13 //location variable includes workplace and school together replace av2 = main8 + main14 replace av3 = main9 replace av4 = main15 + main17 replace av5 = main11 + main63 + main64 replace av6 = main18 + main19 replace av7 = main20 + main21 replace av8 = main22 + main23 + main27 + main32 replace av9 = main46 replace av10 = main24 + main26 replace av11 = main28 + main29 + main30 + main31 replace av12 = main66 + main67 replace av13 = main1 + main4 replace av14 = main25 replace av15 = main6 replace av16 = main2 + main3 replace av17 = main62 + main65 + main68 replace av18 = main35 + main38 + main45 replace av19 = main42 + main44 replace av20 = main36 replace av21 = main43 + main47 replace av22 = main34 replace av23 = main33 replace av24 = main37 replace av25 = main40 replace av26 = 0 replace av27 = main39 replace av28 = 0 replace av29 = main48 replace av38 = main50 replace av30 = main58 replace av31 = main59 replace av32 = main57 replace av33 = main16 replace av34 = main56 replace av35 = 0 replace av36 = main55 replace av37 = main49 replace av39 = main51 + main52 + main53 replace av40 = main54 + main60 + main61 replace av41 = main41 + main69 **** BADCASE*** *time variables - main* gen miss = av41 //missing activities gen eatdrk = av6 + av15 + av27 + av28+ av29+ av38 lab var eatdrk "Time spent on eating and drinking (basic act.)" gen trav = av5 + av12 + av17 + av19 + av21+ av9+ av24 +av18 +av29 +av19 lab var trav "Time spent on traveling or exercise(basic act.)" gen rst = av16 + av36 lab var rst "Time spent on resting/sleeping (basic act.)" gen pcare = av13 + av14 lab var pcare "Time spent on personal care (basic act.)" gen misbasic = 0 replace misbasic = misbasic + 1 if eatdrk == 0 replace misbasic = misbasic + 1 if trav== 0 replace misbasic = misbasic + 1 if rst == 0 replace misbasic = misbasic + 1 if pcare == 0 lab var misbasic "number of missing basic activities (b.a.)" *lab def misbasic *0 "No missing b.a." *1 "One missing b.a." *2 "Two missing b.a." *3 "Three missing b.a." *4 "Four missing b.a." *lab val misbasic misbasic #delimit cr *no gender or sex gen loss_sex_age=1 if sex<0 | age<0 replace loss_sex_age=0 if loss_sex_age==. rename TOTEPISO epnumx * less than 7 episode count if epnumx <7 *badcase* gen badcase = 0 replace badcase = 1 if miss>90 | epnumx<7 | misbasic >1 | loss_sex_age!=0 replace badcase = 0 if misbasic>1 & epnumx>6 & miss<91 *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 av1-av41 main1-main69 rename DURATION time ** ANIMAL*** gen animal=-9 **WHEREBORN*** rename BRTHREGC wherborn replace wherborn=-8 if wherborn==6| wherborn==8| wherborn==9 *** OCOMBWT*** rename WGHT_PER ocombwt keep country survey swave msamp hldid persid id day cday month year diary time clockst start end epnum main core25 sec av inout eloc ict mtrav alone child sppart oad animal parntid1 parntid2 partid hhtype hhldsize nchild agekidx agekid2 income ownhome urban computer vehicle sex age famstat singpar relrefp civstat cohab citizen wherborn empstat emp unemp student retired empsp workhrs isco1 sector edcat rushed health carer disab ocombwt propwt order country survey swave msamp hldid persid id day cday month year diary time clockst start end epnum main core25 sec av inout eloc ict mtrav alone child sppart oad animal parntid1 parntid2 partid hhtype hhldsize nchild agekidx agekid2 income ownhome urban computer vehicle sex age famstat singpar relrefp civstat cohab citizen wherborn empstat emp unemp student retired empsp workhrs isco1 sector edcat rushed health carer disab ocombwt propwt sort hldid persid id clockst **** ERROR IN THE ORIGINAL DATA**** ***There are some cases where episode start in number 2, becuase the total number of episode is worng** sort persid epino start replace epino=1 if (epino==2 & start==0) by persid:egen numbepisode = count (epino) drop epnumx rename numbepisode epnumx **** Adjustment in the maxi number of episode*** save "C:\Users\Test\Dropbox\2005\MTUS-X\canadian_2005\main_ca_2005.dta",replace