Announcement

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

  • Removing middle character of variable

    Hi Statalist, I am trying to do something I think should be simple but is giving me trouble.

    I have a bunch of variables named in the following format:

    xyz1a_wave1
    xyz1b_wave1
    xyz1c_wave1
    xyz1d_wave1
    xyz2a_wave1
    xyz2b_wave1
    xyz2c_wave1
    ...and so on. I am trying to rename all of these at once, just dropping the "z" in the middle of the variable name (to match the variable naming convention of the other waves of data). The problem is that there are 2 characters in the variable name that are counting up (both the number and the letter immediately following the number), so I don't think I can do this:

    Code:
    rename (xyz**_wave3) (xy**_wave3)
    Because two ** are not allowed. Is there some workaround here that I could use?

  • #2
    I think you are overthinking the problem. This case is essentially to replace one variable name stem with another, so the following works with your example.

    Code:
    rename (xyz*) (xy*)

    Comment


    • #3
      perhaps,
      Code:
      rename (xyz*_wave*) (xy*_wave*)

      Comment


      • #4
        Originally posted by Leonardo Guizzetti View Post
        I think you are overthinking the problem. This case is essentially to replace one variable name stem with another, so the following works with your example.

        Code:
        rename (xyz*) (xy*)
        Oh gosh, you're exactly right. Thank you.

        Comment

        Working...
        X