Announcement

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

  • How to calculate new variable using formula entailing other variables

    Hi,
    I am trying to calculate eGFR with the MDRD forumula: Estimated GFR = 186 x (Creatinine / 88.4) -1.154 x (Age) -0.203 x (0.742 if female) x (1.210 if black)

    I have all the necessary variables (Creatinine, age, gender (female=2), ethnic background (black=4) ) but cannot manage to do it with the gen var command when it comes to doing the extra multiplications for females and individuals of colour, could you assist with some ideas please?
    gen estimatedgfr= 186 *(creatinine/88.4)-1.1154*(age) -0.203* (0.742 if gender=2) x (1.210 if ethnicbackground=4) does not work.

    Best wishes,
    Lena

  • #2
    I am not familiar with this equation but as a matter of general Stata technique (see help operators)

    multiplication is coded with
    Code:
     *
    not x

    a power like age raised to the power -0.203 would need to be
    Code:
    age^(-0.203)
    0.742 if gender = 2 would be, I guess, as we're multiplying
    Code:
    cond(gender == 2, 0.742, 1)

    Comment


    • #3
      Hi sorry I need to correct the formula, thank you Nick for recognising and sending the code!

      Estimated GFR = 186 x (Creatinine / 88.4) ^-1.154 x (Age)^ -0.203 x (0.742 if female) x (1.210 if black)
      unfortunately the cond code for the condition of being female or of ethnic background brings an error message as invalid (r198),

      Comment


      • #4
        I can't comment hepfully without seeing the exact code you typed. I may also need to ask about your data.

        Comment


        • #5
          Hi, I hope this shows up as the code I used:

          code:
          gen egfr= 186 *(creatinine/88.4)^-1.1154*(age)^-0.203* cond(gender == 2, 0.742, 1)* cond(ethnicbackground == 4, 1.210, 1),

          I realised I had a typo which caused the error message. I ran it again and got some results, so thank you Nick all the above advice worked!

          Many thanks
          Lena

          Comment

          Working...
          X