Announcement

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

  • inlist more than 10 string variables

    I am using the command keep if inlist (county, "a", "b", "c", etc..........) with almost 20 string values in the brackets.

    I dont want to separate them into 2 or 3 smaller groups then do the append nor do I want to generate a group identifier and work with the numeric values from there....

    Is there a more efficient way to tackle this with local macros or loop?

  • #2
    why not just use more than one "inlist()" with the or symbol , "|", between them? e.g.
    Code:
    keep if inlist(country, "a","b") | inlist(country("c","d")

    Comment


    • #3
      You did not describe what you want to do exactly, but you could define a local list and loop over the words of that list. As in:
      Code:
      local counties "a b c d e"
      local n : word count `counties'
      forvalues i = 1(1)`n'     {
             local str = word("`counties'", `i') 
             <syntax what to do with `str'>
      }
      Two remarks:
      - mind the double quotes around the local macro `counties' in line 4 of the above syntax
      - This works as long as the entries of the list are separated by blanks, meaning that no entry has a blank (not like New York). If this is the case, you have to use and define a special character which separates the words of the list.

      Comment

      Working...
      X