Announcement

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

  • sort for each column (variable)?

    Dear all, How can I sort for each column/variable so that the values are in ascending order for each column/variable?
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(var1 var2 var3)
    -.000565588  .003170494    .0004866
      .00274415  .001754911 -.005638469
    -.007524003  .008604493  .000423284
    -.003661071  -.00127114 -.000131669
     .003904666 -.000133898 -.005763379
     .001541395 -.003228544 -.001410524
       .0038835 -.001180972  .004857452
    -.000484614 -.007589492 -.000792214
    -.008681948   .00113195 -.005468268
    -.006704849 -.002468719  .000455252
    end
    I have the following code to do this, but wonder if there exists a more concise way.
    Code:
    gen t0 = _n
    reshape long var, i(t0) j(i)
    bys i (var): gen t1 = _n 
    drop t0
    reshape wide var, i(t1) j(i)
    drop t1
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    I wonder whether the command - sort var1 var2 var3 - fits your needs.
    Best regards,

    Marcos

    Comment


    • #3
      Code:
      ssc desc fixsort

      Comment


      • #4
        Originally posted by Marcos Almeida View Post
        I wonder whether the command - sort var1 var2 var3 - fits your needs.
        Marcos: thanks, but not really.

        Ho-Chuan (River) Huang
        Stata 17.0, MP(4)

        Comment


        • #5
          Thanks again, Nick. It is exactly what I am looking for.
          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment

          Working...
          X