Announcement

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

  • spmat - inverse distance matrix involving two or more observations at some locations

    Hi,

    I am trying to create a firm-to-firm inverse distance matrix and there are several firms at the same geographical coordinates--this is a historical dataset (mostly 19th C) and the coordinates are at the city or county level.

    Years ago, I _successfully_ used this code to generate it:

    spmat idistance invdistmatrix_sp x_long2 y_lat2, id(id) dfunction(dhaversine, miles)

    Having to use this code to create some new measures, I run into this error: "Two or more observations have the same coordinates"

    Please help! Have tried a few workarounds but nothing has worked so far. I would prefer not to use another software package if I can help it since I want the measures to be consistent across my studies, but if there's no choice, would appreciate any suggestions.

    Thank you in advance!

    Best wishes,
    Chirag



    Last edited by Chirag Kasbekar; 12 May 2022, 20:07.

  • #2
    spmat is from the Stata Journal (FAQ Advice #12).

    "Two or more observations have the same coordinates"
    The error message is self explanatory. Check for identifiers with the same coordinates.

    Code:
    bys id x_long2 y_lat2: gen tag=_N>1
    list id x_long2 y_lat2 if tag, sepby(id)

    ADDED IN EDIT: On first reading, I missed:

    there are several firms at the same geographical coordinates--this is a historical dataset (mostly 19th C) and the coordinates are at the city or county level.
    As I do not use these commands, I can only recommend trying out the official command spmatrix to see if you get the same error. If it does not make a difference, you can contract the dataset based on latitudes and longitudes, generate the measures and merge back with the full dataset.
    Last edited by Andrew Musau; 14 May 2022, 10:06.

    Comment


    • #3
      Hi Andrew,

      Thanks very much for your response. I really appreciate it.

      I did try spmatrix and run into the same problem. (A problem I didn't face many years ago!) I am not sure how to use contract and expand/merge here since what I need is an (symmetric) inverse distance matrix involving each firm. If I create the inverse distance matrix only with one firm from each location, I don't know how to include the other firm observations at those locations in the symmetric inverse distance matrix. The objective really is to create a spatially weighted competitor density (count) measure for each firm.

      Thanks again!

      Best wishes,
      Chirag

      Comment


      • #4
        I have looked into it and this replicates the error.

        Code:
        copy https://www.stata-press.com/data/r16/texas_merge.dta .
        copy https://www.stata-press.com/data/r16/texas_merge_shp.dta .
        use texas_merge, clear
        *CREATE DUPLICATE
        expand 2 if countyname=="Houston"
        *THIS REPLICATES ERROR
        spmatrix create contiguity W

        The issue isn't duplicate coordinates per se, but duplicate identifiers. You need to assign each duplicate a distinct identifier and include the identifier in the shape file.

        Comment


        • #5
          Hi, Chirag!

          Have you solved your problem? Even though I am not familiar with STATA, I guess panel data analysis (spxtregress) would work for your analysis.

          Comment

          Working...
          X