Announcement

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

  • Creating indicator variables from multiple categorical variable

    Hello,

    I wanted to create an indicator variable combining two or more categorical variable. So for one of my variables i want to combine the variable gender (female=1 and male=0) and race (white=1, black=2, Hispanic=3 and other=4) to create 12 variables. Generally, when i create indicator variables using one categorical variable, i usually do one of the three options: manually generate variable or tabulate with generate ( ) or make a loop with the generate command. I tried to do this using 2 variables using the second or third method, but i kept getting an error from STATA. Is there an easy way to generate indicator variables using 2 or more categorical variables?

  • #2
    I don't see how you expect to get 12 variables out of 2*4=8; at any rate, the easiest way is probably to use -egen- with the "group" function to get one variable with all existing combinations; if you want to use this in an analysis, you should probably stop there and use factor variable notation; see
    Code:
    help egen
    help fvvarlist
    added in edit: if you then really want the set of indicator variables, you can use -tab-, with the generate option;
    note also for the above that, with -egen- you may well want the "label" option
    Code:
    help tab
    Last edited by Rich Goldstein; 20 May 2019, 14:25.

    Comment


    • #3
      Sorry, i meant to say 8! But yes i used -egen- with group and that seemed to work. Thank you so much, Rich!

      Comment

      Working...
      X