Announcement

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

  • Help merging feet and inches into one variable

    Hello I need to calculate BMI in a dataset, however my measurements of height (in feet) and weight (in stone) have been measured across two variables each (feet+inches and stones+pounds).

    I'd like to create a new variable to so that height and weight are each displayed as a single variable (e.g. 5.4 for height and 10.0 for weight), so that I can then convert these into metres and kgs.

    HEIGHT HEIGHTM HEIGHTFT HEIGHTINCH WEIGHT WEIGHTKG WEIGHTST WEIGHTSP
    Feet 5 4 Stone 10 0
    Metre 1.82 Kilog 83
    Metre 1.77 Kilog 63


    A bit of a stata newbie here and have been unable to work this out online!
    Last edited by Elena Marcus; 13 Sep 2022, 03:54.

  • #2
    You can work in say inches, so

    Code:
    gen wanted1 = inches + 12 * feet
    or in feet

    Code:
    gen wanted2 = feet + inches/12
    with similar advice for stones and pounds, where the conversion factor is 14 or its reciprocal. Concatenation is not the answer as neither factor is 10 or 1/10.

    Comment


    • #3
      Working with inches and pounds

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str5 height float heightm byte(heightft heightinch) str5 weight byte(weightkg weightst weightsp)
      "Feet"     . 5 4 "Stone"  . 10 0
      "Metre" 1.82 . . "Kilog" 83  . .
      "Metre" 1.77 . . "Kilog" 63  . .
      end
      
      gen wanted1= cond(missing(heightm), ((heightft*12)+ heightinch)/39.3701, heightm)
      gen wanted2= cond(missing(weightkg), ((weightst*14)+ weightsp)*0.453592, weightkg)
      Res.:

      Code:
      . l
      
           +--------------------------------------------------------------------------------------------------------+
           | height   heightm   heightft   height~h   weight   weightkg   weightst   weightsp    wanted1    wanted2 |
           |--------------------------------------------------------------------------------------------------------|
        1. |   Feet         .          5          4    Stone          .         10          0   1.625599   63.50288 |
        2. |  Metre      1.82          .          .    Kilog         83          .          .       1.82         83 |
        3. |  Metre      1.77          .          .    Kilog         63          .          .       1.77         63 |
           +--------------------------------------------------------------------------------------------------------+

      Comment


      • #4
        perfect, thank you!

        Comment

        Working...
        X