// Program: kr2009_mtusx.do // Task: Korean MTUS-X main and survey files // Project: MTUS-X file // Created: 07/11/2019 // Program setup ****************************************************************************** set more off set linesize 80 set varabbrev off clear all // Variables ****************************************************************************** use kr2009_sequence, clear sort col2 col3 //sort by hhid and persid //Household variables gen country = "KR" gen survey=2009 gen swave=0 //longitudinal gen msamp=0 //multiple samples gen hldid=col2 //hhid gen persid=col3 //personal id seq a, f(1) t(2) by(hldid persid)//diary identifier rename a id gen day=col5 gen cday=-9 gen month=9 gen year=2009 gen diary=0 //diary order replace diary=1 if id==1 replace diary=2 if id==2 sort hldid gen animal = -9 by hldid: gen chcount=1 if h_age<18 //age of younget child by hldid: egen nchild=count(chcount) by hldid: replace nchild=0 if nchild==. gen nchild2=nchild/2 drop nchild rename nchild2 nchild //number of child aged under 18 egen hld_tag=tag (hldid persid) //hhldsize: number of people in household egen hhldsize = sum(hld_tag), by(hldid) sort hldid by hldid: gen chage =h_age if h_age < 18 //Identify those whose ages are below 18 sort hldid chage by hldid: replace chage = chage[1] by hldid: replace chage =h_age if chage == . & (rela_h ==3|rela_h ==4) //Identify those who are children of the reference person by hldid: gen inlaw_age=1 if chage>17 & rela_h ==4 //Mark cases with in-law can be the youngest child sort hldid chage by hldid: replace chage = chage[1] sort hldid rela_h by hldid: gen parn = 1 if rela_h==6 sort hldid parn by hldid: replace parn = parn[1] sort hldid rela_h by hldid: replace chage =h_age if chage == . & rela_h == 1 & parn == 1 by hldid: egen young = min(chage) replace young = -7 if young == . gen agekid = 1 if (young>=0 & young<=4) replace agekid = 2 if (young>=5 & young<=12) replace agekid = 3 if (young>=13 & young<=17) replace agekid = 4 if young >= 18 replace agekid=-7 if young==-7 rename agekid agekidx sort hldid egen pregnant=tag(hldid) if agekidx==. tab pregnant list hldid if pregnant==1 //three households with pregnant women replace agekidx=1 if agekidx==. gen agekid2 = young //age of youngest child recode agekid2 (-1=0) gen income=-9 gen ownhome=-5 replace ownhome=1 if col8==1 replace ownhome=2 if col8==2|col8==3 replace ownhome=3 if col8==4 //household income recode empinclm (1=0)(2=25)(3=75)(4=125)(5=175)(6=225)(7=275)(8=325)(9=375) /// (10=425)(11=500), into(make_income) egen med_income=sum(make_income) if id==1, by(hldid) xtile quart = med_income, nq(4) gen income=-5 replace income=1 if quart==1 replace income=2 if quart==2|quart==3 replace income=3 if quart==4 sort hldid persid save kr2009_hh.dta, replace //Individual variables gen civstat=-5 replace civstat=1 if col14==2 replace civstat=2 if col14==1|col14==3|col14==4 replace civstat=-8 if col14==. gen sex=col11 gen age=col12 recode age (90/max=90) //cap is 90 gen relrefp=-5 replace relrefp=1 if rela_h==1 replace relrefp=2 if rela_h==2 replace relrefp=3 if rela_h==3 |rela_h==4 replace relrefp=4 if rela_h==6 replace relrefp=5 if rela_h==8 replace relrefp=9 if rela_h==5 | rela_h==7 replace relrefp=10 if rela_h==9 replace relrefp=-8 if rela_h==. *keep if id==1 //then run through for id = 2 //partid //Identify the spouse/partner of the reference person by hldid: gen spid = persid if relrefp == 2 sort hldid spid by hldid: replace spid = spid[1] if spid == . by hldid: gen refid = persid if relrefp == 1 sort hldid refid by hldid: replace refid = refid[1] if refid == . by hldid: gen partid = refid if relrefp == 2 by hldid: replace partid = spid if relrefp == 1 //Identify the spouse/partner of non-reference person by hldid: gen inlaw_m = persid if (rela_h== 4 & sex==1 & civstat!=2) by hldid: gen inlaw_f = persid if (rela_h ==4 & sex ==2 & civstat!=2) by hldid: gen ninlaw=1 if (inlaw_m!=.|inlaw_f!=.) by hldid: egen total_inlaw=count(ninlaw) by hldid: replace total_inlaw=0 if total_inlaw==. count if total_inlaw==2 & ninlaw==1 sort hldid inlaw_m inlaw_f by hldid: replace inlaw_m=inlaw_m[1] if inlaw_m==.& ninlaw==1 & total_inlaw==2 sort hldid inlaw_m inlaw_f by hldid: replace inlaw_f=inlaw_f[1] if inlaw_f==. &ninlaw==1 & total_inlaw==2 sum age if total_inlaw==2 & ninlaw==1, detail sort hldid inlaw_m inlaw_f by hldid: replace partid = inlaw_m if ninlaw==1 & total_inlaw==2 & sex==2 & partid==. & civstat!=2 sort hldid inlaw_m inlaw_f by hldid: replace partid = inlaw_f if ninlaw==1 & total_inlaw==2 & sex==1 & partid==. & civstat!=2 replace civstat=1 if partid!=. & civstat!=2 sort hldid persid by hldid: gen non=1 if h_suv!=1 & civstat!=-8 sort hldid non by hldid: replace non=non[1] if partid!=. replace partid = -8 if non==1 tab partid non if partid==-8 replace partid = -7 if partid == . replace partid = -8 if partid==-7 & civstat==1 //parntid1 & panrtid2 sort hldid by hldid: gen parntid = persid if relrefp == 4 sort hldid relrefp persid by hldid relrefp: gen parnt_no = _n if relrefp == 4 by hldid: gen parntid1 = parntid if parnt_no == 1 by hldid: gen parntid2 = parntid if parnt_no == 2 sort hldid parntid1 by hldid: replace parntid1 = parntid1[1] if parntid1 == . sort hldid parntid2 by hldid: replace parntid2 = parntid2[1] if parntid2 == . replace parntid1 = . if relrefp ~= 1 replace parntid2 = . if relrefp ~= 1 sort hldid by hldid: gen child = 1 if relrefp == 3 sort hldid child by hldid: replace child = child[1] if child == . by hldid: gen parent1 = persid if relrefp == 1 & child == 1 sort hldid parent1 by hldid: replace parent1 = parent1[1] if parent1 == . & child == 1 by hldid: gen parent2 = persid if relrefp == 2 & child == 1 sort hldid parent2 by hldid: replace parent2 = parent2[1] if parent2 == . & child == 1 replace parent1 = . if relrefp ~= 3 replace parent2 = . if relrefp ~= 3 replace parntid1 = parent1 if parntid1 == . & parent1 ~= . replace parntid2 = parent2 if parntid2 == . & parent2 ~= . sort hldid col10 by hldid: gen grandptid = persid if col10 ==7 order hldid col10 persid grandptid parntid1 parntid2 sort hldid col10 persid by hldid col10: gen grandpt_no = _n if col10 ==7 order hldid col10 persid grandptid grandpt_no parntid1 parntid2 sort hldid grandptid by hldid: replace grandptid = grandptid[1] if grandptid==. replace grandptid = . if col10 ~=6 replace parntid1=grandptid if parntid1==. & col10==6 drop grandptid grandpt_no sort hldid by hldid: gen sibling=1 if relrefp==5 sort hldid sibling by hldid: replace sibling =sibling[1] if sibling==. by hldid: gen npar=1 if (sibling==1 & relrefp==4) order hldid persid relrefp npar sibling parntid1 parntid2 sort hldid relrefp by hldid: replace parntid1= parntid1[1] if parntid1==. & relrefp==5 by hldid: replace parntid2= parntid2[1] if parntid2==. & relrefp==5 replace parntid1 = -7 if parntid1 == . replace parntid2 = -7 if parntid2 == . sort hldid by hldid: gen grandchild=1 if col10==5 sort hldid grandchild by hldid: replace grandchild=grandchild[1] if grandchild==. by hldid: gen midpar=1 if (grandchild==1 & relrefp==3) sort hldid col10 persid by hldid col10: gen midpar_no = _n if grandchild==1 & relrefp==3 by hldid: gen m_parntid = persid if grandchild==1 & relrefp == 3 by hldid: gen mparntid1=m_parntid if midpar_no==1 by hldid: gen mparntid2=m_parntid if midpar_no==2 sort hldid mparntid1 by hldid: replace mparntid1=mparntid1[1] if mparntid1==. sort hldid mparntid2 by hldid: replace mparntid2=mparntid2[1] if mparntid2==. by hldid: replace parntid1=mparntid1 if parntid1==-7 & col10==5 by hldid: replace parntid2=mparntid2 if parntid2==-7 & col10==5 order hldid persid relrefp col10 grandchild midpar_no m_parntid mparntid1 mparntid2 parntid1 parntid2 replace parntid1 = -7 if parntid1 == . replace parntid2 = -7 if parntid2 == . list hldid if col10==5 & parntid1==-7 //household type gen hhtype=-5 gen couple=1 if civstat==1 sort hldid by hldid: egen hcouple=count(couple) sort hldid by hldid: replace hhtype=1 if hhldsize==1 //single person household by hldid: replace hhtype=2 if hhldsize==2 & hcouple==2 //couple only by hldid: replace hhtype=3 if hhldsize>2 & hcouple>1 //couple + others by hldid: replace hhtype=3 if hhldsize==2 & hcouple==1 by hldid: replace hhtype=3 if hhldsize>2 & hcouple==1 replace civstat=1 if hldid==1052 & empsp==-8 & civstat==2 //correcting - dead spouse replace hhtype =2 if hldid==1052 by hldid: gen hhtype_m=1 if (hhldsize>=2 & hcouple==1) list hldid if hhldsize>=2 & hcouple==1 list hldid if h_suv!=1 & h_suv!=. & h_suv!=2 count if hhtype_m==1 egen tag=tag(hldid hhtype_m) egen count2=total(tag) tab count2 by hldid: replace hhtype=4 if hhldsize>=2 & hcouple==0 //other tab hhtype civstat, missing //famstat gen famstat=-5 replace famstat = 0 if nchild == 0 & age >= 18 & age <= 39 replace famstat = 1 if famstat ==-5 & age>= 18 & agekidx == 1 replace famstat=2 if famstat==-5 & (age>=18 & agekidx==2| agekidx==3) replace famstat=3 if famstat==-5 & nchild==0 & age>=40 replace famstat = 4 if age < 18 & famstat==-5 & ((parntid1!=-7)| (parntid2!=-7)) replace famstat = 5 if age < 18 & famstat==-5 & (parntid1==-7 & parntid2==-7) //singpar gen singpar=-5 sort hldid by hldid: gen parent=1 if relrefp == 4 //parents sort hldid child by hldid: gen child = 1 if relrefp == 3 by hldid: replace child=child[1] if child==. sort hldid parent by hldid: replace parent=1 if relrefp ==1 & child==1 by hldid: replace parent = 1 if relrefp == 2 & child == 1 by hldid : replace singpar=1 if parent==1 & (partid==-7) by hldid : replace singpar=0 if parent==.| (parent==1 & partid!=-7) tab singpar civstat if h_suv==1 replace singpar2=0 if gen singpar2=-5 replace singpar2=0 if col36!=1 & col36!=2 replace singpar2=1 if col36==1 | col36==2 gen ownhome=-5 //ownhome replace ownhome=1 if col8==1 replace ownhome=2 if col8==2|col8==3 replace ownhome=3 if col8==4 gen urban=-5 //urban replace urban=1 if col6==2 replace urban=2 if col6==1 gen computer=-9 gen vehicle=-9 gen cohab=-5 //cohabiting replace cohab=0 if col14==2 replace cohab=1 if (col14==1|col14==3|col14==4) & (partid!=-7) replace cohab=-7 if (col14==1|col14==3|col14==4) & (partid==-7) gen citizen=1 gen whereborn = -9 gen health=-9 gen carer=-9 gen disab=-9 gen workhrs=-5 replace workhrs = col24 + col25 if col24>=0 & col25>=0 //main + second jobs replace workhrs=col24 if (col24>=0 & col25<0) replace workhrs=col25 if (col24<0 & col25>=0) replace workhrs = -7 if col22==22 gen empstat=-5 replace empstat=1 if col29==1 |((col28==2|col28==3|col28==4)& workhrs>=30) replace empstat=2 if col29==2 |((col28==2|col28==3|col28==4)&(workhrs>0 & workhrs<30)) replace empstat=3 if (empstat==-5 & workhrs==0) replace empstat=4 if paidwork==2 gen emp=-5 replace emp=1 if paidwork==1 replace emp=0 if paidwork==2 gen unemp=-9 gen student=-5 replace student=1 if col16 ==2|col16==4 replace student=0 if col16 ==1 | col16==3| col16==5 replace student=0 if col16==. gen retired=0 replace retired=1 if age>59 & (empstat!=1) gen empsp=-5 sort hldid by hldid: gen spid = empstat if relrefp == 2 sort hldid spid by hldid: replace spid = spid[1] if spid == . by hldid: gen refid = empstat if relrefp == 1 sort hldid refid by hldid: replace refid = refid[1] if refid == . by hldid: replace empsp = refid if relrefp == 2 by hldid: replace empsp = spid if relrefp == 1 by hldid: gen einlaw_m = empstat if (col10 == 4 & sex==1) by hldid: gen einlaw_f = empstat if (col10==4 & sex ==2) sort hldid einlaw_m einlaw_f by hldid: replace einlaw_m=einlaw_m[1] if einlaw_m==.& ninlaw==1 & total_inlaw==2 sort hldid einlaw_m einlaw_f by hldid: replace einlaw_f=einlaw_f[1] if einlaw_f==. & ninlaw==1 & total_inlaw==2 sort hldid einlaw_m einlaw_f by hldid: replace empsp = einlaw_m if ninlaw==1 & total_inlaw==2 & sex==2 & empsp==-5 sort hldid einlaw_m einlaw_f by hldid: replace empsp = einlaw_f if ninlaw==1 & total_inlaw==2 & sex==1 & empsp==-5 replace empsp = -7 if civstat == 2 replace empsp=-8 if partid==-8 replace empsp = -7 if partid == -7 recode empsp -7 = -8 if civstat == 1 tab empsp civstat tab relrefp empsp recode occupo (0=0)(1=1)(2=2)(3=4)(4/5=5)(6=6)(7=3)(8=8)(9=9)(-7=-7), into(isco1) tab occupo isco1 gen sector =-5 replace sector=1 if col26==9 replace sector=2 if col26!=9 gen edcat=-5 replace edcat=1 if (col15>=0 & col15<=2) |(col15==3 & (col16==2|col16==4|col16==5)) replace edcat=2 if (col15==3 & (col16==1|col16==3)) |(col15==4) replace edcat=3 if (col15>=5 & col15<=7) gen rushed=-5 replace rushed=0 if (col19==3|col19==4) replace rushed=1 if (col19==2) replace rushed=2 if (col19==1) //keep only those with diaries keep if h_suv==1 keep if h_age>9 //Time variables //main activities forvalues i=39(3)468 { rename col`i' act`i' } local j=1 forvalues i=39(3)468 { rename act`i' act`j' local j=`j'+1 } //location forvalues i=40(3)469 { rename col`i' loc`i' } local j=1 forvalues i=40(3)469 { rename loc`i' loc`j' local j=`j'+1 } //with whom forvalues i=41(3)470 { rename col`i' who`i' } local j=1 forvalues i=41(3)470 { rename who`i' who`j' local j=`j'+1 } //Secondary activities forvalues i=471/614 { rename col`i' sec`i' } local j=1 forvalues i=471/614 { rename sec`i' sec`j' local j=`j'+1 } order act* sec* loc* who* //Make some changes in activities //1) missing main but second act exists forvalue i=1/144 { list hldid id if (act`i'=="S999" & sec`i'!="") } gen marker=0 forvalue i=1/144 { replace marker=1 if (act`i'=="S999" & sec`i'!="") } forvalue i=1/144 { replace act`i'=sec`i' if (act`i'=="S999" & sec`i'!="") } replace sec106="" if marker==1 //change the second to main drop marker //2) Short gap between activities forvalue i=2/144 { local k=`i'-1 local j=`i'+1 list hldid id if (act`i'=="S999" & (act`k'=="S111"|act`j'=="S111")) } forvalue i=2/144 { local k=`i'-1 local j=`i'+1 list hldid persid id if (act`i'=="S999" & (act`k'=="S111"|act`j'=="S111")) } forvalue i=2/144 { local k=`i'-1 local j=`i'+1 replace act`i'= "imp1" if (act`i'=="S999" & (act`k'=="S111"|act`j'=="S111")) /// & ((hldid==7686 & id==1)|(hldid==6434 & id==1)) } replace act127="imp1" if act128=="imp1" replace act141="imp1" if act142=="imp1" forvalue i=1/50 { list hldid persid id if act`i'=="S999" } forvalue i=100/144 { list hldid persid id if act`i'=="S999" } forvalue i=100/144 { replace act`i'="imps" if act`i'=="S999" & hldid==3199 & persid==2 & id==2 } //3) Short gap <25 before/after the travel and at home forvalue i=2/144 { local k=`i'-1 local j=`i'+1 list hldid persid id if (act`i'=="S999" & (loc`i'==1) &hldid!=4860) } keep countrya survey swave msamp hldid persid id day month year diary sex age act* /// sec* loc* who* sort hldid persid id seq a rename a unique forvalues i=1/144 { gen timeslot`i'=`i' } reshape long timeslot act sec loc who, i(unique) j(tsl) //Create time variables drop secjob sector gen epnum=-3 gen clockst=-3 gen start=-3 gen end=-3 gen main=-3 gen secx=-3 gen av==-3 gen inout=-3 gen eloc=-3 gen ict=-3 gen mtrav=-3 gen alone=-3 gen child=-3 gen sppart=-3 gen oad=-3 //create episode level to code meal at work sort unique tsl tsset unique tsl gen begin=1 if act!= act[_n-1] replace begin=1 if unique!= unique[_n-1] gen finish=1 if act!= act[_n+1] replace finish=1 if unique!= unique[_n+1] drop if begin==. & finish==. replace begin= tsl if begin==1 replace finish=tsl if finish==1 replace finish=finish[_n+1] if finish==. drop if begin==. //Main activities - imputation replace main=1 if main==-3 & act=="imp1" //personal care replace main=2 if main==-3 & (act=="S111"|act=="S112"|act=="S143") //sleep replace main=3 if main==-3 & act=="imps" replace main=4 if main==-3 & act=="S131"|act=="S132"| act=="S141"| act=="S199" replace main=5 if main==-3 & loc!=1 & (act[_n-1]==("S211")| act[_n-1]=="S212"| /// act[_n-1]=="S213"| act[_n-1]=="S214"|act[_n-1]=="S311"|act[_n-1]=="S312" /// |act[_n-1]=="S313"|act[_n-1]=="S314"|act[_n-1]=="S319") & /// (act=="S122"|act=="S1221"|act=="S1222"|act=="S123") & /// (act[_n+1]=="S211"|act[_n+1]=="S212"|act[_n+1]=="S213"|act[_n+1]=="S214"| /// act[_n+1]=="S311"|act[_n+1]=="S312" /// |act[_n+1]=="S313"|act[_n+1]=="S314"|act[_n+1]=="S319") //eating not at home replace main=5 if main==-3 & loc!=1 & (act=="S122"|act=="S1221"|act=="S1222"|act=="S123") /// & (sec=="S211"|sec=="S212"|sec=="S213"|sec=="S214"|sec=="S216" /// | sec=="S311"|sec=="S312"|sec=="S313"|sec=="S314"|sec=="S319") //eating at school or work replace main =5 if main==-3 & loc!=1 & ((sec=="S122"| sec=="S1221"|sec=="S1222"| /// sec=="S123") & (act=="S211"|act=="S212"|act=="S213" /// |act=="S214"|act=="S216" /// | act=="S311"|act=="S312"|act=="S313"| /// act=="S314"|act=="S319")) replace main=6 if main==-3 & ((act=="S121" | act=="S1221" |act=="S1222"| act=="S123")&(loc==1)) replace main=7 if main==-3 & ((act=="S211"|act=="S214"|act=="S2601"|act=="S2602") & (loc!=1)) replace main=8 if main==-3 & (act=="S215" | ((act=="S211"|act=="S214"|act=="S2601"|act=="S2602"|act=="S212"|act=="S220"|act=="S230") & (loc==1))) replace main=9 if main==-3 & ((act=="S212"|act=="S220" |act=="S230") & (loc!=1)) //no main10 replace main=11 if main==-3 & (act=="S822") replace main=12 if main==-3 & (act=="S213") replace main=13 if main==-3 & (act=="S216"| act=="S299") replace main=14 if main==-3 & (act=="S250") replace main=15 if main==-3 & (act=="S311" |act=="S312" |act=="S314"|act=="S319"|act=="S321") replace main=16 if main==-3 & (act=="S322" |act=="S313") replace main=17 if main==-3 & (act=="S329" |act=="S721"|act=="S722" |act=="S723"| act=="S724" |act=="S729"|act=="S3301"|act=="S3302") replace main=18 if main==-3 & (act=="S411"|act=="S413") replace main=19 if main==-3 & (act=="S412") replace main=20 if main==-3 & (act=="S431"|act=="S432"|act=="S433") replace main=21 if main==-3 & (act=="S421"|act=="S422"|act=="S423") replace main=22 if main==-3 & (act=="S4411"|act=="S4421") replace main=23 if main==-3 & (act=="S461"|act=="S462"|act=="S499"|act=="S4431") replace main=24 if main==-3 & (act=="S451"|act=="S452"|act=="S4531"|act=="S4532"|act=="S7801"|act=="S7802") replace main=25 if main==-3 & (act=="S133"|act=="S142") replace main=26 if main==-3 & (act=="S424"|act=="S4412"|act=="S4422"|act=="S4432"|act=="S463") //no main27 replace main=28 if main==-3 & (act=="S511"|act=="S5191"|act=="S5291"|act=="S521") replace main=29 if main==-3 & (act=="S522") replace main=30 if main==-3 & (act=="S5121"|act=="S5122") replace main=31 if main==-3 & (act=="S523"|act=="S5192"|act=="S5292") replace main=32 if main==-3 & (act=="S5301"|act=="S5309"|act=="S5401"|act=="S5409"|act=="S5501"|act=="S5509") replace main=33 if main==-3 & (act=="S6101"|act=="S6102"|act=="S6109" /// | act=="S6211"|act=="S6212"| (act>="S631" & act<="S634") |act=="S639" |act=="S919") replace main=34 if main==-3 & (act=="S741"|act=="S742"|act=="S743") //no main35 replace main=36 if main==-3 & (act=="S754") replace main=37 if main==-3 & (act=="S751"|act=="S752") replace main=38 if main==-3 & (act=="S753"|act=="S755") replace main=39 if main==-3 & (act=="S775"| ((act=="S121" |act=="S1221"|act=="S1222"|act=="S123")&(loc!=1))) replace main=40 if main==-3 & (((act=="S715"| act=="S719") & (loc!=1))) replace main=41 if main==-3 & (act=="S999" & loc!=1) replace main=42 if main==-3 & (act=="S763"|act=="S764"|act=="S766") replace main=43 if main==-3 & (act=="S761"|act=="S762") //no main44 replace main=45 if main==-3 & (act=="S765") replace main=46 if main==-3 & (act=="S240") //no main47 replace main=48 if main==-3 & (((act=="S712"|act=="S713")|((act=="S719"|act=="S715")&(loc==1)))) replace main=49 if main==-3 & (act=="S711") replace main=50 if main==-3 & (act=="S773") replace main=51 if main==-3 & (act=="S799") //no main52 and main53 replace main=54 if main==-3 & (act=="S774"|act=="S425") replace main=55 if main==-3 & (act=="S776"|act=="S777") replace main=56 if main==-3 & (act=="S771"|act=="S731"|act=="S732") replace main=57 if main==-3 & (act=="S736") replace main=58 if main==-3 & (act=="S735") replace main=59 if main==-3 & (act=="S733"|act=="S734") replace main=60 if main==-3 & (act=="S772") replace main=61 if main==-3 & (act=="S714"|act=="S7371"|act=="S7372") //no main62 replace main=63 if main==-3 & (act=="S821") replace main=64 if main==-3 & (act=="S831"|act=="S8721") replace main=65 if main==-3 & (act=="S861") replace main=66 if main==-3 & (act=="S851") replace main=67 if main==-3 & (act=="S811"|act=="S841") replace main=68 if main==-3 & (act=="S800"|act=="S871"|act=="S8722"|act=="S891") replace main=69 if main==-3 & ( act=="S999" & loc==1) //secondary actvities replace secx=2 if secx==-3 & (sec=="S111"|sec=="S112"|sec=="S143") replace secx=4 if secx==-3 & (sec=="S131"|sec=="S132"| sec=="S141"| sec=="S199") replace secx=6 if secx==-3 & (((sec=="S121" | sec=="S1221" |sec=="S1222"| sec=="S123")&(loc==1))) replace secx=7 if secx==-3 & ((sec=="S211"|sec=="S214"|sec=="S2601"|sec=="S2602") & (loc!=1)) replace secx=8 if secx==-3 & (sec=="S215" | ((sec=="S211"|sec=="S214"|sec=="S2601"|sec=="S2602"|sec=="S212"|sec=="S220"|sec=="S230") & (loc==1))) replace secx=9 if secx==-3 & (((sec=="S212"|sec=="S220" |sec=="S230") & (loc!=1))) replace secx=11 if secx==-3 & (sec=="S822") replace secx=12 if secx==-3 & (sec=="S213") replace secx=13 if secx==-3 & (sec=="S216"| sec=="S299") replace secx=14 if secx==-3 & (sec=="S250") replace secx=15 if secx==-3 & (sec=="S311" |sec=="S312" |sec=="S314"|sec=="S319"|sec=="S321") replace secx=16 if secx==-3 & (sec=="S322" |sec=="S313") replace secx=17 if secx==-3 & (sec=="S329" |sec=="S721"|sec=="S722" |sec=="S723"| sec=="S724" |sec=="S729"|sec=="S3301"|sec=="S3302") replace secx=18 if secx==-3 & (sec=="S411"|sec=="S413") replace secx=19 if secx==-3 & (sec=="S412") replace secx=20 if secx==-3 & (sec=="S431"|sec=="S432"|sec=="S433") replace secx=21 if secx==-3 & (sec=="S421"|sec=="S422"|sec=="S423") replace secx=22 if secx==-3 & (sec=="S4411"|sec=="S4421") replace secx=23 if secx==-3 & (sec=="S461"|sec=="S462"|sec=="S499"|sec=="S4431") replace secx=24 if secx==-3 & (sec=="S451"|sec=="S452"|sec=="S4531"|sec=="S4532"|sec=="S7801"|sec=="S7802") replace secx=25 if secx==-3 & (sec=="S133"|sec=="S142") replace secx=26 if secx==-3 & (sec=="S424"|sec=="S4412"|sec=="S4422"|sec=="S4432"|sec=="S463") replace secx=28 if secx==-3 & (sec=="S511"|sec=="S5191"|sec=="S5291"|sec=="S521") replace secx=29 if secx==-3 & (sec=="S522") replace secx=30 if secx==-3 & (sec=="S5121"|sec=="S5122") replace secx=31 if secx==-3 & (sec=="S523"|sec=="S5192"|sec=="S5292") replace secx=32 if secx==-3 & (sec=="S5301"|sec=="S5309"|sec=="S5401"|sec=="S5409"|sec=="S5501"|sec=="S5509") replace secx=33 if secx==-3 & (sec=="S6101"|sec=="S6102"|sec=="S6109" /// | sec=="S6211"|sec=="S6212"| (sec>="S631" & sec<="S634") |sec=="S639" |sec=="S919") replace secx=34 if secx==-3 & (sec=="S741"|sec=="S742"|sec=="S743") replace secx=36 if secx==-3 & (sec=="S754") replace secx=37 if secx==-3 & (sec=="S751"|sec=="S752") replace secx=38 if secx==-3 & (sec=="S753"|sec=="S755") replace secx=39 if secx==-3 & (sec=="S775"| ((sec=="S121" |sec=="S1221"|sec=="S1222"|sec=="S123")&(loc!=1))) replace secx=40 if secx==-3 & ((sec=="S715"| sec=="S719") & (loc!=1)) replace secx=41 if secx==-3 & (sec=="S999" & loc!=1) replace secx=42 if secx==-3 & (sec=="S763"|sec=="S764"|sec=="S766") replace secx=43 if secx==-3 & (sec=="S761"|sec=="S762") replace secx=45 if secx==-3 & (sec=="S765") replace secx=46 if secx==-3 & (sec=="S240") replace secx=48 if secx==-3 & (((sec=="S712"|sec=="S713")|((sec=="S719"|sec=="S715")&(loc==1)))) replace secx=49 if secx==-3 & sec=="S711" replace secx=50 if secx==-3 & sec=="S773" replace secx=51 if secx==-3 & sec=="S799" replace secx=54 if secx==-3 & (sec=="S774"|sec=="S425") replace secx=55 if secx==-3 & (sec=="S776"|sec=="S777") replace secx=56 if secx==-3 & (sec=="S771"|sec=="S731"|sec=="S732") replace secx=57 if secx==-3 & (sec=="S736") replace secx=58 if secx==-3 & sec=="S735" replace secx=59 if secx==-3 & (sec=="S733"|sec=="S734") replace secx=60 if secx==-3 & sec=="S772" replace secx=61 if secx==-3 & (sec=="S714"|sec=="S7371"|sec=="S7372") replace secx=63 if secx==-3 & sec=="S821" replace secx=64 if secx==-3 & (sec=="S831"|sec=="S8721") replace secx=65 if secx==-3 & sec=="S861" replace secx=66 if secx==-3 & sec=="S851" replace secx=67 if secx==-3 & (sec=="S811"|sec=="S841") replace secx=68 if secx==-3 & (sec=="S800"|sec=="S871"|sec=="S8722"|sec=="S891") replace secx=69 if secx==-3 & (sec=="S999" & loc==1) //AV -- 41 MTUS main categories replace av=1 if av==-3 & ((act=="S211"| act=="S213"| act=="S214"| act=="S2601"| act=="S2602"| act=="S216"| act=="S299") & (loc!=1)) replace av=2 if av==-3 & (((loc==1) & (act=="S211"| act=="S213"| act=="S214"| act=="S2601"| act=="S2602"| act=="S216"| act=="S299"))| act=="S215"|act=="S250") replace av=3 if av==-3 & (act=="S212"|act=="S220"|act=="S230") replace av=4 if av==-3 & (act=="S311"|act=="S312"|act=="S313"|act=="S314"|act=="S319"|act=="S321"|act=="S723"|act=="S724") replace av=5 if av==-3 & (act=="S821"|act=="S822"|act=="S831") replace av=6 if av==-3 & (act=="S411"|act=="S412"|act=="S413") replace av=7 if av==-3 & (act=="S421"|act=="S422"|act=="S423"|act=="S431"|act=="S432"|act=="S433"|act=="S499") replace av=8 if av==-3 & (act=="S4411"|act=="S4421"|act=="S4431"|act=="S461"|act=="S462"|act=="S5301"|act=="S5309"|act=="S5401"|act=="S5409"|act=="S5501"|act=="S5509"|act=="S6101"|act=="S6102"|act=="S6109") replace av=9 if av==-3 & act=="S240" replace av=10 if av==-3 & (act=="S3301"|act=="S3302"|act=="S424"|act=="S4412"|act=="S4422"|act=="S4432"|act=="S451"|act=="S452"|act=="S4531"|act=="S4532"|act=="S7801"|act=="S7802"|act=="S463") replace av=11 if av==-3 & (act=="S511"|act=="S5121"|act=="S5122"|act=="S5191"|act=="S5291"|act=="S5192"|act=="S5292"|act=="S521"|act=="S522"|act=="S523") replace av=12 if av==-3 & (act=="S811"|act=="S841"|act=="S851") replace av=13 if av==-3 & (act=="S131"|act=="S132"|act=="S199") replace av=14 if av==-3 & (act=="S133"|act=="S142"|act=="S141") replace av=15 if av==-3 & (((act=="S121"|act=="S1221"|act=="S1222"|act=="S123") & (loc==1))) replace av=16 if av==-3 &(act=="S111"|act=="S112"||act=="S143") replace av=17 if av==-3 & (act=="S800"|act=="S861"|act=="S871"|act=="S8721"|act=="S8722"|act=="S891") replace av=18 if av==-3 & (act=="S753"|act=="S755"|act=="S765") replace av=19 if av==-3 & (act=="S763"|act=="S764"|act=="S766") replace av=20 if av==-3 & act=="S754" replace av=21 if av==-3 & (act=="S761"|act=="S762") replace av=22 if av==-3 & (act=="S741"|act=="S742"|act=="S743") replace av=23 if av==-3 & (act=="S6211"|act=="S6212"|act=="S631"|act=="S632"|act=="S633"|act=="S634"|act=="S639"|act=="S919") replace av=24 if av==-3 & (act=="S751"|act=="S752") replace av=25 if av==-3 & (((act=="S715"|act=="S719") & (loc!=1))) //no av26 replace av=27 if av==-3 & act=="S775" replace av=28 if av==-3 & (((act=="S121"|act=="S1221"|act=="S1222"|act=="S123")&(loc!=1))) replace av=29 if av==-3 & ((act=="S712"|act=="S713") & loc!=1) replace av=30 if av==-3 & act=="S735" replace av=31 if av==-3 & (act=="S733"|act=="S734") replace av=32 if av==-3 & act=="S736" replace av=33 if av==-3 & (act=="S322"|act=="S329"|act=="S721"|act=="S722"|act=="S729") replace av=34 if av==-3 & act=="S771" replace av=35 if av==-3 & (act=="S731"|act=="S732") replace av=36 if av==-3 & (act=="S776"|act=="S777") replace av=37 if av==-3 & act=="S711" replace av=38 if av==-3 & (((act=="S712"|act=="S713"|act=="S719"|act=="S715")&(loc==1))) replace av=39 if av==-3 & act=="S425" replace av=40 if av==-3 & (act=="S714"|act=="S7371"|act=="S7372"|act=="S772"|act=="S773"|act=="S774"|act=="S799") replace av=41 if av==-3 & act=="S999" //core 25 categories gen core25 = -5 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 //Location replace eloc=1 if loc==1 & eloc==-3 //no eloc=2 replace eloc=3 if eloc==-3 & loc==0 & (main==7 | main==9 |main==12| main==13) replace eloc=4 if eloc==-3 & loc==0 & (act=="S311"|act=="S312"|act=="S313"|act=="S314"|act=="S319"|act=="S321") replace eloc=5 if eloc==-3 & loc==0 & (act=="S133"|act=="S142"|act=="S2601"|act=="S3301"| /// act=="S4422"|act=="S451"|act=="S452"|act=="S463"| /// act=="S7801") replace eloc=6 if eloc==-3 & loc==0 & main==39 replace eloc=7 if eloc==-3 & loc==0 & (act=="S741"|act=="S742"|act=="S743") replace eloc=8 if eloc==-3 & loc>=2 & loc<=9 replace eloc=9 if eloc==-3 //inout replace inout=3 if inout==-3& loc>=3 & loc<=9 replace inout=2 if inout==-3& (loc==2 | act=="S715"| act=="S76" | act=="S761" /// | act=="S762"| act=="S764"| act=="S765" /// | act=="S766") replace inout=1 if inout==-3 & (loc==1 | act=="S111"| act=="S112"| act=="S131" /// | act=="S132" |act=="S133"| act=="S141"|act=="S142" /// |act=="S143"|act=="S199"|act=="S215"|eloc==4 /// |main==18| main==19| main==20|main==21|main==23|main==39 /// |act=="S511"| act=="S5121"| act=="S521"| act=="S751" /// |act=="S752"| act=="S753"| act=="S741"|act=="S742"|act=="S743") replace inout=-8 if inout==-3 //mode of transportation replace mtrav=-8 if mtrav==-3& act=="S999" replace mtrav=-7 if mtrav==-3 & (loc==1|inout==1) replace mtrav=1 if mtrav==-3 & (loc==5|loc==6|loc==7) replace mtrav=2 if mtrav==-3 & (loc==3|loc==4|loc==8) replace mtrav=3 if mtrav ==-3 & ((loc==2)|(act=="S761")|(act=="S762")) replace mtrav=5 if mtrav==-3 & (loc==9) replace mtrav=-7 if mtrav==-3 & eloc!=8 //With whom //spouse present replace sppart=1 if who==2 replace sppart=0 if who!=2 replace sppart=1 if act=="S530"| act=="S5301"| act=="S5309" //child present replace child=1 if child==-3& who==3 replace child=1 if child==-3 & (act=="S511"|act=="S512"|act=="S5121"|act=="S5122"|act=="S519" /// |act=="S5191"|act=="S5192"|act=="S521"|act=="S522" /// |act=="S529"| act=="S5291"|act=="S5292") replace child=0 if child==-3 //other adult present replace oad=1 if who==4|who==5|sppart==1 replace oad=1 if act=="S540" | act=="S5401"|act=="S5409" replace oad=0 if oad==-3 //alone replace alone=1 if alone==-3 & (who==1) replace alone=0 if alone==-3 & who!=1 gen alone2=-3 replace alone2=1 if (who==1 & sppart==0 & child==0 & oad==0) replace alone2=0 if alone2==-3 rename alone alone_owndef rename alone2 alone //use of ict during activity gen ict=-3 replace ict=1 if act=="S714"|act=="S737"|act=="S7371"|act=="7372"|act=="S772"|act=="722" replace ict=0 if ict==-3 //episode number bysort unique: replace epnum=_n //clockst, start, end time replace start=(begin-1)*10 order unique tsl start end begin finish replace end=finish*10 gen cl_temp=0 replace cl_temp=start gen cl_hour=trunc(cl_temp/60) gen cl_min=((cl_temp-(cl_hour*60))*0.01) replace clockst=cl_hour+cl_min format clockst %12.2f gen time = end-start //bad case by unique: egen eatdrkt = total(time) if inlist(av, 6, 15, 27, 28, 29, 38) by unique: egen rstt = total(time) if inlist(av, 16, 36) by unique: egen pcaret = total(time) if inlist(av, 13, 14) by unique: egen eatdrk = max(eatdrkt) by unique: egen rst = max(rstt) by unique: egen pcare = max(pcaret) replace eatdrk = 0 if eatdrk ==. replace rst = 0 if rst ==. replace pcare = 0 if pcare ==. //noweight gen nowght = -5 replace nowght = 1 if main==69 & time>90 replace nowght = 1 if epnumx<7 replace nowght = 1 if (eatdrk==0 & rst==0 & pcare==0) tab nowght replace nowght=0 if nowght==-5 //original weight rename col38 ocombwt //individual weight //variables added gen region = -9 gen ethnic = -9 gen migrantd = -9 gen migrantm = -9 gen migrantf = -9 //checks tab mtrav tab inout if mtrav==-8 list main if inout==1 & mtrav==-8 list loc if inout==1 & mtrav==-8 replace mtrav=-7 if inout==1 & mtrav==-8 tab av list main if av==-3 replace av=16 if av==-3 & main==3 replace av=13 if av==-3 & main==1 replace secx=69 if secx==-3 list main if hldid==3006 & persid==3 & id==1