Announcement

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

  • How to implement in Stata to define a market using a fixed radius

    Hi,

    I have facility-level data with geographic coordination for each facility. Instead of defining a geographic market using political boundaries such as county or state, I try to define each market based on a fixed radius around each facility (e.g., 20km of fixed radius). The structure of the data is listed below:

    Facility longitude latitude
    A -100 90
    B -30 60
    .......

    I'm not quite familiar with the Stata geographic coding program. Does anyone know how to implement this in Stata?

    Thanks!

    -Allen

  • #2
    Allen,

    If you are interested in straight-line distance ("as the crow flies"), try the geodist and geonear commands, available from SSC. If you are interested in driving distance, that is also possible, but much more complicated, as it requires using Google Maps or MapQuest and I don't think there is a canned command for that.

    Regards,
    Joe

    Comment


    • #3
      Thank you, Joe, for the hint. Is there a way to compute the distance for all the possible combinations? My data is like this:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str6 id double(lon lat) float year
      "105620"  -81.923623 27.965858 2008
      "295078"  -115.74636  40.85789 2008
      "145409"  -88.314065 41.840182 2008
      "135055"  -116.56787 48.271862 2008
      "275035" -113.965708 46.892982 2008
      "505126" -119.119899 46.246465 2008
      "105628"  -87.239318 30.431241 2008
      "245223"  -92.547685 44.560656 2008
      "335725"   -73.81007  40.70049 2008
      "26A127"  -94.484158 38.812419 2008
      end
      I need to compute the geographic distance between each id. Since there are multiple years of observations, I would also need bysort year. On average, there are over 10,000 observations each year...

      Thanks,
      Allen

      Comment


      • #4
        Allen,

        I think geonear could do this, using the within(#) option. Getting all possible combinations would probably require making two copies of your data set. geonear takes the open dataset, goes through all observations and looks for neighbors for each observation in a different data set. If the two data sets are the same, it should use all possible combinations to find those within the specified radius.

        Alternatively, if you just want to compute all possible distances and figure out later who is within the desired radius, you could create two copies of the file and use the joinby command. I'm assuming you have the computing resources to store 10,000x10,000 (1 billion) combinations per year?

        I suspect that there may be more efficient ways to do all possible distances, starting from scratch in Mata (unless someone has already done it). geonear is optimized to find nearest neighbors, not all possible neighbors, so might not be the best tool for the job,

        Regards,
        Joe

        Comment


        • #5
          Another option is to try distmatch.

          Comment

          Working...
          X