Announcement

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

  • condition if var=number with two decimal place

    Hi,

    I have a variable displayed like below, It is of type float and format %9.0g. There are two numbers that occurs with more frequency than others, 620.32 and 685.62. I would like to generate a new variable that equals to 1 if var1 takes 620.32 or 685.62. However these numbers actually have more precision than what is displayed. I am struggling with how to do this in a easy way (my current code is gen category=1 if inrange(var1,620.31, 620.33) | inrange(var1,685.61, 685.63)). I tried rounding and recasting the variable as double but the precision doesn't seem to decrease. It would be great if you can suggest a quick way to do this. Thanks!

    var1
    rate_06
    620.32
    620.32
    620.32
    620.32
    620.36
    620.54
    620.54
    620.57
    685.62
    685.62
    685.62
    685.62


    Best,
    Angela





  • #2
    Code:
    h precision
    which both explains the issue and offers solutions

    Comment


    • #3
      An old maxim of computer management of data was and is "Never compare floating point numbers for exact quality." (This was on the wall of a university computer room when I was a student, and I had to struggle with a situation like the current one before I understood it.) I suppose there are situations in which this maxim could or should safely be violated.

      Comment


      • #4
        Thanks Rich and Mike!

        Comment

        Working...
        X