Announcement

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

  • combining categorical variables into one

    Hi,
    I have 5 variables SexFemale_1, SexAnon_1, SexIDU_1, SexIntoxHigh_1, ExcSex_1 with responses "yes" or 'no" and I want to combine them into 1 variable non_MSM with all the yes together and all the no together. I need help since am new to stata. I used the egen command but don't know if this is correct

    I used egen non_MSM = rowmax (SexFemale_1, SexAnon_1, SexIDU_1, SexIntoxHigh_1, ExcSex_1)
    tab non_MSM

  • #2
    I'm afraid you need to be clearer in how you want to construct the joint variable -- should it take the value 1 when all the component variables are 1? should it take the value 1 when any of them are 1? should it count the number of component variables that are 1?

    The egen command with rowmax will give you a variable that takes the value 1 if any of the component binary variables are 1, and zero if all of them are zero. However, when you specify the component variables, you are specifying a variable list, and you cannot separate those with commas. Separate them with just spaces instead:

    Code:
    egen non_MSM = rowmax(SexFemale_1 SexAnon_1 SexIDU_1 SexIntoxHigh_1 ExcSex_1)
    Also see
    Code:
    help varlist
    Last edited by Hemanshu Kumar; 05 Oct 2022, 19:01.

    Comment


    • #3
      Thank you so much!

      Comment

      Working...
      X