capture log close log using "By-Egen\SOCY498C-HW6-BY-EGEN.txt", text replace clear capture confirm file "C:\Documents and Settings\HP_Owner\My Documents\My Research\GSS\GSS-Cumulative-72-06.dta" if _rc { di "_rc" } else { local gss "C:\Documents and Settings\HP_Owner\My Documents\My Research\GSS\GSS-Cumulative-72-06.dta" } #delimit ; use year socbar socrel socommun socfrend marital race age sex sexfreq if race!=3 using "`gss'", clear; #delimit cr /* Create average sociability measure */ #delimit ; recode socrel socommun socfrend socbar (1=7) (2=6) (3=5), prefix(x) label(socrel); #delimit cr generate sociability=(xsocrel+xsocommun+xsocfrend+xsocbar)/4 label variable sociability "Sociability Scale (1-25)" drop xsocrel xsocommun xsocfrend xsocbar #delimit ; recode sexfreq (0=0) (1=1.5) (2=12) (3=30) (4=52) (5=130) (6=237), gen(sexfreq1) ; #delimit cr label variable sexfreq1 "Sexual Frequency (yearly)" /* by and egen examples */ sort marital by marital: summarize sociability sort marital age by marital: gen minage=age[1] drop minage bysort marital (age): gen minage=age[1] egen age_cat1 = cut(age), at(18, 25, 35, 45, 55, 65, 75, 90) egen age_cat2 = cut(age), group(6) egen sexfreq2 = mean(sexfreq1), by(marital) egen sexfreq3 = mean(sexfreq1), by(sex marital) egen numobs1 = count(sexfreq1), by(year) egen numobs2 = count(sexfreq1), by(year marital) egen sexmar=group(sex marital), label egen marsex=group(marital sex), label egen sexmarcon=concat(sex marital), punct(/) /* by and egen problems */ egen socmiss=rowmiss(socrel socommun socfrend socbar) tab socmiss egen racesex=group(race sex), label tab racesex graph bar (p25) sociability (p75) sociability, over(racesex) egen avgsoc=mean(sociability), by(year sex) log close