/*-------------------------------------------- HOW TO USE THIS FILE EVERYTHING INSIDE (STAR SLASH) AND (SLASH STAR) IS TAKEN AS A COMMENT open it in the Stata do file editor Run one line or group of lines at a time by either highlighting them and going to DO in the tools window (Run from this window will do it but give you no output) Or press Ctrl^D /*-------------------------------------------- Analyse SHS data in Stata Exemplar 2 First read in the file set the survey description and run the svydes to get a description of it use "C:\Documents and Settings\gillian raab\My Documents\aprojects\peas\web\exemp2\data\ex2.dta", clear --------------------------------------------------*/ svyset [pwei=ind_wt],psu(psu) strata(stratum) svydes /*------------------------------------------------- First simple proportions of INTERNET USE We give the code for this below, but in Stata you can Also get a dialogue box by searching for the commands in the help menu When you complete this the code will be generated for you ------------------------------------------------*/ svyprop intuse /*------------------------------------------------------ svyprop does not give design effects so must treat proportion as the mean of a 0/1 variable to get the design effects and we can also get them for subgroups -------------------------------------------------------------*/ svymean intuse , ci deff svymean intuse, deff deft by(sex) /*------------------------------------------------------------ Now getting proportions of internet hours use for users --------------------------------------------------------------*/ svymean rc5 /*------------------------------------------------------------ this fails because of lonely PSUs due to missing values ------------------------------------------------------------*/ svydes if intuse==1 /*--------------------------------------------------- This identifies them but there is no easy way round it except by setting it up as a regression RESULTS FOR TABLE 2.4 IN EXEMPLAR 2 HOME PAGE different design options In order to text out what the design effect for internet use would have been for different types of design it is necessary to set up a new design BUT all previous settings need to be cleared as part of this process. Unless this is done previous settings will remain -------------------------------------------------------------*/ svyset [pweight=ind_wt], clear( strata psu pweight ) svymean intuse , ci deff svyset ,psu(psu) svymean intuse , ci deff svyset, clear(psu) strata(stratum) svymean intuse , ci deff svyset,psu(psu) Now chi square tests for surveys So the table with RC5 fails for same reasons s previously. ------------------------------------------------------------*/ svytab intuse sex, count row percent svytab intuse rc5, svytab sex groc, count row percent format(%10.2f) /*------------------------------------------------------------- Now internet use by council area to illustrate different types of design effect for sub-groups The srssubpop option in the second command gives design effects compared to simple random sampling in sub populations -----------------------------------------------------------*/ svymean intuse, ci deff by(council) svymean intuse, ci deff by(council) srssubpop *-------------------------------------------------------- now some logistic regression first get the dummy variables -----------------------------------------------------------*/ tabulate groupinc, generate(groupinc) tabulate groupinc1 /*---------------------------------- will miss out groupinc2 as analysis restricted to cases with income data -----------------------------------------*/ svylogit intuse groupinc3-groupinc6 if groupinc>0,prob deff deft or /*---------------------------------------------- compare with unweighted logistic regression --------------------------------------------------*/ logistic intuse groupinc3-groupinc6 if groupinc>0, or /*------------------------------------------------ now add urban rural you will see almost no effect -----------------------------------------------------*/ tabulate shs_6cla, generate (rural) svylogit intuse groupinc3-groupinc6 rural2-rural6 if groupinc>0,prob or /*-------------------------------------------------- to fit a spline model you need to install the bsplines package which is done easily by following the help --------------------------------------------------------*/ bspline,x(age) power(3) gen(bs) svymlogit intuse bs1-bs4,noconst deft deff predict pr0 pr1 plot pr1 age