/*--------------------------------------------------------------
ex2.do version  of 25/9/04

HOW TO USE THIS FILE
To submit commands highlight the line you want to submit and 
go to >Do  on the >Tools menu

Any text between a /* and  a */ is treated as a comment.

At the Stata command window typing "help do" will give more information 
   and   "help help" gives very useful information on viewing results

Analyse  SHS data in Stata Exemplar 2

HIGHLIGHT AND do ONE LINE AT A TIME STARTING AFTER THE COMMENT

set the survey description
and run the svydes to get a description of it
--------------------------------------------------------------*/

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

Stata allows two different design effects in 
this case 
The default option assumes 
 -------------------------------------------------------------*/

svymean intuse , ci deff

svymean intuse, deff deft ci by(sex)

/*-----------------------------------------------
Stata allows two different design effects for 
subpopulations 
 
The default option assumes simple random sampling 
accross the whole population
The option srssubpop assumes simple random samplin
within each subpopulation
See the differences by council area.
 -------------------------------------------------------------*/

svymean intuse, deff  ci by(council) srssubpop
svymean intuse,  ci deff by(council)

/*------------------------------------------------------------
Now getting proportions of internet hours use for users
--------------------------------------------------------------*/

svymean rc5

svymean rc5,  by (intuse)

/*------------------------------------------------------------
this fails because of lonely PSUs due to missing values
No easy way round it at present

Now chi square tests for surveys
The table with RC5 fails for same reasons 
as previously.

------------------------------------------------------------*/

svytab sex intuse, ci deff deft

svytab rc5 intuse, ci deff deft

svytab rc7e intuse, ci deff
/*--------------------------------------------------------
now some logistic regression
first get the dummy variables
-----------------------------------------------------------*/
tabulate groupinc, generate(groupinc)

tabulate groupinc1

svymlogit intuse groupinc2-groupinc6

/*------------------------------------------------
now add urban rural
-----------------------------------------------------*/
tabulate shs_6cla, generate (rural)

svymlogit intuse groupinc2-groupinc6 rural2-rural6,deft deff

/*--------------------------------------------------
to fit a spline model you need to install the bsplines
package which is done easily by following the help
menu for bsplines
--------------------------------------------------------*/
 bspline,x(age)  power(3) gen(bs)

svymlogit intuse bs1-bs4,noconst deft deff

predict pr0 pr1

plot pr1 age