Announcement

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

  • gosrt are not stable when identifiers are the same, how to make it the order stable?

    I find when use gsort var, when var has some duplicates of obervation, the order after gsorting are not stable. How to make it stable?

  • #2
    The stable options keeps contiguous blocks of observations defined by the same sort value together in the same relative ordering prior to the sort. The use of -stable- sorting option is pretty controversial to some on this forum. The crux of the argument is that if the apparent stability is important, then the sort variables are incompletely defined and the data should speak for themselves, or else the stability doesn't matter and so one should not care that Stata breaks ties in a random fashion.

    You can mimic sort order by first creating an observation index.

    Code:
    gen idx = _n
    gsort -sortvar1 idx

    Comment


    • #3
      Originally posted by Leonardo Guizzetti View Post
      The stable options keeps contiguous blocks of observations defined by the same sort value together in the same relative ordering prior to the sort. The use of -stable- sorting option is pretty controversial to some on this forum. The crux of the argument is that if the apparent stability is important, then the sort variables are incompletely defined and the data should speak for themselves, or else the stability doesn't matter and so one should not care that Stata breaks ties in a random fashion.

      You can mimic sort order by first creating an observation index.

      Code:
      gen idx = _n
      gsort -sortvar1 idx
      Thanks for the tips!

      Comment

      Working...
      X