2
$\begingroup$

I have a survey design with 12 strata and have the marginal distributions of the post-stratification variables for each stratum. I am calling the rake function in the survey package as follows:

the_design = svydesign(ids=~SID, strata=~Stratum, weights=~Baseweight, data=my_data)

raked_design = rake(design=the_design , sample.margins=list(~Stratum+Annual_Income), population.margins = list(income_frequencies))

However this code produces the following error:

Error in postStratify.survey.design(design, strata[[i]], population.margins[[i]],  : 
  Stratifying variables don't match

I believe this is telling me that I need to change income_frequencies which is a data.frame that looks like this:

   HHI_lt75K HHI_gt75K
0   7.116883 11.038961
1   4.218109 10.173087
2  17.362333 10.796333
3   6.333889  9.296901
...

and where row.names='Stratum' for this data.frame.

Unfortunately I do not know

  1. If this truly is what the error message is telling me, and
  2. If this is what the error message is telling me, what I need to change.
$\endgroup$
1
$\begingroup$

The documentation of the rake function indicates that "The sample.margins should be in a format suitable for postStratify".

The Details section of the postStratify documentation indicates that "the population totals can be specified as a table with the strata variables in the margins, or as a data frame where one column lists frequencies and the other columns list the unique combinations of strata variables".

After I created income_frequencies as the following data.frame :

Stratum Annual_Income   Frequency
0       HHI_lt75k       7.116883
0       HHI_gt75k       11.038961
1       HHI_lt75k       4.218109
1       HHI_gt75k       10.173087
2       HHI_lt75k       17.362333
2       HHI_gt75k       10.796333
3       HHI_lt75k       6.333889
3       HHI_gt75k       9.296901
...

the code worked just fine.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.