Announcement

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

  • Keeping only numbers after the decimal

    I am cleaning someone else's data set, and having trouble with one variable: infant's birth weight. It was recorded as lbs.oz. So, for example, a value of "7.80" means 7lbs 8oz, not 7.8 lbs (which would correspond to 7lbs 12.8 oz). I need to fix this so that, for example, a value of "7.80" means 7.8lbs. I used the command "gen bo_wght_lbs=int(bo_wght)" to create a new variable with the lbs (e.g., the "7"). Now I am at a loss as to how to extrapolate the values after the decimal (e.g., the ".80"). Once I can create a new variable with just the ounces after the decimal point, I can convert it to pounds and combine the two variables together into one variable for lbs. Thanks in advance.

  • #2
    Code:
    clear
    input weirdweight
    7.8
    end
    gen lbs = floor(weirdweight)
    gen oz = mod(weirdweight,1)*10
    gen realweight = lbs * 0.45359237 + 0.0283495231 * oz
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      If you have 7.1 does that mean 7lbs and 1 oz or 7lbs and 10oz (since there are 16oz in lbs)? A consistent scheme like that would mean 7lbs and 8oz would be coded as 7.08 and not 7.8. (Anyone need any convincing metric is king when you want to work with decimal numbers?)
      Last edited by Maarten Buis; 28 Apr 2022, 02:16.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Originally posted by Maarten Buis View Post
        If you have 7.1 does that mean 7lbs and 1 oz or 7lbs and 10oz (since there are 16oz in lbs)? A consistent scheme like that would mean 7lbs and 8oz would be coded as 7.08 and not 7.8. (Anyone need any convincing metric is king when you want to work with decimal numbers?)
        Ugh I hadn't even thought of that. What a pain this data set is. I agree with you about metric. Thank you for pointing this out.

        Comment

        Working...
        X