Announcement

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

  • "undue" sort command

    Hi there,

    I was wondering if it's possible to go back to the original listing of a dataset after using the -sort- command.

    For example:

    Code:
    clear all
    webuse fullauto
    sort price

    When you first open the dataset and browse, image 1 displays the first 5 observations. After using the command -sort price-, the first 5 observations become those depicted in image 2. My question is if there is a command that brings you back to image 1 after using that sort command. Or should I just run my do-file again, use preserve and restore or anything of that sort?

    Thank you in advance (:

    Image 1

    Click image for larger version

Name:	Schermafbeelding 2020-11-24 om 19.33.14.png
Views:	1
Size:	233.6 KB
ID:	1583199


    Image 2

    Click image for larger version

Name:	Schermafbeelding 2020-11-24 om 19.33.29.png
Views:	1
Size:	244.9 KB
ID:	1583200




  • #2
    Usually you will have an id and/or time variable that defines a particular sort order. In your example, that would be

    Code:
    sort make model
    Otherwise,

    Code:
    gen order=_n
    *DO SOMETHING
    sort order

    Comment


    • #3
      Andrew Musau

      I had not thought of that, thank you! Have a blessed day (:

      Comment


      • #4
        In general, you can get back to the original sort order if and only if it is defined by particular variables, or the original dataset. There isn't an "undo the last sort" as such.

        Comment


        • #5
          Nick Cox

          Okay, thank you for the explanation (: Have a great day

          Comment

          Working...
          X