/*------------------------------------------- ex5.do You won't need the first line if you have read this in by clicking on file log using ex5_res ---------------------------------------------*/ clear use "C:\Documents and Settings\gillian raab\My Documents\aprojects\peas\web\exemp5\data\ex5.dta" /*----------------------------------------------------------- first define the design - only need weighting -------------------------------------------------------------*/ svyset [pweight=weight] /*----------------------------------------------------------- now get proportions of various categories compared with unweighted tables -------------------------------------------------------------*/ svyprop q85a tabulate q85a svyprop q85b tabulate q85b svyprop living tabulate living svyprop genhelf tabulate genhelf svyprop empl tabulate empl /*---------------------------------------------------------------- some code to recode drug use into scores so that they make ordered categories ------------------------------------------------------------------*/ recode q85a (1=0) (2=0) (3=1) (4=1) (5=1) (6=0.5) ,gen (canscore) recode q85b (3=6) (1=0) (2=0) (3=1) (4=1) (5=1) (6=0.5) ,gen (ampscore) /*------------------------------------------------------------- now some mean scores to check design effects ----------------------------------------------------------------*/ svymean genhelf sinc sacc /*------------------------------------------------------------ now some regressions to predict general health score although this is categorical it is quite legitimate to use it in a regression to look for simple associations ----------------------------------------------------------*/ svyregress genhelf sinc canscore ampscore regress genhelf sinc canscore ampscore /*--------------------------------------------------- next bit of code gets some Stata commands that enable you to generate nice output to paste into reports the findit command gives access to some regression formatiing commands available from a submission to the Stata journal NEED TO EDIT HOW TO DO THIS ON A CLEAN VERSION OF Stata http://www.ats.ucla.edu/stat/Stata/faq/outreg.htm Results are sent to an external file output.doc ------------------------------------------------------*/ findit outreg net from http://www.Stata.com svyregress genhelf canscore outreg using output.doc, nolabel replace svyregress genhelf ampscore outreg using output.doc , nolabel append svyregress genhelf sinc outreg using output.doc , nolabel append svyregress genhelf canscore sinc outreg using output.doc , nolabel append svyregress genhelf ampscore sinc outreg using output.doc , nolabel append svyregress genhelf canscore ampscore outreg using output.doc , nolabel append svyregress genhelf canscore ampscore sinc outreg using output.doc , nolabel append /*----------------------------------------------------- now the same thing for an unweighted regression ------------------------------------------------------*/ regress genhelf canscore outreg using output2.doc, nolabel replace regress genhelf ampscore outreg using output2.doc , nolabel append regress genhelf sinc outreg using output2.doc , nolabel append regress genhelf canscore sinc outreg using output2.doc , nolabel append regress genhelf ampscore sinc outreg using output2.doc , nolabel append regress genhelf canscore ampscore outreg using output2.doc , nolabel append regress genhelf canscore ampscore sinc outreg using output2.doc , nolabel append /*---------------------------------------------- now look at the proportions in health groups by the original categories of cannabis use and a survey-corrected chi square ----------------------------------------------*/ svytab genhelf q85a,column percent /*------------------------------------------ now test out the effect of the finite population correction The number of women of this age group in the population is 29457. This will be set as the population size for all units since there is no startification here --------------------------------------------------*/ generate popsize=29457 /*--------------------------------------------------- now redo the survey set up putting in the FPC this can be either the pop size if > number in strata (as here) or the sampling fraction GWEIGHT needs to be used since we need to have weights that add to population totals -------------------------------------------------*/ svyset [pweight=gweight],fpc(popsize) /*--------------------------------------------- now rerun one svy mean from above it makes little difference Though the first run was wrong because it needed to have weights that add to population totals -----------------------------------------------------------*/ svymean genhelf sinc sacc