SAS results exemplar 4

 This is an HTML version of the SAS program ex4.sas
 To run the program you must read ex4.do into the Stata do file editor
 to view the ouptut from these commands in html go to Stata results page

Links in this page

Equal opportunities policies weighted and unweighted - Table 4.3 E O policy by workplace size Table 4.4 Other factors by equal opportunities policy Table 4.5 Logistic regressions Table 4.6 Logistic regressions Table 4.7 Finite population corrections Table 4.8
Back to topuparrow /*----------------------------------------------------------- Table 4.3 get unweighted estimate of proportion of workplaces with an equal opportunities policy (EOP) but allowing for stratification -------------------------------------------------------------*/ gen const=1 svyset [pweight=const], strata(strata) /*---------------------------------------------------------- now get weighted estimate - strata remain from previous call using svymean to get design effect ------------------------------------------------------------*/ svyset [pweight=est_wt] svydes svyprop eo svymean eo,deff deft Back to topuparrow /*-------------------------------------------------------------- table 4.4 now weighted table of proportions woth EOP by size of workplace ------------------------------------------------------------*/ svytab nempsize eo, row percent Back to topuparrow /*------------------------------------------------------- table 4.5 factors compared between eo workplaces and others -------------------------------------------------------*/ svymean eo if ethnic==1 /*--------------------------------------------- note this command is wrong because it does not define a subgroup of the survey On the practical side it fails here because you will get a warning stratum with only one PSU detected Defining subsets of the survey works. It is more forgiving to the odd lonely PSU -------------------------------------------------*/ svymean female,by(eo) svymean ethnic,by(eo) svyprop eo,by(disabgrp) /*-------------------------------------------------------------- now weighted linear models to get ses of differences ------------------------------------------------------------*/ svyregress female eo svyregress ethnic eo /*--------- get dummies for linear models----------*/ tab disabgrp, gen(disab) svyregress disab1 eo svyregress disab2 eo svyregress disab3 eo /*-------------------------------------------------------------- same analyses unweighted ------------------------------------------------------------*/ svyset [pweight=const] svymean female,by(eo) svymean ethnic,by(eo) svyprop disabgrp,by(eo) svyregress disab1 eo svyregress disab2 eo svyregress disab3 eo Back to topuparrow /*-------------------------------------------------------------- table 4.6 now weighted multivariate logistic models ------------------------------------------------------------*/ svyset [pweight=est_wt] svylogit eo female disab2 disab3 ethnic /*-------------------------------------------------------------- now unweighted multivariate logistic models ------------------------------------------------------------*/ svyset [pweight=const] svylogit eo female disab2 disab3 ethnic Back to topuparrow /*-------------------------------------------------------------- table 4.7adjusted for workplace size now weighted multivariate logistic models ------------------------------------------------------------*/ tab nempsize, gen(numemp) svyset [pweight=est_wt] svylogit eo female disab2 disab3 ethnic numemp2-numemp6 /*-------------------------------------------------------------- now unweighted multivariate logistic models ------------------------------------------------------------*/ svyset [pweight=const] svylogit eo female disab2 disab3 ethnic numemp2-numemp6 Back to topuparrow /*-------------------------------------------------------------- now mean of eo and by size group allowing for finite population correction Stata requires two things to get the finite population correct 1. A variable with the number of PSUs in the startum 2. Weights that add to the population size first without fpc ------------------------------------------------------------*/ svyset [pweight=grosswt], strata(strata) clear(fpc) svymean eo ,deff deft svymean eo, deff deft by(nempsize) svymean eo, deff deft by(nempsize)srssubpop /*----------- now with fpc--------------------------------*/ svyset [pweight=grosswt] ,fpc(sampfrac) strata(strata) svymean eo, deff deft svymean eo, deff deft by(nempsize) svymean eo, deff deft by(nempsize)srssubpop /*---------------------------------------------------- The two analyses give the different ways that design effects can be defined for subgroups The second one that compares the design with simple random samples of the same size within subgroups is more helpful Note that design effects are much reduced within subgroups. This is because the subgroups are so strogly associated with the weighting factor here. ---------------------------------------------------------*/ /*------------------------------------------------------------ now testing the effect of a finite population correction For this we need to make a SAS table with a record for each startum and a variable _rate_ with the sampling fraction table 4.8 -----------------------------------------====---------------*/ PROC sort data=exemp4.ex4 out=rates; by strata; run; data rates; set rates; by strata; if first.strata; _rate_=sampfrac; keep _rate_ strata; run; PROC surveymeans data=exemp4.ex4 mean stderr nobs clm rate=rates; weight est_wt; var eo; strata strata; domain nempsize; run;