Announcement

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

  • move a column up

    how i can do this
    title
    1
    2
    3
    4
    5
    6

    title
    2
    3
    4
    5
    6
    .

  • #2
    try this:
    Code:
    replace title=title[_n+1]

    Comment


    • #3
      thank you

      Comment


      • #4
        and how to move down ?

        Comment


        • #5
          Code:
          replace title=title[_n-1]

          Comment


          • #6
            No, Jorrit Gosens that will not work. That will just replace all values in that column with missings.
            Code:
            // incorrect way
            sysuse auto, clear
            replace make=make[_n-1]
            list make price
            
            // correct way (one of)
            sysuse auto, clear
            tempvar idx
            generate long `idx'=_n
            gsort -`idx'
            replace make=make[_n+1]
            gsort `idx'
            drop `idx'
            list make price
            Last edited by Sergiy Radyakin; 23 Mar 2016, 10:05. Reason: Added code example

            Comment


            • #7
              May ask why one would want to do such things?

              Seems like a good idea to do it via reproducible syntax anyway.

              Best
              Daniel

              Comment


              • #8
                Ah, I spoke too soon, apologies. Won't work because it starts making the changes from the top, and finds a missing for every next change it wants to make, yes?

                Comment

                Working...
                X