Announcement

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

  • Creating a numeric variable that has a different formula for each gender

    Greetings,

    I want to generate the Visceral Adiposity Index (VAI) in Stata. The formula for this index varies by gender:
    VAI (for men) = (WC(cm)/(39.68+(1.88*BMI) *(TG/1.03) *(1.31/HDL)
    VAI (for women) = (WC(cm)/(36.58+(BMI *1.89) *(TG/0.81) *(1.52/ HDL)

    Ps: WC= waist circumference, BMI=Body mass index, TG=triglycerides, HDL= high density lipoprotein

    In my dataset, I have the variable sex (0=men / 1=women). The rest of the variables are labeled as above.
    What would be the Stata command to create a unique variable for VAI considering the different formulas (by gender)?

    Thanks in advance

  • #2
    Code:
    gen VAI = cond(gender==0,(WC/(39.68+(1.88*BMI)))*(TG/1.03)*(1.31/HDL),(WC/(36.58+(BMI *1.89))) *(TG/0.81) *(1.52/ HDL))

    Comment


    • #3
      It does not work. I got a "Type mismatch" message. Maybe it is because (gender==1) is missing?

      Comment


      • #4
        That means one of the variables (gender, WC, BMI, TG, HDL) is in nonnumeric format. Please share a data example by using the -dataex- command and pasting the output into the forum. That will make giving an answer that works with your data easier.

        Comment


        • #5
          Dear Ali, you were right. I forgot to destring the variable. Now it works. Thank you very much!

          Comment

          Working...
          X