Announcement

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

  • Selecting varlist based on value of variable in foreach loop

    Hi,

    I have to do a procedure for multiple subsets of data repeatedly. I defined three variable lists,
    Code:
    A_var B_var C_var
    . Based on the value of my iterable, I then want to select the variable list.
    However, I am struggling with implementing this.

    Code:
    foreach method in A B C {
      if `method' == A {
        vl create local_varlist = A_var
      }
      ...
      vl drop local_varlist
    }
    Some insights as to how this ought to work would be greatly appreciated!

    Thanks,
    Alex

  • #2
    I guess

    Code:
     
     if `method' == A {
    needs to be
    Code:
      
     if "`method'" == "A" {
    and in the rest of your code you need to distinguish (a) literal strings that are or are not variable names and (b) local macro names and their contents.

    Comment


    • #3
      Awesome, thanks -- that did the trick! I suppose the intuition is that `method' is a string and thus the comparison needs to be between two strings, and as such, done explicitly.

      Comment

      Working...
      X