Announcement

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

  • Order data in descending order

    Dear all,

    I use the TNIC data from Hoberg&Phillips and want to sort the scores pro competitor_rank1 in descending order in order to keep only the top 5 competitors for each gvkey1. I am not experienced with STATA and tried to do it using the following code, but the score is still in descending order:

    clear
    cd "C:\Users\etc"
    use tnic3
    sort gvkey1 score
    gen competitor_rank = _n
    sort competitor_rank gvkey1
    egen competitor_rank1 = group(gvkey1)
    bysort competitor_rank1 (score): gen descending_order = _n
    sort competitor_rank1 -descending_order

    alternative:
    use tnic3
    sort gvkey1 score
    gen competitor_rank= _n
    sort competitor_rank gvkey1
    egen competitor_rank1=group(gvkey1)
    sort -score competitor_rank1

    (here the error is "- invalid name" even if the column is names "score")


    Any help, however small would be greatly appreciated! Thank you in advance!
    Attached Files

  • #2
    Code:
    help gsort
    See also my paper on the largest 5 in the Stata Journal.

    Comment


    • #3
      https://journals.sagepub.com/doi/pdf...6867X221106436 is the paper concerned.

      Comment


      • #4
        Thank you so much!!! I just started to use STATA and wasted so much time trying to arrange the data without result, you really saved me! Thank you very much!

        Comment

        Working...
        X