Announcement

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

  • Rounding issues when using weights (pw)

    I am puzzled by something that seems to be a minor issue. I assign weights in Stata (pw) and for some reasons Stata displays a number which is slightly different 12.14999999999 than the 12.15 it should show (original data is (.65*12.5) + (.35 *11.5). I did not think the 12.14999999 would have been a problem but when I round the number it rounds this specific datapoint to 12.1 rather than 12.2 ( and the issue is not with rounding up or down as all the other datapoints are rounded up). Thank you for any insight.

  • #2
    This is a precision issue. It is mathematically impossible to represent 12.15 exactly as a binary number with a finite number of bits. (Just as it is impossible to represent 1/3 exactly as a decimal number with a finite number of digits.) So the number that Stata is actually storing is neither 12.1499999999999 nor 12.15 but some binary number that is the best possible approximation to 12.15 within the limit of the number of bits available, and which, when displayed with a large number of decimal places, looks like 12.1499999999999. See -help precision- and sources linked therein for more information about this general phenomenon.

    And, of course, the correct round to 2 decimal places of 12.149999999999, is indeed, 12.1, not 12.2

    Why are you rounding the weights in the first place? Why impose additional rounding error on top of the unavoidable discrepancies resulting from finite precision? That's a self-inflicted wound. Just leave the weights alone, don't round them--that just makes the errors worse. It is inconceivable that the error you get from having 12.149999999999999 instead of 12.15 as a weight in your analysis will be of any practical importance. It is almost certainly many orders of magnitude smaller than other sources of error in your data.

    Comment


    • #3
      Thanks a lot for the response. I understand that it is a small issue but very important for what I am doing. I am not rounding the weights, the weights are .65 and .35 but once we do the basic math and apply the weights to the data the result should be 12.15 ( which is what shows when you click on the datapoint) and not the 12.149999 Stata is displaying. I do not have a problem with the way Stata displays it if it uses the correct 12.15 when it rounds. I understand that if you round up 12.14999 once you get 12.15 - but if you round up 12.15 you get 12.2 so stata seems to be rounding that 12.14999 which is a problem for what i need this data for, as the correct data is 12.15.

      Comment


      • #4
        Are you saying that the difference in a result between 12.149999 and 12.15 is meaningful and important? That's an error of less than 1 part in 1 million. What is the context here? What makes you think that the 12.15 is really exactly 12.15 and not off by more than 1 part in 1 million for all sorts of reasons? I find that claim very difficult to believe.

        And I hasten to point out that .65 and .35, like 12.15, cannot be exactly represented in binary.

        And when you round numbers that are already rounded or truncated, it is mathematically inevitable that you amplify errors in many cases.

        Comment

        Working...
        X