Announcement

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

  • How to label variables taking last part of variable names

    I have numerous variables. For example, I have variables var1, var3, var6, var30. And I want to label those as
    temp1, temp3, temp6, temp30 accordingly.

    There is no pattern in the number at the end, so I cannot use forval..
    Is there a way to do such a task?

  • #2
    Code:
    rename var* temp*
    you might want to check out -help rename group-

    Comment


    • #3
      Originally posted by Øyvind Snilsberg View Post
      Code:
      rename var* temp*
      you might want to check out -help rename group-
      Thank you! But I am looking to label variables, not rename..

      For example I want to label var1 as "var_t_1" and label var30 as "var_t_30"

      Comment


      • #4
        Code:
        foreach v of varlist  var1 var3 var6 var30 {
            
            lab var `v' `=subinstr("`v'","var","var_t_",1)'
        }

        Comment

        Working...
        X