Announcement

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

  • rename variables with loops and locals

    Hi Statalist,

    Apologies for what is probably a very basic question.

    I am trying to rename a list of variables to have the same root and with ascending sequence of numbers. The original variable names look something like: xb xc xd ... xp
    and I am trying to rename them to something like: z2 z3 z4 ... z15.

    I am trying to avoid doing this manually. I have tried using a combination of locals and loops but am a beginner with those commands. Any help is much appreciated.


    Thank you!
    Robbie

  • #2
    Many details are left unspecified here, but


    Code:
    rename (x?) (z#) , renumber
    might be all that is needed.

    Best
    Daniel

    Comment


    • #3
      Daniel,

      Thanks for your quick reply. I was definitely trying to do something more complicated than necessary!

      thanks,
      Robbie

      Comment


      • #4
        If you haven't already done so, you should review help rename group (which has just a brief reference in help rename and is easily overlooked) to get some idea of how powerful the rename command can be. You'll never remember all the various possibilities, but you'll hopefully remember where to look.

        Comment

        Working...
        X