Introduction
I have multilevel survey data of teachers nested in schools. I have manually calculated design weights and non-response adjustment weights based on probability selection and response rate. Now I want to create post-stratification weights to compensate for non-coverage, mainly by raking on two marginals: the sex of (male or female) and the employment status (full-time or not full-time) of the teacher. I have tried doing this in Stata using the user-written module survwgt; however, I can't get it to work on nested data.
Sample Data
Failed Attempts
This produced the following error, presumably because the data are nested in schools:
This produced the following error, presumably because the data are nested in schools:
How can I rake margins for observations that are nested in groups?
I have multilevel survey data of teachers nested in schools. I have manually calculated design weights and non-response adjustment weights based on probability selection and response rate. Now I want to create post-stratification weights to compensate for non-coverage, mainly by raking on two marginals: the sex of (male or female) and the employment status (full-time or not full-time) of the teacher. I have tried doing this in Stata using the user-written module survwgt; however, I can't get it to work on nested data.
Sample Data
**Variables** school : unique school id male : 1 = male teacher fulltime : 1= full-time teacher Nall : true population total of teachers, per school nall : number of teachers in the sample, per school Nmale : true population total of male teachers, per school nmale : number of male teachers in the sample, per school Nfull : true population total of full-time teachers, per school nfull : number of full-time teachers in the sample, per school rr : response rate of teachers, per school (used to calculate oldwt) oldwt : the product of the design weight and the non-response adjustment newwt : the new weight, to be produced via raking |
school | male | fulltime | Nall | nall | Nmale | nmale | Nfull | nfull | rr | oldwt |
1 | 1 | 1 | 9 | 5 | 4 | 3 | 7 | 3 | .56 | 1.8 |
1 | 1 | 1 | 9 | 5 | 4 | 3 | 7 | 3 | .56 | 1.8 |
1 | 1 | 0 | 9 | 5 | 4 | 3 | 7 | 3 | .56 | 1.8 |
1 | 0 | 1 | 9 | 5 | 4 | 3 | 7 | 3 | .56 | 1.8 |
1 | 0 | 0 | 9 | 5 | 4 | 3 | 7 | 3 | .56 | 1.8 |
2 | 1 | 1 | 8 | 6 | 6 | 4 | 5 | 4 | .75 | 1.3 |
2 | 1 | 1 | 8 | 6 | 6 | 4 | 5 | 4 | .75 | 1.3 |
2 | 1 | 0 | 8 | 6 | 6 | 4 | 5 | 4 | .75 | 1.3 |
2 | 1 | 1 | 8 | 6 | 6 | 4 | 5 | 4 | .75 | 1.3 |
2 | 0 | 1 | 8 | 6 | 6 | 4 | 5 | 4 | .75 | 1.3 |
2 | 0 | 0 | 8 | 6 | 6 | 4 | 5 | 4 | .75 | 1.3 |
Failed Attempts
- I first tried
Code:
survwgt rake oldwt, by(nmale nfull) totvars(Nmale Nfull) generate(newwt)
Control total Nmale not constant within categories of dimension nmale
- So I next tried specifying the data as grouped:
Code:
bysort school: survwgt rake oldwt, by(nmale nfull) totvars(Nmale Nfull) generate(newwt)
survwgt may not be combined with by
Comment