Announcement

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

  • Label variables ascending order

    Hi,

    I am using Stata 17.

    I have 61 variables in my dataset (q1-q61). I would like to label them as follows:

    q1 - item01
    q2 - item02
    .
    .
    .
    q61 - item61

    How would you suggest doing this? Of course, I could repeat the same "label variable" command 61 times, but if there is a quicker way, I would prefer to learn it.

    Thanks in advance for all of your help.

  • #2
    Use a simple loop:
    Code:
    foreach n of numlist 1/61 {
     if `n'<10 {
       label variable q`n' item0`n'
     }
     else {
       label variable q`n' item`n'
     }
    }

    Comment


    • #3
      Code:
      forvalues i = 1/61 {
          local number : display %02.0f `i'
          label variable q`i' "item`number'"
      }
      I find these labels pretty meaningless; they add no information over what is already present in the variable names.

      Comment


      • #4
        I agree with daniel klein For more discussion of his method for looping see https://www.stata-journal.com/articl...article=pr0051

        Comment


        • #5
          Thank you very much! Your comments were very helpful!

          Comment

          Working...
          X