Announcement

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

  • Command to store list of variables with value labels

    I was looking for a command (or package) which will store a list of variables with value labels so I can refer to them later in a loop. Thanks.

  • #2
    Code:
    help ds
    search findname, all

    Comment


    • #3
      Andrew, I'm not sure if you mean you want to store only those variables with value labels (Nick's suggestion in #2 addresses this), OR, you want to store a list of variables along with their value labels. If the latter, once you store the variable names in a macro (with ds , for example) you can then access the variable label with the extended macro function variable label. Each example shows a different way to input the list of variables, but all use the extended macro variable label to store the variable label.

      Code:
      *Identify and store a list of variables with ds
      
      ds, has(varlabel)
      
      foreach v of varlist `r(varlist)' {
           local vlab : variable label `v'
           di "The label for variable `v' is `vlab'"
          }
      
      
      *OR provide a varlist in your loop
      
      foreach v of varlist x1 x10-x15 {
           local vlab : variable label `v'
           di "The label for variable `v' is `vlab'"
          }
      
      
      *OR create a macro containing a list of variable names
      
      local vlist a b c d e f g h i j k
      
      foreach v of `vlist' {
           local vlab : variable label `v'
           di "The label for variable `v' is `vlab'"
          }


      Stata/MP 14.1 (64-bit x86-64)
      Revision 19 May 2016
      Win 8.1

      Comment

      Working...
      X