Announcement

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

  • Some GPS coordinates not responsive

    Hello Stata community

    I have GPS coordinates, where some coordinates have latitude and longitude values of 0.000000.
    I want to replace these values as missing, so I use the command

    replace lat = . if lat == 0.000000

    However, 0 changes are made, even when these values are present within the lat variable. Other commands are also unresponsive to these values, such as 'browse'. However, it is possible to control+f search for these values when I browse without conditioning on them.

    Does anyone know why these values might be acting in this way and how I can circumvent this issue?

    Thanks!

  • #2
    Numbers with decimals in them, that is, ones stored as "floating point" values, cannot generally be represented exactly by computers. Consequently, what appears to you as 0.000000 might actually be stored in Stata as something like 0.000001. See -help precision-.

    The solution is to adhere to the old computing maxim "Never compare floating numbers for exact equality." In your case, you might instead try something like:
    Code:
    replace lat = . if lat < 0.0001
    // Or, perhaps
    replace lat = . if abs(lat) < 0.0001
    Last edited by Mike Lacy; 31 Oct 2024, 09:40.

    Comment


    • #3
      Thank you for the advice, Mike! I thought I was going crazy, but your solution worked well!

      Comment

      Working...
      X