Announcement

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

  • variable labelling

    Hi
    Can I label variable multiple times with a single command. I have many variables that it requires time to do them one by one. Particularly, I need each varname ended in 3 to be labelled Visit3 varname, any var name ended in 2 to be labbelled as visit2 varname etc

  • #2
    The following does what I think you want. Because I lacked a good data example on which to test it, there might be mistakes.
    Code:
    // Example data
    clear
    input x2 y z1 q3
    1 1 1 1
    end
    // Start here
    ds
    foreach v of varlist `r(varlist)' {
       forval num = 1/3  { // assume 3 possible visit numbers for illustration
          if substr("`v'", -1, 1) == "`num'" {
             label var `v' "Visit`num' `v'"
          }
       }
    }
    desc // inspect the result

    Comment

    Working...
    X