Announcement

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

  • #16
    Dear Helen,

    Thanks for your post. It's a bit difficult to say what's going on without knowing more about your database.
    I suspect that you're using an old version of the command, in which temporary variables were kept for every iteration until the end. Current version is 2.5 (released 30jan2020). Could you please check that is the one you're using? If not, please update the command and try again.
    Best,

    Sylvain

    Comment


    • #17
      Hi Helen,

      I ran into the same problem you have described here and found a workaround that might work for you (though I suspect you've moved on by now) or others experiencing this issue.

      How can that be? Is there not enough memory on Stata to run the code through all of the observations?
      I'm currently using Stata/MP 16.0. I tried using compress on my original dataset but no changes were made. Could you maybe tell me, what the problem could be and if it has anything to do witht he georoute command?
      It's possible to run georoute through a loop. Just generate a new variable that breaks up your dataset into numbered sections, then:
      Code:
      forvalues x=1/10 {
      georoute if newvar==`x', hereid(BfSfwSlKMCPHj5WbVJ1g) herecode(bFw1UDZM3Zgc4QM8lyknVg) startad(strt1 zip1 city1 cntry1) endad(strt2 zip2 city2 cntry2) km di(dist) ti(time) co(p1 p2)
      }

      The problem I found with this is that georoute overwrites previous loops, so only keeps time/distance values for the last run iteration of the loop, so:
      Code:
      forvalues x=1/10 {
      preserve keep if newvar==`x' georoute if newvar==`x', hereid(BfSfwSlKMCPHj5WbVJ1g) herecode(bFw1UDZM3Zgc4QM8lyknVg) startad(strt1 zip1 city1 cntry1) endad(strt2 zip2 city2 cntry2) km di(dist) ti(time) co(p1 p2) save temp`x'.dta, replace restore
      }

      And then:
      Code:
      use temp1, clear
      
      forvalues x=2/10 {
      append using temp`x'.dta
      }
      Last edited by Stephen Petersen; 22 Nov 2020, 14:34.

      Comment


      • #18
        Dear Helen, Dear Stephen, Dear all,

        Sorry for this. I thought we had corrected this memory issue in version 2.5 of georoute, but that's not true. The problem is caused by the temporary variables that are created within the loop that starts on line 288 of georoute.ado. Even though the same name is used in every loop, Stata creates a different temporary variable for each iteration, and therefore the memory fills in very quickly. The solution is to move the creation of the temporary variables out of the loop (and to clean the content of these variables at the end of each iteration). To fix the issue, please replace the current lines 287-367 of georoute.ado (version 2.5) by the piece of code reproduced below.

        I also take this opportunity to mention that we are working on a completely updated version of the command that will accommodate a number of options (such as selection of transport mode, time of travel, type of route, ...). We will keep you posted regarding this new version as soon as possible.

        Best regards,

        Sylvain


        Code:
        *Create temporary variables that will be used for insheetjson in following loop
        tempvar temp_x temp_y temp_matchlevel
        qui: gen str240 `temp_x' = ""
        qui: gen str240 `temp_y' = ""
        qui: gen str240 `temp_matchlevel' = ""
        tempvar temp_time temp_distance
        qui: gen str240 `temp_distance' = ""
        qui: gen str240 `temp_time' = ""
        
        local t 0
        forv i = 1/`=_N' {
            if `touse'[`i'] {
                *Add an optional timer
                if "`timer'"=="timer" {
                    local ++t
                    *Pause for 30 seconds every 100th geocoded observation
                    if "`pause'"=="pause" & mod(`t',100)==0 sleep 30000
                    if `t'==1 {
                        di _n(1) _dup(9) as txt "-"
                        di as txt "Geocoding"
                        di _dup(9) as txt "-"
                    }
                    if int(`t'/(`N'/10))>int((`t'-1)/(`N'/10)) di _continue as res " `=int(`t'/(`N'/10))*10'% "
                    if int(`t'/(`N'/100))>int((`t'-1)/(`N'/100)) & int(`t'/(`N'/10))==int((`t'-1)/(`N'/10)) di _continue as res "."
                    if `=int(`t'/(`N'/10))*10'==100 di ""
                }
                *Addresses to xy-coordinates (only if addresses are provided, skipped if xy-coordinates are provided)
                foreach p in start end {
                    if "``p'address'"!="" & !mi(``p'_address'[`i']) {
                        local coords = ``p'_address'[`i']
                        local coords = subinstr("`coords'", ".", "", .)
                        local xy_request = "`xy_url'" + "`coords'" + "`here_key'"
                        local xy_request = subinstr("`xy_request'", " ", "%20", .)
        
                        #d ;
                        qui: insheetjson `temp_x' `temp_y' `temp_matchlevel' using "`xy_request'",
                            columns("Response:View:1:Result:1:Location:DisplayPosition:Latitude"
                                    "Response:View:1:Result:1:Location:DisplayPosition:Longitude"
                                    "Response:View:1:Result:1:MatchCode"
                                    )
                            flatten replace
                        ;
                        #d cr
        
                        local `p'_coord = `temp_x'[1] + "," + `temp_y'[1]
                        if "`coordinates'"!="" & "``p'xy'"=="" {
                            qui: replace ``p''_x = `temp_x'[1] in `i'
                            qui: replace ``p''_y = `temp_y'[1] in `i'
                            qui: replace ``p''_match = `temp_matchlevel'[1] in `i'
                        }
                        if "`coordinates'"=="" & "``p'xy'"=="" {
                            qui: replace ``p'_match' = `temp_matchlevel'[1] in `i'
                        }
                        *Empty temporary variables before next loop
                        qui: replace `tmp_x' = ""
                        qui: replace `tmp_y' = ""
                        qui: replace `tmp_matchlevel' = ""
                    }
                    if "``p'xy'"!="" {
                        local `p'_coord = ``p'_xy'[`i']
                    }
                }
                *xy-coordinates to distance
                if "`start_coord'"!="," & "`end_coord'"!="," {
                    local s = "`start_coord'"
                    local e = "`end_coord'"
                    local route_request = "`route_url'" + "&waypoint0=geo!" + "`s'" + "&waypoint1=geo!" + "`e'" + "&mode=fastest;car;&representation=overview"
        
                    #d ;
                    qui: insheetjson `temp_distance' `temp_time' using "`route_request'",
                        columns("response:route:1:summary:distance"
                                "response:route:1:summary:travelTime"
                        )
                        flatten replace
                    ;
                    #d cr
        
                    if "`km'"=="" {
                        qui: replace `distance' = real(`temp_distance'[1])/1609.344 in `i'
                    }
                    if "`km'"=="km" {
                        qui: replace `distance' = real(`temp_distance'[1])/1000 in `i'
                    }
                    qui: replace `time' = (1/60)*real(`temp_time'[1]) in `i'
                    
                    *Empty temporary variables before next loop
                    qui: replace `tmp_distance' = ""
                    qui: replace `tmp_time' = ""
                }
            }
        }

        Comment


        • #19
          Hello All,

          I just wanted to say that this thread was very helpful when I ran into the exact same issue that Helen described. Georoute is a great package and I am always impressed by the Stata community's helpfulness and innovation.

          Sylvain- I followed your instructions to replace lines 287-367 with the code you generously provided in the ado file. However it is not working as hoped. I am getting a r(100) varlist required error when I use the updated syntax in the ado file. When I use the trace option to see where the hang up might be it seems to be happening around lines 340-343 of the "updated" ado file using the new syntax added in

          here is what I think the offending syntax might be

          Code:
                          *Empty temporary variables before next loop
                          qui: replace `tmp_x' = ""
                          qui: replace `tmp_y' = ""
                          qui: replace `tmp_matchlevel' = ""
          Not sure why this triggers a varlist error. But I'll admit this beyond my depth so I thought I would share here in case anyone is still following this thread.

          The original ado file works well though, expect for the issue that Helen originally raised. For the time being I will try Stephen's work-around.

          For anyone still reading... I am working on a database of about 8700 addresses (gun shops to be specific). I just need the lat-long numbers which georoute gathers. Georoute is great but it does more than I need it to since I am not interested in travel times really. I have found that HERE is a good service for finding tricky addresses that the Census geocoder API is not able to pin down. Since Sylvain mentioned that they are working on an update, I just wanted to put it out there that it would be useful to have a "lat long only" option that uses HERE to get the geocode for those of us just getting that information. But its certainly an odd request to ask a user-written command to do less work.

          Comment


          • #20
            Dear all,

            We have just released a new version 3.2 of georoute and georoutei on SSC (thank you Kit!). Type
            Code:
            ssc install georoute
            to install it or
            Code:
            ssc install georoute, replace
            to replace the older version.
            Version 3.2 contains major improvements, such as the possibility to specify transport mode, departure time, and various features of the route to be followed. Please have a look at the help file for all details.
            The "temporary variables" problem discussed above is also solved.

            Don't hesitate to let us know if you encounter further issues as we try to keep improving and maintaining the command.

            All the best,

            Martin Péclat, August Warren, and Sylvain Weber

            Comment


            • #21
              Dear georoute users,

              I should also point out we have just released a companion paper that describes the new features available in version 3.2 of georoute:
              Sylvain Weber, Martin Péclat & August Warren, 2021. "Travel distance and travel time using Stata: New features and major improvements in georoute," IRENE Working Papers 21-04, IRENE Institute of Economic Research.

              Best regards,

              Sylvain

              Comment


              • #22
                Dear all,

                First of all thank you to everyone who contributed to this great command!

                I wish to make a travel distance matrix between around 36,000 cities. Do you have any recommendations on how to best do that. Specific commands, loops or mata? Right now I can only figure out how to do have a dataset with 36000*36000 observations. I instead need to make a matrix.

                All the best,

                Cyprien

                Comment


                • #23
                  Here is what I get using georoute between pairs of 4 out of the 36026 cities:

                  clear
                  input long (depcom depcom2 dist)
                  1001 1001 .
                  1001 1002 50.224
                  1001 1004 45.807
                  1001 1005 20.264
                  1002 1001 .
                  1002 1002 .
                  1002 1004 14.039
                  1002 1005 47.122
                  1004 1001 .
                  1004 1002 .
                  1004 1004 .
                  1004 1005 40.941
                  1005 1001 .
                  1005 1002 .
                  1005 1004 .
                  1005 1005 .
                  end

                  And I would want a lower triangular matrix instead with the dist value between pairs of depcom/depcom2

                  Thank you very much in advance!

                  Comment


                  • #24
                    Dear all and professor Weber,

                    Apparently there have been some changes in the HERE Developer platform. I was wondering whether that affected the command geroutei. Actually, I got an error when running the following:

                    georoutei, herekey(WWJ2upwy3JxF0bBHCYfkkzyuJefAkrdxFNlUarXm6G 8) startxy(41.37599, 2.1492) endxy(41.5094, 1.90636)


                    Impossible to calculate a routing distance:
                    - Check that the two addresses/geographical points you provided can actually be linked b
                    > y road.


                    It's the first time a see this, and I used to run the same command one month ago. Does it happen to you or is it a problem of my HERE account?

                    Thank you!

                    Comment


                    • #25
                      I received the same error as Bernat when testing the georoutei command today. The georoute command looks great, would be much appreciated to get some help sorting out what I am doing wrong.

                      Code
                      global apikey [API Key]
                      georoutei , ///
                      herekey("$apikey") ///
                      startaddress("Vancouver, Canada") ///
                      endaddress("Whistler, Canada") ///
                      km

                      Output
                      SETTINGS
                      Start: Vancouver, Canada (49.26039,-123.11336)
                      End: Whistler, Canada (50.11984,-122.95414)
                      Mode: car (assigned by default)
                      Route: balanced (assigned by default)
                      Traffic: default (assigned by default)
                      Departure: 07 Apr 2022 09:46:33 (now; assigned by default)

                      Error message
                      Impossible to calculate a routing distance:
                      - Check that the two addresses/geographical points you provided can actually be linked by road.

                      Comment


                      • #26
                        The command below fixed georoute for me:

                        findit dm0092_1
                        (install & replace old versions)

                        from(http://www.stata-journal.com/software/sj22-1)

                        Comment


                        • #27
                          Hi Sylvain, I am trying to mimic the example given in the help file, and it is showing the following error- I have created the API key. Can you help me fix this problem?

                          georoute, herekey("$apikey") startad(address1) endad(address2) km di(dist) ti(time) co(p1 p2)


                          There seems to be an issue with the credentials of your HERE application: https://developer.here.com.
                          r(198);

                          Comment


                          • #28
                            Does anyone know if there are again some changes at HERE in the last weeks?
                            When I am replicating the georoute results of a month ago, I get the same result for lets say 95% of the routes and the other 5% became "no route found" (while I run exactly the same do-file as a month ago). Anyone experiencing the same issues lately?

                            Comment


                            • #29
                              Hi jeroen vc,

                              I have been having the same trouble. When I run georoute now I commonly get a "no route found" result when a route was found previously. In fact, if I run the command several times in a row, it will sometimes find a route and other times not, but not always for the same address combinations. I tried adding the "pause" option (even though my ds is not that large), but it didn't help. So, I have to run the command again and again, each time just extracting the results that worked on that particular run.

                              Comment


                              • #30
                                Hi everyone,

                                I get the error "impossible to calculate a routing distance: -Check that the two addresses/ geographical points you provided can actually be linked by road" when running a toy example with georoutei following Example 3.1 https://www.econstor.eu/bitstream/10.../1/WP21-04.pdf .

                                Comment

                                Working...
                                X