/*Exercise: Understanding Affect Data from the Well-Being Module*/ /*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);