I have a survey project in Stata but I want to transfer this into R.
This code in Stata sets the weighting:
svyset sitename [pweight=wgt], poststrata(strata) postweight(popsize)
and then this code produces the final weighted proportions of gender and also gender in two different age groups:
svy: prop gender
svy, subpop(if agegroup==1): prop gender
svy, subpop(if agegroup==2): prop gender
I have been trying to use the survey package in R to produce the same results and although it is weighting the figures they are not the same as the results in Stata.
I have tried a few different methods of creating a survey design object:
survey_design <- svydesign(ids = ~sitename, strata = ~strata, weights = ~wgt, data = pc_2022_data, fpc = ~popsize, nest=T)
I used this code to produce the gender proportion:
prop_table <- svytable(~pvgender, survey_design)
print(prop_table)
weighted_prop_table <- prop_table / sum(prop_table) * 100
print(weighted_prop_table)
I am trying to get the same proportion results out of both Stata and R.