Announcement

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

  • How to generate a new binary variable based on individuals having 2 or more of other risk factors

    I would like to create a variable based on individuals being classified as "high risk" or "low risk".

    This risk stratification would be based on individuals having 2 or more of certain other characteristics or risk factors, such as sex, age, education etc.

    Ordinarily if it was looking at 1 or more of any risk factor, my practice would be to generate a new variable and just "replace as I go" with each old variable in turn.

    However, how is it possible to do this if an individual is classified as "high risk" based on having 2 or more of a series of variables?

    I can't seem to readily find this on this forum or elsewhere online.

  • #2
    you don't say enough for a complete answer but here is a sketch:
    1. for each such variable, generate a new variable that is equal to 1 if "high" for that variable and 0 otherwise; then
    2. use -egen- with the "rowtotal" function to calculate the number of "high's"; if that total is 2 or more, make your new variable high and make it low if it less than 2
    see
    Code:
    FAQ
    help egen
    added in edit: then, of course, you can drop all the interim variables you created if they are no longer needed (though you might want to retain the pen-ultimate variable that adds the number of "high's"

    Comment


    • #3
      I think you are saying that your normal practice would be something like the following.
      Code:
      generate atrisk = 0
      replace atrisk = 1 if sex==2
      replace atrisk = 1 if smoker==1
      replace atrisk = 1 if education < 12
      ...
      which would leave atrisk as either 1 - if any of the risk factors were met - or 0 - if none were.

      Perhps what you seek is
      Code:
      generate atrisk = 0
      replace atrisk = atrisk+1 if sex==2
      replace atrisk = atrisk+1 if smoker==1
      replace atrisk = atrisk+1 if education < 12
      ...
      replace atrisk = atrisk>=2
      which would leave atrisk as either 1 - if two or more of the risk factors were met - or 0 - if one or none were.

      Comment

      Working...
      X