How can I rank observations within groups in Stata?

前端 未结 6 1467
闹比i
闹比i 2020-12-21 01:30

I have some data in Stata which look like the first two columns of:

group_id   var_to_rank  desired_rank
____________________________________

1           10         


        
6条回答
  •  难免孤独
    2020-12-21 02:14

    The following works for me:

    bysort group_id: egen desired_rank=rank(var_to_rank)
    

    enter image description here

提交回复
热议问题