Announcement

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

  • combination variable and display the name

    hello

    I work on 9 symptoms of a disease. these are dummy variables- If someone has a symptom 1, otherwise 0. I need to make a combination of 9C2 to present dual symptoms. If I want to show the name of symptoms only if they are 1, how to make it?

    For example,

    Symptom A =1 and Symptom B= 1 but other symptoms are zero.

    Then I want to only show "symptom A" & 'symptom B".

    Many thanks in advance for your help!

    BW
    Kim

  • #2
    "show" in what context? -list-? Maybe you are looking for.-file write- but I can't really tell.

    Comment


    • #3
      You did not show any example data, so I have made a demonstration data set to illustrate the approach. Much of this code depends specifically on the names of the individual symptom variables. Following your lead in #1, I have called them symptom_A, symptom_B,..., symptom_I. But you will need to adapt/revise the code if the real variable names are different. Apart from that, the way to generate all 9C2 combinations would be effectively the same.
      Code:
      //    CREATE A DEMONSTRATION DATA SET
      clear*
      
      set obs 100
      set seed 1234
      forvalues i = 1/9 {
          gen byte symptom_`:word `i' of `c(ALPHA)'' = runiformint(0, 1)
      }
      
      //    SOLVE THE PROBLEM
      forvalues i = 1/9 {
          local ialpha: word `i' of `c(ALPHA)'
          forvalues j = `=`i'+1'/9 {
              local jalpha: word `j' of `c(ALPHA)'
              gen byte symptoms_`ialpha'`jalpha' = symptom_`ialpha' == 1 ///
                  & symptom_`jalpha' == 1
          }
      }

      Comment


      • #4
        Dear Clyde,

        Thank you very much indeed for your kind explanation. I can definitely apply this to my specific data. Thank you again!
        BW
        kim

        Comment

        Working...
        X