Announcement

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

  • local list from variables

    Hi Statalists,

    I am trying to create a list from variables, that I can loop through. But the script I wrote only actions the first variable in the list.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str2 id
    "a"
    "b"
    "c"
    "d"
    "e"
    "f"
    "g"
    "h"
    "i"
    "j"
    "k"
    end
    
    local idlist = id
    
    foreach i in `idlist' {
        display "`i'"
    }
    How do I make the loop go over all variables in list?

    Thanks so much!


  • #2
    Read variables as observations in #1.

    Code:
    levelsof id, local(idlist)

    Comment


    • #3
      Hi Andrew, thank you very much for your solution and quick reply! That works perfectly (also in the actual script, which of course was not the above). I will read about levelsof to actually understand why this works.

      Thanks again!!

      Comment

      Working...
      X