Dear all,

I tried to create an inverse spatial weight matrix, but without success. I rely on a cross-sectional firm-level dataset which consists of more than 90,000 observations. For each firm I have information about the Latitude and the Longitude.

My data look like this:
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input float ID double(Revenues Ebitda Longitude Latitude)

2 38624.446 3741.754 45.485734 11.418047
3 16322.134 1397.343 45.578752 12.373638
4 3806.701 187.363 44.913215 8.616946
5 923.103 26.39 45.465844 12.217479
7 1629.393 148.883 45.621295 8.865697
8 936.349 62.485 45.615311 8.836641
9 821.583 40.058 44.17739 12.292067
10 2172.014 172.566 45.605449 8.870614
11 3553.138 416.369 37.180847 15.128322
12 6428.817 1110.01 44.510647 11.833396
end
[/CODE

First, I set spatial data by typing:
Code:
spset ID, coord(Longitude Latitude) coordsys(latlong, kilometers)
And then:
Code:
spmatrix create idistance idW, normalize(none)
But I get the result:
Code:
Two or more observations have the same coordinates
r(498);
To solve this issue, I detect for the presence of duplicates in my data and handle them as follow:
Code:
set seed 10000
gen double shuffle1 = runiform(0.00000000001,0.00000000002)
replace _CX =_CX +shuffle1 if tag>0
replace _CY =_CY +shuffle1 if tag>0
When I type:
Code:
duplicates report _CX _CY
I get the result:
Code:
--------------------------------------
   copies | observations       surplus
----------+---------------------------
        1 |       92000             0
--------------------------------------
After that, I rewrite the command:
Code:
spmatrix create idistance idW, normalize(none)
But what I get is the following error:
Code:
Division by zero: Two or more observations have the same coordinates
r(498);
This is somewhat puzzling since there are not anymore duplicates in the data. And, even more importantly, I am able to create an inverse spatial weight matrix with the above procedure only when I focus on a smaller sample of approximately 10,000 observations.

Thank you in advance for your support.

Best,
Stefano