Dear Forum,
I want to create weights for survey data (using the characteristics of gender, age and ethnicity) and was just wondering if I was using the survwgt package (and its raking function) correctly? Any comments on the code below would be most gratefully received. Best and thanks,
Thomas
gen Weight = 1
// generate totals for the weights using demographic data
gen GenderTotal=.
replace GenderTotal = 0.49 if Gender == 1
replace GenderTotal = 0.51 if Gender == 2
gen AgeTotal=.
replace AgeTotal = 0.12 if Age_group == 1
replace AgeTotal = 0.17 if Age_group == 2
replace AgeTotal = 0.17 if Age_group == 3
replace AgeTotal = 0.16 if Age_group == 4
replace AgeTotal = 0.38 if Age_group == 5
gen EthnicityTotal=.
replace EthnicityTotal = 0.63 if Ethnicity == 1
replace EthnicityTotal = 0.12 if Ethnicity == 2
replace EthnicityTotal = 0.06 if Ethnicity == 3
replace EthnicityTotal = 0.11 if Ethnicity == 4
replace EthnicityTotal = 0.08 if Ethnicity == 5
// rake the weights using the Stata survwgt package
survwgt rake Weight , by(Gender Age_group Ethnicity) totvars(GenderTotal AgeTotal EthnicityTotal) generate(rakedweight)
I want to create weights for survey data (using the characteristics of gender, age and ethnicity) and was just wondering if I was using the survwgt package (and its raking function) correctly? Any comments on the code below would be most gratefully received. Best and thanks,
Thomas
gen Weight = 1
// generate totals for the weights using demographic data
gen GenderTotal=.
replace GenderTotal = 0.49 if Gender == 1
replace GenderTotal = 0.51 if Gender == 2
gen AgeTotal=.
replace AgeTotal = 0.12 if Age_group == 1
replace AgeTotal = 0.17 if Age_group == 2
replace AgeTotal = 0.17 if Age_group == 3
replace AgeTotal = 0.16 if Age_group == 4
replace AgeTotal = 0.38 if Age_group == 5
gen EthnicityTotal=.
replace EthnicityTotal = 0.63 if Ethnicity == 1
replace EthnicityTotal = 0.12 if Ethnicity == 2
replace EthnicityTotal = 0.06 if Ethnicity == 3
replace EthnicityTotal = 0.11 if Ethnicity == 4
replace EthnicityTotal = 0.08 if Ethnicity == 5
// rake the weights using the Stata survwgt package
survwgt rake Weight , by(Gender Age_group Ethnicity) totvars(GenderTotal AgeTotal EthnicityTotal) generate(rakedweight)



Comment