stata - Collapse with weights -- how to get the sample count, not the population count? -


i'm collapsing data using weight, want weight apply median , sum, not count. want count sample size, not population size.

example:

. input outcome group weight         outcome      group     weight   1. 1 1 3   2. 1 2 3   3. 1 3 3   4. end 

running collapse (sum) outcome (count) n = outcome [pweight = weight], by(group) gives

. list       +---------------------+      | group   outcome   n |      |---------------------|   1. |     1         3   3 |   2. |     2         3   3 |   3. |     3         3   3 |      +---------------------+ 

both sum , count using weight. want count sample size, i.e. 1 each group.

unfortunately not possible have different weights when using collapse.

the few solutions have in mind:

  • create weights in data, , compute weighted statistics yourself
  • have @ user-written version of collapse, might include feature. instance, collapse2 or xcollapse

Comments