Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • tabulate with weighed data

    Hello, I have a simple question. I have a dataset that is weighed according to a specific variable. Let's say when I do a simple tab, I write svy: tab X Y. Now I would like to tabulate two variables but according to a third variable. Usually on unweighed data, I use the command bysort Z=... tab X Y. This doesnt work with weighed data or the command svy:

    Does anyone have a simple solution to this really simple problem
    Many thanks

  • #2
    Perhaps using the subpop option to the svy prefix will do what you need. Example 3 in the documentation for svy: tabulate twoway in the Stata Survey Data Reference Manual (as of version 13, at least) shows how to restrict the tab to a subpopulation (males, in the example). So you'd have to run the command repeatedly, once for each subpopulation (value of Z). Assuming Z takes on values 1, 2, and 3, something like this might do the trick.
    Code:
    svy, subpop(if Z==1): tab X Y
    svy, subpop(if Z==2): tab X Y
    svy, subpop(if Z==3): tab X Y
    Of course you could get fancier and use a loop, and use levelsof to figure out the values Z takes, if you're going to be doing this repeatedly and are fonder of programming than of copy/paste/edit.

    Comment


    • #3
      The (non-svy) table command accepts pweights and can take a bys prefix.
      Last edited by Steve Samuels; 15 Oct 2015, 21:43.
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment

      Working...
      X