Announcement

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

  • Label variable values using loop / label variable values using a local list

    I want to define the value label of the variable wave in a panel dataset.
    For this, I define the values:
    HTML Code:
    la        define     wavel 1 "Wave 1" 2 "Wave 2" 3 "Wave 3" 4 "Wave 4" 5 "Wave 5"
    la         values    wave wavel  
    I want to write this flexibly, such that the code can be adapted to other HRS-type surveys.
    For this, I do
    HTML Code:
    la         define         wavel `wavelabellist'
    Where I want the local -wavelabellist- to be defined as " 1 "Wave 1" 2 "Wave 2" 3 "Wave 3" 4 "Wave 4" 5 "Wave 5" ".
    However, this combines a set of numbers, 1,2,3,4,5 with a set of strings "wave 1" ... "wave 5".
    I tried the following:
    HTML Code:
    loc wavelast "5"
        forvalues i=1/`wavelast'{
        loc wavelabellist `" `wavelabellist' `i' "wave"      "' 
        }
        di "`wavelabellist'"    
    But this does not work, because wavelabellist seems to end the local at the first ", i.e. before the first Wave.
    Is it possible to combine 1 and "wave" into a local, whereby the quotation (") shall be kept into the local?

  • #2
    Code:
    loc wavelast "5"
    forvalues i=1/`wavelast'{
        loc wavelabellist `wavelabellist' `i' "wave `i'"
    }
    di `"`wavelabellist'"'
    Added: There are two problems with your original code. The first, which you did not notice, or at least did not mention, is that the local macro it creates looks like
    Code:
    1 "wave"       2 "wave"       3 "wave"       4 "wave"       5 "wave"
    without the number as part of the label.

    The second, which is the one you wrote about, is actually just a problem with your -display- command, not with the creation of local macro wavelabellist. Because `wavelabellist' contains quotes (" ") within it, in order to -display- it you have to surround it by compound double quotes (`" "'). You cannot nest simple quotes inside simple quotes.
    Last edited by Clyde Schechter; 09 Jul 2023, 10:09.

    Comment

    Working...
    X