I am trying to get the weighted n for a variable and can't figure out how to do it with svyset
in Stata.
This is how I have applied svyset:
svyset final_cleaned_id [pweight = totalweight_max_low2], strata(final_urban_rural)
When I use svy : tab sex
I only get weighted proportions. For sex, male is coded as 0 and female as 1.
Is there a way to get the weighted numbers in my scenario? I am also open to using something other than svyset
as I find it frustratingly limited.
If you only want the counts, and don't care about the standard errors, you could just use frequency weights:
tab sex [fw=totalweight_max_low2]
You can only use frequency weights if the weights are integers. It's quite common practice to just round your weights if they contain non-integers:
gen roundweight = round(totalweight_max_low2)
tab sex [fw=roundweight]
You may find it helpful to read help weight
, which has helpful and clear documentation.
You need to be really careful with which kinds of weights you use when you're conducting inference (so need standard errors etc). In your case for inference you probably would need to use the svy
suite of commands to take account of the complex survey design. You could then try commands like svy, subpop(sex): total sex
to get total population for women with standard errors; then define a dummy variable for men and analogously run svy, subpop(male): total sex
to get the total for men.