Announcement

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

  • Why can't I refer to an existing value in stata?

    Dear Stata users,

    I just encountered a weird issue where I cannot refer to a value that exists in my dataset. Please see below the picture.
    Click image for larger version

Name:	Issue.jpg
Views:	2
Size:	95.7 KB
ID:	1753076


    Any help and suggestions will be greatly appreciated.
    Thank you so much!

    Best,
    Tiange

  • #2
    This is a precision issue arising from the fact that Stata at machine level works in binary. A number like 0.1 has no exact binary representation.

    Long story short, you need to grapple with the different between double and float, as here

    Code:
    . clear
    
    . set obs 1
    Number of observations (_N) was 0, now 1.
    
    . gen ave_lob = 0.1
    
    . list if ave_lob == 0.1
    
    . l
    
         +---------+
         | ave_lob |
         |---------|
      1. |      .1 |
         +---------+
    
    . list if ave_lob == float(0.1)
    
         +---------+
         | ave_lob |
         |---------|
      1. |      .1 |
         +---------+
    .The keyword is precision and a search of Stata using that keyword will point to several blog posts, short papers and other resources on the topic.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      This is a precision issue arising from the fact that Stata at machine level works in binary. A number like 0.1 has no exact binary representation.

      Long story short, you need to grapple with the different between double and float, as here

      Code:
      . clear
      
      . set obs 1
      Number of observations (_N) was 0, now 1.
      
      . gen ave_lob = 0.1
      
      . list if ave_lob == 0.1
      
      . l
      
      +---------+
      | ave_lob |
      |---------|
      1. | .1 |
      +---------+
      
      . list if ave_lob == float(0.1)
      
      +---------+
      | ave_lob |
      |---------|
      1. | .1 |
      +---------+
      .The keyword is precision and a search of Stata using that keyword will point to several blog posts, short papers and other resources on the topic.
      Thank you soooo much, Nick!

      It is super helpful!

      Best,
      Tiange

      Comment

      Working...
      X