Stata OUTPUT FOR WEIGHTING EXEMPLAR 5
. . 

. /*------------------------------------------------
> 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")
(6237 real changes made)

. 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)
note: npop has non-integer values

Iteration 0:   log likelihood = -9706.4317  
Iteration 1:   log likelihood = -9062.1124  
Iteration 2:   log likelihood = -9057.7472  
Iteration 3:   log likelihood = -9057.7441  
Iteration 4:   log likelihood = -9057.7441  

Generalized linear models                          No. of obs      =     12473
Optimization     : ML: Newton-Raphson              Residual df     =     12465
                                                   Scale parameter =         1
Deviance         =  11071.29384                    (1/df) Deviance =  .8881904
Pearson          =  14532.76795                    (1/df) Pearson  =  1.165886

Variance function: V(u) = u*(1-u/npop)             [Binomial]
Link function    : g(u) = ln(u/(npop-u))           [Logit]
Standard errors  : OIM

Log likelihood   = -9057.744071                    AIC             =  1.453659
BIC              = -106490.1297

------------------------------------------------------------------------------
    ayra_num |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      agegrp |   .1284079   .0070475    18.22   0.000      .114595    .1422207
         sex |   .8600035   .1178021     7.30   0.000     .6291157    1.090891
      sexage |  -.1149884   .0277591    -4.14   0.000    -.1693953   -.0605815
     sex2age |   .0021792   .0018124     1.20   0.229    -.0013731    .0057315
        sinc |  -.0108381   .0022407    -4.84   0.000    -.0152297   -.0064464
      sexinc |  -.0045198   .0029784    -1.52   0.129    -.0103574    .0013178
        sacc |   .0446326    .023689     1.88   0.060    -.0017971    .0910622
       _cons |  -5.011847   .0703457   -71.25   0.000    -5.149722   -4.873972
------------------------------------------------------------------------------

. predict phat
(option mu assumed; predicted mean ayra_num)

. /*------------------------------------
> Stata predicts number not probability
> so need to multiply weight by npop
> ---------------------------------------*/
. generate gweight=npop/phat

. 
end of do-file

. edit
- preserve