/*-------------------------------------------------- ex5wt.do To calculate weights for the Ayr and Arran health survey The first command will not be needed if data read in already ----------------------------------------------------*/ use "C:\Documents and Settings\gillian raab\My Documents\aprojects\peas\web\exemp5\data\ex5wt.dta", clear . /*------------------------------------------------ run a regression model for non response Only the final model is shown here not the model building steps To get categorical variables in Stata a set of dummy variables need to be created first calculate variables making sex numeric and calculating interaction variables -------------------------------------------------------*/ generate sex=0 replace sex=1 if match(gender,"F") generate agegrpsq=agegrp*agegrp generate sexage=agegrp*sex generate sex2age=agegrp*agegrp*sex generate sexinc=sinc*sex glm ayra_num agegrp sex sexage sex2age sinc sexinc sacc, f(bin npop) link(logit) predict phat /*------------------------------------ Stata predicts number not probability so need to multiply weight by npop ---------------------------------------*/ generate gweight=npop/phat /*-------------------------------------- next step is to merge this one back with the main data file for analysis (not shown om this site --------------------------------------------*/