Announcement

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

  • Extracting label for a specific value of a variable

    Hi

    I have a very basic question. I am working on a loop and inside the loop I want to extract the label attached to a particular value of a variable and store it in a local variable so that I can use it in naming of variables.

    Sample Code :

    Code:
     
       
    clear
    set obs 10
    gen var = mod(_n, 3) 
     label define lab 0 "India" 1 "Australia" 2 "Myanmar"   
     label values var lab


    In the above case, lets say, I want to extract the name of the country if var = = 2

    How can that be done in Stata.

    Thanks.

  • #2
    Code:
    clear
    set obs 10
    gen var = mod(_n, 3) 
    label define lab 0 "India" 1 "Australia" 2 "Myanmar"   
    label values var lab
    local wanted: label lab 2
    display "`wanted'"

    Comment


    • #3
      Also see elabel (SSC).

      Code:
      elabel list (var)
      return list
      
      elabel list lab iff # == 2
      return list

      Comment

      Working...
      X