Announcement

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

  • How to generate new variable that contains only males and BMI above 25

    Hey guys,

    I am new to STATA and I want to generate a new variable that contains only males and a BMI of over 25.

    I have variables gender as binary (0= males and 1=females)

    BMI I also have as a seperate variable.

    My best guess is to make to use the gen command in combination with if, but I am not sure.


    Any help would be highly appreciated!

    Thanks in advance

  • #2
    You probably don't need a new variable at all as

    Code:
    if gender == 0 & BMI > 25
    may be enough as a qualifier on whatever you want to do, or sometimes

    Code:
    if gender == 0 & BMI > 25 & BMI < .
    but by the same token

    Code:
    gen BMI2 = BMI if gender == 0 & BMI > 25
    is what you're asking for. See

    Code:
    help if
    I recommend renaming gender as female following the principle that indicator variables are best named for the state coded 1.

    Please see also https://www.statalist.org/forums/help#spelling

    Comment


    • #3
      Great it worked! Thanks Nick!


      WHat do you mean with Ï probably don't need a new variable at al

      Comment


      • #4
        I mean what I say. So, for example, if you had a variable whatever then


        Code:
        summarize whatever if gender == 0 & BMI > 25
        doesn't need a new variable. If you give more details on why you think you need a new variable, more could probably be said.

        Comment


        • #5
          Ah ok.

          No I would like a total new variable because I would like to compare this group of males with a higher BMI with heart chamber dimensions. So creating a new variable would allow me to look into a relationship with the sizes of their right atrium.

          I can do this with the "table1" code.

          Comment

          Working...
          X