*****MTUS - X ****** ******Italian 2008/2009***** clear all save "C:\Users\Test\Desktop\ITALIAN\matriceusotempo2008_ind_ep_individui.dta", replace g nchild=1 if I_eta<18 g agekidx=I_eta if I_eta<18 replace agekidx=I_eta if I_eta>=18 & (I_parent_pr==6 | I_parent_pr==7 | I_parent_pr==10 | I_parent_pr==11) /*agekidx takes on values >=18 only for hh members who are son/daughter of someone in the hh*/ *the following vars will serve to map parents of someone else living in the home g id_pr=nordcomp if I_parent_pr==1 /*father/mother (RP)*/ g id_partpr=nordcomp if I_parent_pr==2 | I_parent_pr==2 /*his/her partner*/ g id_genit=nordcomp if I_parent_pr==4 /*granfather/mother*/ g id_genit_part=nordcomp if I_parent_pr==5 /*mother/father in law*/ g id_figlio=nordcomp if I_parent_pr==6 | I_parent_pr==7 /*dauther/son (if case s/he lives with their children and parents*/ g id_part_figlio=nordcomp if I_parent_pr==8 | I_parent_pr==8 /*spouse of dauther/son (if case s/he lives with their children and parents*/ g id_fratsor=nordcomp if I_parent_pr==12 /*uncle/aunt*/ g id_part_fratsor=nordcomp if I_parent_pr==14 | I_parent_pr==15 /*partner of uncle/aunt*/ g coppia=1 if I_nucleo==1 | I_nucleo==2 /*create an auxiliary variable to identify hhld where there is a couple (to be used to create hhtype)*/ collapse (sum) nchild (min) agekid2=agekidx id_pr=id_pr id_partpr=id_partpr id_genit1=id_genit id_genit_part1=id_genit_part id_figlio=id_figlio /// id_part_figlio=id_part_figlio id_fratsor=id_fratsor id_part_fratsor=id_part_fratsor (max) id_genit2=id_genit id_genit_part2=id_genit_part coppia=coppia, by(progfam) recode agekid2 (60/max=60) recode agekid2 (0/4=1 "0-4") (5/12=2 "5-12") (13/17=3 "13-17") (18/max=4 "18+"), gen(agekidx) replace agekid2=-7 if agekid2==. replace agekidx=-7 if agekidx==. merge 1:m progfam using "C:\Users\Test\Desktop\ITALIAN\matriceusotempo2008_ind_ep_individui.dta" order nchild-agekidx I_nucleo I_n_nucleo ponuc I_tipo_fam I_parent_pr, after(progfam) g hhldsize=I_ncomp g str2 country="IT" g survey=2008 g swave=0 g msamp=0 g hldid=progfam g persid=nordcomp g id=1 sort progfam I_n_nucleo ponuc g partid=nordcomp[_n+1] if ponuc==1 & (I_nucleo==1 | I_nucleo==2) & ponuc[_n+1]==2 & progfam==progfam[_n+1] & I_n_nucleo==I_n_nucleo[_n+1] replace partid=nordcomp[_n-1] if ponuc==2 & (I_nucleo==1 | I_nucleo==2) & ponuc[_n-1]==1 & progfam==progfam[_n-1] & I_n_nucleo==I_n_nucleo[_n-1] replace partid=-7 if partid==. drop _merge save "C:\Users\Test\Desktop\ITALIAN\it2008bv_prov.dta", replace g parntid1=id_pr if (I_parent_pr==6 | I_parent_pr==7) /*assign parent's id1 to children*/ g parntid2=id_partpr if (I_parent_pr==6 | I_parent_pr==7) /*assign parent's id1 to children*/ replace parntid1=id_genit1 if I_parent_pr==1 /*assign parent's id1 to children when they are RP*/ replace parntid2=id_genit2 if I_parent_pr==1 /*assign parent's id1 to children when they are RP*/ replace parntid1=id_genit_part1 if (I_parent_pr==2 | I_parent_pr==3) /*assign parent's id1 to child's spouse (mother/father in law for the the child)*/ replace parntid2=id_genit_part2 if (I_parent_pr==2 | I_parent_pr==3) /*assign parent's id2 to child's spouse (mother/father in law for the the child)*/ replace parntid1=id_figlio if (I_parent_pr==10) /*assign parent's id1 to grandchildren*/ replace parntid2=id_part_figlio if (I_parent_pr==10) /*assign parent's id1 to grandchildren*/ replace parntid1=id_fratsor if (I_parent_pr==11) /*assign parent's id1 to nephew when uncle/aunt withe their children are in the hhld*/ replace parntid2=id_part_fratsor if (I_parent_pr==11) /*assign parent's id1 to nephew when uncle/aunt withe their children are in the hhld*/ replace parntid1=id_genit1 if I_parent_pr==12 /*assign parent's id1 to child's sibling when child is RP (unclear why, but correct)*/ replace parntid2=id_genit2 if I_parent_pr==12 /*assign parent's id1 to child's sibling when child is RP (unclear why, but correct)*/ replace parntid1=id_genit_part1 if I_parent_pr==13 /*assign parent's id1 to child's sibling when child is RP (unclear why, but correct)*/ replace parntid2=id_genit_part2 if I_parent_pr==13 /*assign parent's id1 to child's sibling when child is RP (unclear why, but correct)*/ replace parntid1=-7 if parntid1==. replace parntid2=-7 if parntid2==. | parntid2==parntid1 replace parntid1=parntid2 if parntid2!=. & parntid2!=-7 & parntid1==-7 g parntid1p=parntid1 if parntid1>parntid2 & parntid2!=-7 /*code to assign lower parnt id on parntid1*/ g parntid2p=parntid2 if parntid1>parntid2 & parntid2!=-7 /*code to assignlower parnt id on parntid1*/ replace parntid1=parntid2p if parntid1p>parntid2p & parntid2p!=-7 /*code to assign lower parnt id on parntid1*/ replace parntid2=parntid1p if parntid1p>parntid2p & parntid2p!=-7 /*code to assign lower parnt id on parntid1*/ *replace "by hand" 1 case not findable with previous code replace parntid1=5 if progfam==4719 & nordcomp==6 drop parntid1p parntid2p tab parntid1 parntid2 /*9 cases to check for same parntid*/ replace parntid2=-7 if parntid1==parntid2 & parntid1!=-7 & parntid2!=-7 /*8 are newphes of RP living with one parent in RP hhld*/ replace parntid1=5 if progfam==11621 & nordcomp==7 /*1 case corrected; it's a nephew of RP living with both parents in RP hhld*/ /* There are 42 cases of grandchildren to whom parents's id cannot be assigned because actually they don't live with their parents, but with their granparents; most of them are adult (18+) There are 23 cases of nephews (children of brother or sister of the reference person) to whom parents's id cannot be assigned because actually they don't live with their parents; 8 of them are under 18 years*/ g hhtype=1 if I_ncomp==1 /*variable I_comp records number of people in household (=hhld size)*/ replace hhtype=2 if I_ncomp==2 & I_nucleo==2 & coppia==1/*var I_nucleo identify types of nuclear families 2=couple with no children*/ replace hhtype=3 if I_ncomp>2 & coppia==1 /*hhldsize>2 and presence of a couple within hhld*/ replace hhtype=4 if I_ncomp>=2 & coppia!=1 /*hhldsize>=2 and NO couples within hhld*/ g incorig=-9 /*no available income variable in ISTAT file, altough the question was asked*/ g income=-9 /*no available income variable in ISTAT file, altough the question was asked*/ recode F_titgodab (2=1 "own") (1=2 "rent") (3/5=3 "other arrangement"), gen(ownhome) recode I_amp_centro (1 2 5 6=1 "Urban/suburban") (3 4=2 "rural/semi-rural"), gen(urban) *Urban/rural cannot be defined on the grounds of size of municipality only; I coded as urban municipalities classified as "metropolitan city" and their suburbs *and municipalities with more than 10K inhabitants. I classified the remainder (mun. with less than 10K) as rural. g computer=F_computer==2 | F_internet==4 g vehicle=0 if F_auto==3 & F_motorino==7 & F_moto==1 egen nvehicle=rowmin(F_n_motorino F_n_moto F_n_auto) replace vehicle=3 if nvehicle==1 replace vehicle=4 if nvehicle>1 & nvehicle<. recode I_sesso (1=1 "man") (2=2 "woman"), gen(sex) recode I_eta (90/max=90), gen(age) g famstat=0 if I_eta>=18 & I_eta<=39 & (agekidx==-7 | agekidx==4) replace famstat=1 if I_eta>=18 & agekidx==1 replace famstat=2 if I_eta>=18 & (agekidx==2 | agekidx==3) replace famstat=3 if I_eta>=40 & (agekidx==-7 | agekidx==4) replace famstat=4 if I_eta<18 & (I_parent_pr==6 | I_parent_pr==7 | I_parent_pr==10 | I_parent_pr==11) /*child<18 classified as child or nephew or grandchild of the reference person of the hhld*/ replace famstat=5 if I_eta<18 & (I_parent_pr!=6 & I_parent_pr!=7 & I_parent_pr!=10 & I_parent_pr!=11) g singpar=((I_nucleo==3 | I_nucleo==4) & ponuc==1) recode I_parent_pr (1=1 "Person 1") (2 3=2 "Spouse/ common-law partner") (6 7=3 "Child") (4=4 "Parent") (5=7 "Father/Mother-in-law") (12=5 "Sibling") /// (8 9=6 "Son/Daughter-in-law") (13 14 15=8 "Brother/Sister-in-law") (16 10 11=9 "Other relative") (17=10 "Not related"), gen(relrefp) g civstat=(I_nucleo==1 | I_nucleo==2) & (ponuc==1 | ponuc==2) replace civstat=2 if civstat==0 g cohab=civstat==1 & I_stat_civ!=2 /*I_stat_civ records individual civil status (2=married)*/ replace cohab=-7 if civstat==2 g citizen=I_cittadinanza==1 g empstat=1 if I_temp_lav==1 replace empstat=2 if I_temp_lav==2 replace empstat=4 if I_cond_prof!=1 *it is not possible to distinguish student or unemployed working at least some hours g emp=empstat<4 g unemployed=I_cond_prof==2 | I_cond_prof==3 g student=I_formazione!=1 /*notice that the question on school enrolment refers to the current academic year or the one just finished, so there can be cases of diarists classified as students (if the question was asked during summer holiday), although they are not currently students and are instead employed or unemployed (looking for a job) notice also that most children aged 3 years + are classified as student*/ g retired=I_cond_prof==7 /*information on retirement is derived from a variable about current main or unique employment status, it cannot distinguish between working and non-working retired people*/ g empsp_m=empstat if civstat==1 & I_sesso==1 g empsp_f=empstat if civstat==1 & I_sesso==2 save "C:\Users\Test\Desktop\ITALIAN\it2008bv_prov.dta", replace collapse empsp_m=empsp_m empsp_f=empsp_f, by(progfam I_n_nucleo) merge 1:m progfam I_n_nucleo using "C:\Users\Test\Desktop\ITALIAN\it2008bv_prov.dta" sort progfam nordcomp g empsp=empsp_m if civstat==1 & I_sesso==2 replace empsp=empsp_f if civstat==1 & I_sesso==1 replace empsp=-7 if civstat==2 drop empsp_m empsp_f g workhrs=I_ALTR_LAV_ore /*whorkhrs takes on values from question on reported usual work hours*/ replace workhrs=-8 if I_ALTR_LAV_altro==8 | I_ALTR_LAV_altro==9 replace workhrs=-7 if I_cond_prof!=1 g empinclm=-9 g occupo=I_cod_prof_ISTAT /*NOTE: 14=managers of firms of unknown size*/ replace occupo=-7 if I_cond_prof!=1 replace occupo=-8 if occupo==. & I_cond_prof==1 *Label in Italian in a separate file; *only employed people; no codes for past job (only aggregate categories in separate variable; do not allow even 1-digit classification of manual occupations) /*the Italian classification of occupation 2001 (the one used at that time, now updated in 2011) is very similar to the isco08, but data are provided only at 2 digit, so it is not possible to use the exact conversion table provided by ISTAT which works only with 4-digit codes. A few miscodings are possible, although should be rare */ replace occupo=101 if I_ULTLAV_POSPROF_DIP==1 replace occupo=102 if I_ULTLAV_POSPROF_DIP==2 replace occupo=103 if I_ULTLAV_POSPROF_DIP==3 replace occupo=104 if I_ULTLAV_POSPROF_DIP==4 replace occupo=105 if I_ULTLAV_POSPROF_DIP==5 replace occupo=106 if I_ULTLAV_POSPROF_DIP==6 replace occupo=107 if I_ULTLAV_POSPROF_DIP==7 replace occupo=108 if I_ULTLAV_POSPROF_DIP==8 replace occupo=112 if I_ULTLAV_POS_OCC==2 replace occupo=113 if I_ULTLAV_POS_OCC==3 replace occupo=114 if I_ULTLAV_POS_OCC==4 replace occupo=115 if I_ULTLAV_POS_OCC==5 replace occupo=116 if I_ULTLAV_POS_OCC==6 replace occupo=117 if I_ULTLAV_POS_OCC==7 replace occupo=118 if I_ULTLAV_POS_OCC==8 recode occupo (90=0 "Armed forces occupations") (1 11 12 13 14 101 114=1 "Managers, senior officials and legislators") (21/26 103 104 115=2 "Professionals") /// (3 31/34=3 "Technicians and associate professionals") (4 41 42 102 105=4 "Clerical workers") (5 51/55=5 "Service and sales workers") /// (64=6 "Skilled agricultural, fishery and forestry workers") (6 61 62 63 65 66=7 "Craft and related trade workers") (7 71/74=8 "Plant and machine operators and assemblers") /// (8 81/86 106 107 108=9 "Elementary occupations"), gen(isco1) replace isco1=6 if occupo>=116 & occupo<=118 & I_ULTLAV_ATECO==1 /*self-employed in primary sector go into isco1=6*/ replace isco1=5 if occupo>=116 & occupo<=118 & (I_ULTLAV_ATECO==5 | I_ULTLAV_ATECO==6) /*self-employed in sales or restaurant sector go into isco1=5*/ replace isco1=7 if occupo>=116 & occupo<=118 & (I_ULTLAV_ATECO>=2 & I_ULTLAV_ATECO<=4) /*self-employed in industry, construction and extraction sector go into isco1=7*/ replace isco1=4 if occupo>=116 & occupo<=118 & (I_ULTLAV_ATECO>6 & I_ULTLAV_ATECO<.) & I_tit_stud<6 /*self-employed in other sector go into isco1=4 if they have tertiary education*/ replace isco1=7 if occupo>=116 & occupo<=118 & (I_ULTLAV_ATECO==7) & I_tit_stud>=6 /*self-employed in trasport and communication go into isco1=7 if they have less than tertiary education (they might be mostly truck drivers)*/ replace isco1=9 if occupo>=116 & occupo<=118 & (I_ULTLAV_ATECO>7 & I_ULTLAV_ATECO<.) & I_tit_stud>=6 /*self-employed with less than tertiary education in other sector (also other than transport) are almost impossibile to classify at 1 digit; I coded them as 9 (elementary occ.)*/ replace isco1=4 if (occupo==112 | occupo==113) & I_tit_stud>=6 /*atypical employees coded as isco1=4 if they have tertiary education*/ replace isco1=5 if (occupo==112 | occupo==113) & I_tit_stud<6 & (I_ULTLAV_ATECO==5 | I_ULTLAV_ATECO==6) /*atypical employees coded as isco1=5 if they have less than tertiary education & worked in sales or restaurant sector*/ replace isco1=9 if (occupo==112 | occupo==113) & I_tit_stud<6 & (I_ULTLAV_ATECO!=5 & I_ULTLAV_ATECO!=6) /*atypical employees coded as isco1=9 if they have less than tertiary education & did not work in sales or restaurant sector*/ g sector=1 if I_sett_ateco==10 | I_pubb_priv==1 replace sector=2 if I_sett_ateco!=10 & I_sett_ateco<. replace sector=-7 if I_cond_prof!=1 replace sector=-8 if I_sett_ateco==. & I_cond_prof==1 g educa=I_tit_stud /*original level of education variable; labels in separate file*/ replace educa=-7 if educa==. /*children under 6 are not asked the level of education (although they can be considered as "students"*/ recode educa (9/12=1 "uncompleted secondary or less") (6/8=2 "completed secondary") (1/5=3 "above secondary") , gen(edcat) recode D_stress (1 2=2 "Often") (3=1 "Sometimes") (4=0 "Almost never") (.=-8), gen(rushed) replace rushed=-7 if age<15 *The original question is "Generally, do feel stressed?" recode D_cond_sal (1=3 "Very good") (2=2 "Good") (3=1 "Fair") (4 5=0 "Poor"), gen(health) replace health=-7 if age<3 *The original question is "In general, how is your health?". Answers on 1-Very good to 5-Very bad scale (with intermediate labelled points) g carer=-9 recode D_limitazioni (1=1 "Yes") (2 3=0 "No") (.=-8), gen(disab) replace disab=-7 if age<3 /*The original question is : "Do you have limitations in daily activities because of health problems lasting at least 6 months?" 1=Yes, severe limitations 2=Yes, not serious limitations 3=No limitations"*/ drop _merge sort hldid persid gen animal=F_animali * 1=no, 2=yes* gen wherborn=-9 egen persid2 = concat(hldid persid) destring persid2, replace save "C:\Users\Test\Desktop\ITALIAN\it2008bv_prov.dta", replace ************************************************* clear all *importing time diaries in Stata from ISTAT file (text data), B file (containing size of municipality and geographical area)* /// using "C:\Users\Test\Desktop\ITALIAN\tus08.fs_sk8a" *variable labels lab var ril "survey number" lab var annoril "survey year" lab var trim "quarter" lab var progfam "household id" lab var nordcomp "person id" lab var gg "calendar day of diary" lab var mm "calendar month of diary" lab var aa "calendar year of diary" lab var gsett "day of week" lab var prog_ep "episode number" lab var oraini "start hour" lab var minini "start minute" lab var orafine "end hour" lab var orafine "end minute" lab var attprin "main activity code (string var)" lab var attsec "secondary activity code (string var)" lab var luogo "location/ mode of transport code" lab var solo "alone" lab var madre "with mother" lab var padre "with father" lab var partner "with partner" lab var figlio "with child" lab var fratello "with sibling" lab var altri "with known others" lab var cod_aus "with whom auxiliary code" save "C:\Users\Test\Desktop\ITALIAN\tus08.fs_sk8b.dta", replace use "C:\Users\Test\Desktop\ITALIAN\tus08.fs_sk8b.dta", clear /*original ISTAT data file*/ sort progfam nordcomp prog_ep /*sort by hldid persid epnum*/ ****generating time variables****** replace orafine=0 if orafine==24 /*1 episode ending at midnight was mistakenly coded "24.00" instead of "0.00"*/ g p_start=oraini*60+minini /*provisional start variable*/ g p_end=orafine*60+minfine /*provisional end variable*/ g start=oraini*60+minini g end=orafine*60+minfine replace end=end+1440 if endprog_ep[_n-1] /*add 1440 min to episodes ending after midnight*/ replace end=end+1440 if end[_n]prog_ep[_n-1] /*add 1440 min to episodes ending after midnight*/ replace start=start-240 /*subtract 240 minutes from all episodes (since diary starts at 4 am)*/ replace end=end-240 /*subtract 240 minutes from all episodes (since diary starts at 4 am)*/ drop p_start p_end g time=end-start g clockst=oraini+minini/100 /*note that this variable is not formatted in stata time format*/ format clockst %9.2f g epnum=prog_ep ****harmonization of activity codes (see excel file) *main activity g main=. replace main=2 if attprin=="011" | attprin=="012" replace main=4 if attprin=="031" | attprin=="039" | attprin=="0391" replace main=5 if substr(attprin,1,3)=="021" & (luogo==16 | luogo==17) replace main=6 if substr(attprin,1,3)=="021" & (luogo!=16 & luogo!=17 & luogo!=20 & luogo!=21 & luogo!=22) replace main=7 if (attprin=="11" | attprin=="111") & (luogo!=11 & luogo!=12 & luogo!=13) replace main=8 if (attprin=="11" | attprin=="111" | attprin=="121") & (luogo==11 | luogo==12 | luogo==13) replace main=8 if attprin=="132" replace main=9 if attprin=="121" & (luogo!=11 & luogo!=12 & luogo!=13) replace main=11 if attprin=="9011" | attprin=="9012" replace main=12 if attprin=="112" | attprin=="122" replace main=13 if attprin=="139" replace main=14 if attprin=="1391" replace main=15 if attprin=="211" | attprin=="219" replace main=16 if attprin=="212" | attprin=="2121" | attprin=="2122" replace main=17 if substr(attprin,1,2)=="22" replace main=18 if attprin=="311" | attprin=="319" replace main=19 if attprin=="312" | attprin=="3121" replace main=20 if substr(attprin,1,2)=="32" & attprin!="323" replace main=21 if substr(attprin,1,2)=="33" replace main=22 if substr(attprin,1,2)=="35" | attprin=="323" | attprin=="342" replace main=23 if attprin=="371" | attprin=="372" replace main=24 if attprin=="361" | attprin=="3611" replace main=25 if attprin=="3641" | attprin=="3642" replace main=26 if attprin=="362" | attprin=="3621" | attprin=="365" | attprin=="363" | attprin=="3631" | attprin=="369" replace main=27 if attprin=="343" | attprin=="734" replace main=28 if attprin=="381" | attprin=="3811" | attprin=="427" | attprin=="4271" replace main=29 if attprin=="382" replace main=30 if attprin=="383" | attprin=="3831" | attprin=="3832" replace main=31 if attprin=="3812" | attprin=="384" | attprin=="389" replace main=32 if substr(attprin,1,2)=="39" | (substr(attprin,1,2)=="42" & attprin!="427" & attprin!="4271") replace main=33 if attprin=="411" | attprin=="4111" | attprin=="995" | attprin=="431" | attprin=="439" replace main=34 if substr(attprin,1,3)=="432" replace main=35 if attprin=="529" | attprin=="517" | attprin=="519" replace main=36 if attprin=="525" replace main=37 if attprin=="521" | attprin=="522" replace main=38 if attprin=="523" | attprin=="524" replace main=39 if substr(attprin,1,3)=="021" & (luogo==20 | luogo==21 | luogo==22) replace main=40 if attprin=="513" replace main=41 if (attprin=="997" | attprin=="999") & luogo==44 /*1 episode with no activity but place other than home specified*/ replace main=42 if attprin=="6132" | attprin=="614" | attprin=="6141" | attprin=="6142" | attprin=="6143" | attprin=="613" | attprin=="6149" /// | attprin=="615" | attprin=="616" | attprin=="6161" | attprin=="617" | attprin=="6162" | attprin=="619" | attprin=="736" | attprin=="7361" | attprin=="7362" replace main=43 if attprin=="611" | attprin=="6111" | attprin=="612" replace main=44 if attprin=="6131" replace main=45 if attprin=="631" replace main=46 if attprin=="341" | attprin=="3411" | attprin=="3412" | attprin=="621" | attprin=="349" replace main=47 if attprin=="344" replace main=48 if substr(attprin,1,3)=="512" replace main=49 if attprin=="511" | attprin=="514" | attprin=="5141" | attprin=="5142" | attprin=="5143" | attprin=="516" | substr(attprin,1,3)=="515" replace main=50 if attprin=="731" | attprin=="732" | attprin=="739" replace main=52 if attprin=="711" | attprin=="7111" | attprin=="735" | attprin=="7351" replace main=53 if attprin=="713" replace main=54 if attprin=="712" | attprin=="719" | attprin=="7191" replace main=55 if attprin=="531" | attprin=="532" | attprin=="533" replace main=56 if substr(attprin,1,2)=="81" replace main=57 if attprin=="831" | attprin=="714" replace main=58 if attprin=="8311" | attprin=="832" replace main=59 if substr(attprin,1,2)=="82" replace main=60 if substr(attprin,1,3)=="733" replace main=61 if substr(attprin,1,2)=="72" replace main=63 if attprin=="9013" | attprin=="901" replace main=64 if substr(attprin,1,3)=="902" replace main=65 if substr(attprin,1,3)=="904" replace main=66 if attprin=="9038" | attprin=="9039" replace main=67 if attprin=="900" | attprin=="903" | attprin=="9031" | attprin=="9036" replace main=68 if attprin=="905" | attprin=="9051" | attprin=="907" | attprin=="9081" | attprin=="9082" | substr(attprin,1,3)=="909" | attprin=="90" replace main=69 if (attprin=="997" | attprin=="999") & luogo!=44 *secondary activity *a few of these lines do not change anything because certain secondary activity actually were not recorded g sec=. replace sec=5 if attsec=="131" /*code 131 was added as secondary activity only by ISTAT coders for episodes where diarist recorded a lunch break at work */ replace sec=2 if attsec=="011" | attsec=="012" replace sec=4 if attsec=="031" | attsec=="039" | attsec=="0391" replace sec=5 if substr(attsec,1,3)=="021" & (luogo==16 | luogo==17) replace sec=6 if substr(attsec,1,3)=="021" & (luogo!=16 & luogo!=17 & luogo!=20 & luogo!=21 & luogo!=22) replace sec=6 if attsec=="0222" /*code 0222 does not exist in ISTAT codebook (1 episode); it is likely a mistake for 0212 (snacks) but diarist is at a bar and main act. is conversation with friends*/ replace sec=7 if (attsec=="11" | attsec=="111") & (luogo!=11 & luogo!=12 & luogo!=13) replace sec=8 if (attsec=="11" | attsec=="111" | attsec=="121") & (luogo==11 | luogo==12 | luogo==13) replace sec=8 if attsec=="132" replace sec=9 if attsec=="121" & (luogo!=11 & luogo!=12 & luogo!=13) replace sec=11 if attsec=="9011" | attsec=="9012" replace sec=12 if attsec=="112" | attsec=="122" replace sec=13 if attsec=="139" replace sec=14 if attsec=="1391" replace sec=15 if attsec=="211" | attsec=="219" replace sec=16 if attsec=="212" | attsec=="2121" | attsec=="2122" replace sec=17 if substr(attsec,1,2)=="22" replace sec=18 if attsec=="311" | attsec=="319" replace sec=19 if attsec=="312" | attsec=="3121" replace sec=20 if substr(attsec,1,2)=="32" & attsec!="323" replace sec=21 if substr(attsec,1,2)=="33" replace sec=22 if substr(attsec,1,2)=="35" | attsec=="323" | attsec=="342" replace sec=23 if attsec=="371" | attsec=="372" replace sec=24 if attsec=="361" | attsec=="3611" replace sec=25 if attsec=="3641" | attsec=="3642" replace sec=26 if attsec=="362" | attsec=="3621" | attsec=="365" | attsec=="363" | attsec=="3631" | attsec=="369" replace sec=27 if attsec=="343" | attsec=="734" replace sec=28 if attsec=="381" | attsec=="3811" | attsec=="427" | attsec=="4271" replace sec=29 if attsec=="382" replace sec=30 if attsec=="383" | attsec=="3831" | attsec=="3832" replace sec=31 if attsec=="3812" | attsec=="384" | attsec=="389" replace sec=32 if substr(attsec,1,2)=="39" | (substr(attsec,1,2)=="42" & attsec!="427" & attsec!="4271") replace sec=33 if attsec=="411" | attsec=="4111" | attsec=="995" | attsec=="431" | attsec=="439" replace sec=34 if substr(attsec,1,3)=="432" replace sec=35 if attsec=="529" | attsec=="517" | attsec=="519" replace sec=36 if attsec=="525" replace sec=37 if attsec=="521" | attsec=="522" replace sec=38 if attsec=="523" | attsec=="524" replace sec=39 if substr(attsec,1,3)=="021" & (luogo==20 | luogo==21 | luogo==22) replace sec=40 if attsec=="513" replace sec=42 if attsec=="6132" | attsec=="614" | attsec=="6141" | attsec=="6142" | attsec=="6143" | attsec=="613" | attsec=="6149" /// | attsec=="615" | attsec=="616" | attsec=="6161" | attsec=="617" | attsec=="6162" | attsec=="619" | attsec=="736" | attsec=="7361" | attsec=="7362" replace sec=43 if attsec=="611" | attsec=="6111" | attsec=="612" replace sec=44 if attsec=="6131" replace sec=45 if attsec=="631" replace sec=46 if attsec=="341" | attsec=="3411" | attsec=="3412" | attsec=="621" | attsec=="349" replace sec=47 if attsec=="344" replace sec=48 if substr(attsec,1,3)=="512" replace sec=49 if attsec=="511" | attsec=="514" | attsec=="5141" | attsec=="5142" | attsec=="5143" | attsec=="516" | substr(attsec,1,3)=="515" replace sec=50 if attsec=="731" | attsec=="732" | attsec=="739" replace sec=52 if attsec=="711" | attsec=="7111" | attsec=="735" | attsec=="7351" replace sec=53 if attsec=="713" replace sec=54 if attsec=="712" | attsec=="719" | attsec=="7191" replace sec=55 if attsec=="531" | attsec=="532" | attsec=="533" replace sec=56 if substr(attsec,1,2)=="81" replace sec=57 if attsec=="831" | attsec=="714" replace sec=58 if attsec=="8311" | attsec=="832" replace sec=59 if substr(attsec,1,2)=="82" replace sec=60 if substr(attsec,1,3)=="733" replace sec=61 if substr(attsec,1,2)=="72" replace sec=43 if substr(attprin,1,2)=="90" & luogo==50 & attsec=="" /*42419 changes made*/ replace sec=44 if substr(attprin,1,2)=="90" & luogo==51 & attsec=="" /*3296 changes made*/ replace sec=69 if sec==. & attsec=="" ***INOUT g inout=. g p_in=1 if luogo==11 | luogo==14 | (luogo>=17 & luogo<=24) | (luogo>=26 & luogo<=29) | luogo==31 | luogo==33 | luogo==34 | /// (luogo>=36 & luogo<=39) | luogo==44 /*provisional variable to indicate inside places*/ replace inout=-8 if luogo==99 replace inout=3 if luogo==53 | luogo==54 | (luogo>=56 & luogo<=63) | luogo==98 replace inout=2 if luogo==12 | luogo==25 | luogo==30 | luogo==32 | luogo==35 | (luogo>=40 & luogo<=43) | luogo==45 replace inout=2 if luogo>=50 & luogo<=52 | luogo==55 /*on foot, by bike, by motobike, by boat*/ replace inout=2 if luogo==37 & (attprin=="6141" | attprin=="7361" | attprin=="7362") replace inout=2 if (main>=42 & main<=47) & p_in!=1 replace inout=1 if inout==. drop p_in ***ELOC g eloc=. replace eloc=-8 if luogo==99 replace eloc=1 if luogo>=11 & luogo<=13 replace eloc=2 if luogo==14 replace eloc=3 if luogo==16 replace eloc=4 if luogo==17 | luogo==19 replace eloc=5 if luogo==15 | (luogo>=23 & luogo<=28) replace eloc=6 if luogo>=20 & luogo<=22 replace eloc=7 if luogo==38 replace eloc=8 if (luogo>=50 & luogo<=63) | luogo==98 replace eloc=9 if luogo==18 | (luogo>=29 & luogo<=49 & luogo!=38) ***ICT g ict=0 replace ict=1 if attprin=="2122" | attprin=="2221" | attprin=="223" | attprin=="3621" | attprin=="3631" | attprin=="372" /// | attprin=="4111" | attprin=="5141" | attprin=="5142" | attprin=="5143" | attprin=="7111" | attprin=="7191" | substr(attprin,1,2)=="72" /// | substr(attprin,1,3)=="733" | attprin=="7351" | attprin=="8111" | attprin=="8121" | attprin=="8131" | attprin=="8191" /// | substr(attprin,1,3)=="822" | attprin=="832" ***MTRAV g mtrav=-8 if luogo==97 | luogo==99 replace mtrav=-7 if luogo<=49 replace mtrav=1 if (luogo>=52 & luogo<=54) | luogo==57 replace mtrav=2 if luogo>=58 & luogo<=63 replace mtrav=3 if luogo==50 replace mtrav=3 if luogo==45 & main==43 replace mtrav=4 if luogo==51 | luogo==55 | luogo==56 replace mtrav=5 if luogo==98 ***WITH WHOM VARIABLES g alone=solo==1 g child=figlio==5 /*no straightforward way to distinguish children<18 from children>=18*/ g sppart=partner==4 /*MUST BE SET TO -7 for cases unmarried or not cohabiting (SEE BELOW)*/ g oad=madre==2 | padre==3 | partner==4 | altri==7 /*for children's diaries "others" may be also same age friends; not includes siblings because in most cases would not be adults*/ 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 *av41* gen av = -5 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 /*merge age sex type of household and position within household of diarist*/ merge m:1 progfam nordcomp using "C:\Users\Test\Desktop\ITALIAN\matriceusotempo2008_ind_ep_individui.dta" /// drop if _merge==2 drop _merge replace sppart=-7 if (I_nucleo!=1 & I_nucleo!=2) | ponuc==0 | ponuc==3 ***BADCASE IDENTIFICATION su I_eta I_sesso *no diary with missing sex or age drop ponuc I_nucleo save "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov.dta", replace /*provisional version*/ g misstime=time if attprin=="997" | attprin=="999" g eatdrink=1 if substr(attprin,1,2)=="02" | substr(attsec,1,2)=="02" | attprin=="311" | attprin=="3121" | attprin=="513" | luogo==20 | luogo==21 /*no specific code for "buy food"*/ g sleeprest=1 if substr(attprin,1,2)=="01" | substr(attprin,1,2)=="53" | (attprin=="112" & substr(attsec,1,2)=="53") g personal=1 if substr(attprin,1,2)=="03" | substr(attprin,1,3)=="364" g exertrav=1 if substr(attprin,1,2)=="90" | (main>=42 & main<=47) g carer=time if (main>=28 & main<=32) | (sec>=28 & sec<=32) /*this is to identify exception 3*/ g athome=time if eloc==1 /*this is to identify exception 4*/ g atahome=time if eloc==2 /*this is to identify exception 4*/ collapse (sum) misstime=misstime eatdrink=eatdrink sleeprest=sleeprest personal=personal carer=carer athome=athome /// atahome=atahome exertrav=exertrav total=time (max) totep=prog_ep, by(progfam nordcomp) tab misstime /*3 diaries with more than 90' missing time*/ tab totep /*9 diaries with less than 7 episodes*/ g badcase=misstime>90 | totep<7 g m_eatdrink=eatdrink==0 /*flag for missing eatdrink*/ g m_sleeprest=sleeprest==0 /*flag for missing sleeprest*/ g m_personal=personal==0 /*flag for missing personal*/ g m_exertrav=exertrav==0 /*flag for missing exertrav*/ tab1 m_* egen missbasic=rowtotal(m_*) tab missbasic /*165 diaries missing 2 or more basic activities, BEFORE finding exceptions*/ tab missbasic badcase if totep<15 /*112 counts out 165 must be checked for exceptions because the remainder has 15+ episodes or are already flagged as badcase according to misstime or totep variables*/ g tocheck=missbasic==2 & totep<15 & badcase==0 /*flag for diaries to check for exceptions to the basic activity rule*/ tab tocheck if carer>0 /*7 diaries can be flagged as "carer", so they are not bad (except. 3)*/ replace tocheck=0 if tocheck==1 & carer>0 tab totep if tocheck==1 & (athome==1440 | atahome>=1000) /*43 diaries can be flagged at home with at least 12 episodes (exc. 4)*/ replace tocheck=0 if tocheck==1 & (athome==1440 | atahome>=1000) & totep>=12 *62 remaining diaries to check for expceptions 1-2 drop eatdrink - total merge 1:m progfam nordcomp using "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov.dta" /*merge variables with diaries*/ drop if tocheck==0 /*keep only diaries to check*/ sort progfam nordcomp prog_ep *all diaries to check but 2 have missing personal care *create a flag for diary starting with sleep (2h+) followed by another activity that is not personal care *for the 60 diaries with missing personal care g unreppers=1 if prog_ep==1 & substr(attprin,1,2)=="01" & time>=120 & m_personal==1 & substr(attprin[_n+1],1,2)!="01" tab unreppers /*51 diaries have unreported personal care *I checked the remaining 9 (60-51) by hand and found that, although not chatched by the unreppers flag, *they are still to be flagged as unreported personal care. Here's their household and person ids: 907 1 4053 3 6578 1 9653 3 14539 4 15169 1 16329 1 16542 1 17962 4 *the remaining 2 cases (not missing on personal care) are cases that were in hospital all day long *so I would consider them as good cases. In the end: there are only 12 badcases in dataset!*/ use "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov.dta", clear g misstime=time if main==69 collapse (sum) misstime (max) totep=prog_ep, by(progfam nordcomp) g badcase=misstime>90 | totep<7 keep progfam nordcomp badcase totep merge 1:m progfam nordcomp using "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov.dta" g diary=1 sort progfam nordcomp prog_ep g str2 country="IT" g survey=2008 g swave=0 g msamp=0 g hldid=progfam g persid=nordcomp g id=1 g diaryday=mdy(mm, gg, aa) g day=dow(diaryday) /*in Stata 0=Sunday, so this variable must variable recoded as follow*/ replace day=day+1 g cday=gg g month=mm g year=aa recode I_sesso (1=1 "man") (2=2 "woman"), gen(sex) recode I_eta (90/max=90), gen(age) order country survey swave msamp hldid persid id day cday month year diary badcase sex age time clockst start end epnum main sec inout eloc ict mtrav alone /// child sppart oad *NOTICE that I did not create AV variable *drop progfam- diaryday sort hldid persid drop _merge egen persid2= concat(hldid persid) sort persid2 destring persid2, replace g ocombwt=I_W_COE2 /*3662 missing values for cases who actually did not fill in the diaries: 2516 diary non responses, 1146 children<3 (excluded by default)*/ g agegp=trunc((age+2)/5)*5 if age>2 recode agegp (85/max=85) lab def agegp 5"3-7" 10"8-12" 15"13-17" 85"83+" lab val agegp agegp egen meanw=mean(ocombwt) g adjwt=ocombwt/meanw /*adjwt is missing for cases who did not fill in the diary*/ drop meanw g gdiary=40944/40932 /*good diary inflation factor*/ replace adjwt=0 if badcase==1 replace adjwt=adjwt*gdiary if badcase==0 egen asewt=sum(adjwt), by(agegp sex) egen asedaywt=sum(adjwt), by(age sex day) egen asedaycase=count(adjwt), by(agegp sex day) g esw=asewt/7 g propwt=(esw/asedaywt)/(asedaycase/asedaywt) save "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov.dta", replace /*provisional version*/ ****TO CREATE THE HAF forvalues i=1/69 { g main`i'=time if main==`i' } g spparttime=time if sppart==1 replace spparttime=0 if sppart==0 collapse (sum) main1-main69 spparttime (first) badcase, by(hldid persid) ren spparttime sppart egen tot=rowtotal(main1-main69) /*OK*/ drop tot egen persid2= concat(hldid persid) destring persid2, replace sort persid2 save "C:\Users\Test\Desktop\ITALIAN\it2008haf_prov.dta", replace /*provisional version*/ merge 1:m persid2 using "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov.dta" * AND NOW WE ADD THE BACKGROUND VARIABLES**** drop _m merge m:1 persid2 using "C:\Users\Test\Desktop\ITALIAN\it2008bv_prov.dta" keep country survey swave msamp hldid persid id day cday month year diary time clockst start end epnum main sec av core25 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 **THEN RUN THE FILE "harmonization of background variables.do" clear all use "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov.dta" destring persid2, replace /* There are 42 cases of grandchildren to whom parents's id cannot be assigned because actually they don't live with their parents, but with their granparents; most of them are adult (18+) There are 23 cases of nephews (children of brother or sister of the reference person) to whom parents's id cannot be assigned because actually they don't live with their parents; 8 of them are under 18 years*/ collapse (max) survey swave msamp hldid persid id day cday month year diary badcase sex age time clockst start end epnum main sec inout eloc ict mtrav alone child sppart oad, by(persid2) g str2 country="IT" save "C:\Users\Test\Desktop\ITALIAN\it2008hef_prov2.dta", replace *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 *av41* gen av = -5 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 gen animal=-9 save "C:\Users\Test\Desktop\ITALIAN\it2008haf_prov.dta", replace