[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: ranking with weights

From   Cindy Gao <>
To   "" <>
Subject   st: ranking with weights
Date   Tue, 2 Dec 2008 17:54:58 +0000 (GMT)


I am trying to find a way to rank weighted data (since the egen function -rank- does not work with weights). A simple way would be order the data in terms of variable that I have interest in (monthly expenditure) and then create a new variable like -g rank1=sum(weight)-. But, there is problem. Some of my observations are "tied" as they have the same level of expenditure. Using the simple method I mention means that some observations are ranked above others even though they have same level of expenditure. This is a problem as the weights are large so you find that 2 observations are ranked with bug gap in between even though same level of expenditure. It is even bigger problem because the weights might be correlated with some other variables I am interested in (like region, since some regions are less sampled than other). I also try multiplying the expenditure ranking by the weight, but this gives wrong results (for example they do not add up to weighted
 total). Can anyone help? In other words, I would like for all observations with same expenditure to have same rank, which I assume would be some average of all the weighted observations having that same expenditure.  I include a sample dataset below:

expenditure       weighting        rank       rank1      weighted_rank
10                          341            1           341          341
12                          1065          2.5        1406         ???
12                          98             2.5        1504
15                          254            4          1758




*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index