Announcement

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

  • Swapping prefixes and suffixes of variable names with rename

    I have many variables. Some begin with "YJan2016" (or another date) and others begin with "Y2016" (or another date). Instead, I am trying to make them end with "Jan2016" or "2016", respectively. Does anyone know how I can do this?

    In the rename help file, I found this line, but I don't know how to specify when Stata should be swapping the prefixes and (nonexistent) suffixes. If it helps, no variable besides date variables begins with the character "Y":

    "rename *stat* *[2]stat*[1]: Swaps prefixes and suffixes; it renames bpstata to astatbp, rstater to erstatr, etc."




  • #2
    Here is an example

    Code:
    clear
    inp YJan2016foo Y2016bar
    42 42
    end
    
    describe
    
    rename (Y*#*) (*[3]*[1]#[2])
    
    describe
    Best
    Daniel

    Comment


    • #3
      That worked great. I'm going to have to study it a bit to see what's going on.

      Comment

      Working...
      X