Announcement

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

  • Problem with merge because of -round- function

    Hello,

    I'm trying to merge two datasets using GPS data (latitude and longitude) as ID. On the first dataset, the GPS data is like this : -1.467934012413. On the other one, like this : -1.5.

    In order to be able to merge the datasets, i tried to round the observations from the first dataset using:

    Code:
    replace lon_mod=round(lon_mod, 0.1)
    replace lat_mod=round(lat_mod, 0.1)
    At first I thought it worked fine, but when I tried to perform the merge, I realized that observations that should have matched didn't.

    I think the problem comes from the round function, because when I use dataex, it shows that some observations are not quite rounded. I read on another thread that it was a common phenomen and a matter of format, but I couldn't find how to fix the problem in my case.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(lat_mod lon_mod)
                   -1.5 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001 29.900000000000002
    -1.4000000000000001                 30
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               29.8
                   -1.3               30.1
                   -1.3               30.1
    end
    How can I make these observations perfectly rounded si I can perform the merge?

    Thanks,

    Mathias Imboden

  • #2
    There is probably a "light path" to fix this. Here is what I think a "dark" one. Change them into string:

    Code:
    tostring lat_mod, gen(lats) force
    tostring lon_mod, gen(lons) force
    Then, merge by the string lat and long.

    Comment


    • #3
      Thank you, I did what you suggested and it worked fine.

      Comment

      Working...
      X