Announcement

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

  • Creating dummy variables for each name in a variable

    Hello, I have a variable that contains names of around 50 towns.
    I want to create a dummy variable for each town.
    Is there an efficient way to do this? I want to avoid manually writing a code for each dummy (e.g. gen chicago_dummy = 1 if city == "chicago" or something).

  • #2
    Use tabulate with the generate() option specifying the prefix of your indicator variables (also called dummy variables), see help tabulate.

    Depending on why you want to do this: Note that often factor variable notation in regression models (see help factor variable) is to be preferred, especially if you want to use post-estimation commands such as margins.

    Comment


    • #3
      Tabulate county, generate(dummy_county) worked! Thank you.

      Comment

      Working...
      X