Announcement

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

  • Q: how to combine non-mutually exclusive variables into one categorical variable in Stata

    The non-mutually exclusive variables:
    *cognition: (Yes=1, No=0)
    *Frailty: (Yes=1, No=0)
    *Depression (Yes=1, No=0)
    *Anxiety (Yes=1, No=0)
    *ADL_disability (Yes=1, No=0)
    *IADL_disability (Yes=1, No=0)

    I want to generate a new categorical variable inlcuding these several conditions:
    gen synCondition:
    0=none of these condtions
    1=cognition alone or combined with other conditions
    2=Frailty alone or combined with other conditions
    3=Depression alone or combined with other conditions
    4=Anxiety alone or combined with other conditions
    5=ADL disability alone or combined with other conditions
    6=ADL disability alone or combined with other conditions

    I can not do like this:
    gen synCondition=1 if cognition==1
    replace synCondition=2 if Frailty==1
    replace synCondition=3 if Depression==1
    .....
    Because in this way, the latter one replace the common condition with former one.

    I think this question is very like the question: gen a new multi-categorical variable using non-mutually exclusive responses
    But my goal is generate one categorical variable and make a bar chart (one graph which only show the percent of code=0, 1, 2, 3, 4, 5, and 6)

    Thanks

  • #2
    I don't think I understand. Presumably for the graph to make sense, you want the categories 0-6 to be mutually exclusive. But the way you are defining them, they do not seem to be. For instance, if a person has Frailty and Depression, should that be coded as 1 or 2?

    And if not, why not just create a bar graph with the individual variables you have for each condition? The only thing missing would be a bar for "none of these conditions", but it is easy to create a separate variable for that.

    Comment


    • #3
      See https://www.stata-journal.com/articl...article=dm0034 for ways to do this, mostly egen, group() or concat().

      Otherwise I agree as usual with Hemanshu Kumar The clause "and other conditions" bites hard, as it would you lead you to impossible choices for every possible positive value of your new variable. The only clearcut case is 0 for none of these conditions.

      6 binary indicators imply 64 possible subsets, all of which seem likely in a large dataset.

      Comment

      Working...
      X