Announcement

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

  • bysort descending

    Dear users,

    I am trying to use the "gsort -" command to sort observations in descending order. The problem is that I need to order observations within sub-groups, and the "gsort" command does not seem to support the "by:[...] option. Also, the command "sort" does support the "by:[...]" option, but only sorts in ascending order. Any help on how to solve this?

    Many thanks in advance.

  • #2
    Both commands take a varlist argument. Sorting a group isn't necessary because you can:

    Code:
    gsort group date - metric
    Just make sure the variable you would use for the by prefix as the first argument in the variable list.

    Comment


    • #3
      Various techniques can come in useful here. One is

      Code:
      gsort frog -toad 
      by frog:
      Another is

      Code:
      gen negfrog = -frog 
      bysort negfrog (toad) :
      If this does not help enough, do show concrete examples of what you want to do.

      Comment


      • #4
        Hello,

        Many thanks to both of you for the help.
        All suggested techniques worked perfectly.

        Comment

        Working...
        X