/*exercise 4*/ tab year; tab day; tab day, nol; gen weekday=1; replace weekday=0 if day==1 | day==7; tab weekday day, missing; tab weekday year; tab weekday year, col; svyset [weight=wt06]; svy: tab weekday year, col; /*exercise 5*/ mean act_sports, over(weekday year); svy: mean act_sports, over(weekday year); gen nz_act_sports=act_sports if act_sports>0; svy: mean nz_act_sports, over(weekday year); /*exercise 6*/ svyset [weight=wt06]; /*Recode day of the week*/ gen newday=.; replace newday=1 if day>=2 & day<=6; replace newday=2 if day==7; replace newday=3 if day==1; /*keep only respondents 25 to 64*/ keep if age>=25 & age<=64; /*generate new time use variables*/ gen ex_new=ex64+ex46; gen exal_new=exal64+exal46; gen exoth_new=exoth64+exoth46; /*create dummy variable for female*/ gen female=0; replace female=1 if sex==2; /*generate means for exercising by gender, by gender & day*/ svy: mean ex612 ex126 ex_new, over(female); svy: mean ex612 ex126 ex_new, over(female newday); /*generate means for exercising alone by gender, by gender & day*/ svy: mean exal612 exal126 exal_new, over(female); svy: mean exal612 exal126 exal_new, over(female newday); /*generate means for exercising with others by gender, by gender & day*/ svy: mean exoth612 exoth126 exoth_new, over(female); svy: mean exoth612 exoth126 exoth_new, over(female newday); /*exercise 7*/ /*basic tabulation*/ tab schappy; tab scstress; /*recode NIU as missing*/ foreach var of varlist scpain schappy scsad sctired scstress meaning {; generate new`var'=.; replace new`var'=`var' if `var'>=0 & `var'<=6; }; /*tab happy again*/ tab newschappy; /*generate weighted means for the six subjective well-being items using AWBWT*/ svyset [weight=awbwt]; svy: mean newscpain; svy: mean newschappy; svy: mean newscsad; svy: mean newsctired; svy: mean newscstress; svy: mean newmeaning; /*generate weighted means and unweighted N's for each subjective well-being measure during sports, exercise, and recreation and during work and work-related activities*/ generate sports=0; replace sports=1 if activity>=130101 & activity<=139999; gen work=0; replace work=1 if activity>=050101 & activity<=059999; svy, subpop(if sports==1): mean newschappy newscstress; svy, subpop(if work==1): mean newschappy newscstress; /*generate weighted person-level estimates using WBWT of average subjective well-being (for each of the six well-being measures) for men and women aged 25 to 64 during paid work and work-related activities*/ /*keep only activity records with non-missing well-being data*/ keep if work==1 & awbwt>0 & awbwt!=.; /*generate a new activity line number to use later*/ bysort caseid: gen newactline=_n; tab newactline; /*create average well-being for only work activities*/ egen personhappy_mean=mean(newschappy) , by(caseid); egen personstress_mean=mean(newscstress) , by(caseid); sort caseid newactline; keep if newactline==1; /*now back to the person records—prune the sample*/ keep if age>=25 & age<=64; svyset [weight=wbwt]; svy: mean personhappy_mean personstress_mean, over(sex); /*exercise 8*/ /*get number of ATUS non-respondents to each module*/ tab eh_resp; tab wb_resp; /*number of module respondents in 2013 and 2014*/ tab wb_resp if year==2013; tab eh_resp if year==2014; /*number of respondents in BOTH WB and EH modules*/ tab wb_resp eh_resp; /*eliminate missings in new health variable*/ gen health=genhealth if genhealth<96; /*generate a weight equal to WB module weight if in that module and EH module weight if in that module*/ gen combwt=.; replace combwt=wbwt if wb_resp==1; replace combwt=ehwt if eh_resp==1; /*generate weighted means*/ svyset [weight=combwt]; svy: mean bls_leis_tv, over(health); /*exercise 9*/ /*how many completed module?*/ tab eh_resp; /*keep married only*/ keep if spousepres==1 | spousepres==2; /*keep eh module only*/ keep if eh_resp==1; /*num partnered*/ tab spousepres; /*differentiate same sex vs different sex*/ gen samesex=(sex==spsex); /*num same sex and by sex*/ tab samesex; tab sex samesex; gen resp_coupletype=1 if sex==1 & samesex==1; replace resp_coupletype=2 if sex==1 & samesex==0; replace resp_coupletype=3 if sex==2 & samesex==1; replace resp_coupletype=4 if sex==2 & samesex==0; /*remove missings from foodshop*/ gen r_mealprep=mealprep if mealprep<96; /*generate row percentages*/ svyset [weight=ehwt]; svy: tab resp_coupletype r_mealprep, row; /*generate mean time use by couple type*/ svy: mean foodprep, over(resp_coupletype);