Announcement

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

  • Generate new variables for each word in a list

    Hello,

    I would like to generate new variables take take the value of 0 for each of words in a list. The below code does not give any error, but it also does not produce any variables. Does anyone see what I'm doing wrong? Thank you very much.

    local wordlist "specialist manager sales engineer assistant accounting"
    foreach var in `wordist'{
    g my`var'=0
    }

  • #2
    wordist is a typo for wordlist.

    It is not illegal to refer to a local macro that doesn't exist. Here a macro that doesn't exist and an empty list are one and the same, so as you observed, Stata did nothing.

    Sometimes the consequence of an empty list is syntax that is illegal, but that isn't the case here.

    Any way, just fix the typo.

    By the way, the use of a local macro is neither essential nor helpful here, as the direct syntax starting

    Code:
    foreach var in specialist manager sales engineer assistant accounting {
    would have been fine.

    Comment


    • #3
      That works. Thank you!

      Comment

      Working...
      X