Announcement

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

  • Adding Prefix to all my variables except two of them

    I wanted to add the prefix, say "x" , to all of my variables except two, lets say "var1" and "var2". How can I do that?

  • #2
    I suspect it would be easier to add x to all variable names and then rename the two you didn't want to rename. Something like

    Code:
    ren * x*
    ren xvar1 var1
    ren xvar2 var2
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Yes that works. Thank you Richard.

      Comment


      • #4
        Here's the alternative to Richard's straightforward approach, useful when there are a substantial number to avoid renaming (although my example shows it with just 2).
        Code:
        sysuse auto, clear
        local same make price
        unab allvars : *
        local change : list allvars - same
        rename (`change') (x=)

        Comment


        • #5
          Here's another way:
          Code:
          quietly ds var1 var2, not
          rename (`r(varlist)') x=

          Comment

          Working...
          X