Announcement

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

  • How to combine variables (medications) into one variable

    Hi all, hope someone can help! Really struggling.

    I am analysing a dataset including medications for the treatment of Raynaud's phenemenon.

    I have three variables (Medication 1, Medication 2, Medication 3).

    That is, some patients maybe on 0 to three medications.

    I am trying to create a variable that will allow me have 'Total medications'.

    I have tried reshaping the data (long). However, this messes up the rest of the data (all the patients have a unique study ID) and this works. However, for example, I now have three times the total number of the variable 'Age' (presumably duplicated).

    Any help gratefully accepted.

    Mike


  • #2
    you don't tell us what these variables look like, cut -egen- with the rownonmiss function should help

    Rich

    Comment


    • #3
      Mike,

      If your medication variables are numeric(0,1), you can just add them. If you want missing values to count as zeros, use egen with rowtotal().

      If your medication variables are string and take only one value, you can use egen with rownonmiss(), as suggested above.

      If your medication variables are string and take on more then one value (e.g., YES or NO), you can do (among other things):

      Code:
      gen totmeds=0
      forvalues x=1/3 {
        replace totmeds=totmeds+1 if med`x'=="YES"
      }
      Regards,
      Joe

      Comment

      Working...
      X