Dear All,

I have the following data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte _ID str52 regionname float(trust trust2)
60 "ABRUZZI - MOLISE - BASILICATA"                        29.31034 29.31034
46 "ALENTEJO"                                             17.77778 17.77778
44 "ALGARVE"                                              26.08696 26.08696
15 "ANDALUCIA"                                            24.47873 24.47873
12 "ARAGON"                                               55.93221 55.93221
62 "ASTURIAS-CANTABRIA"                                   31.86275 31.86275
48 "AZORE ISLANDS"                                        19.54023 19.54023
 4 "BADEN-WUERTTEMBERG"                                   44.13265 44.13265
17 "BALEARES"                                             23.65591 23.65591
 9 "BAYERN"                                               34.59119 34.59119
64 "BREMEN HAMBURG"                                       35.52631 35.52631
42 "CALABRIA"                                              37.3494  37.3494
33 "CAMPANIA"                                             28.01303 28.01303
18 "CANARIAS"                                             23.56688 23.56688
21 "CASTILLA-LA MANCHA"                                   32.59669 32.59669
19 "CASTILLA-LEON"                                        42.19949 42.19949
22 "CATALUNA"                                             34.40135 34.40135
47 "CENTRO (P)"                                           19.70803 19.70803
14 "COMUNIDAD VALENCIANA"                                 24.49941 24.49941
68 "EAST ANGLIA"                                          47.41379 47.41379
27 "EAST FR"                                              19.19192 19.19192
54 "EAST MIDLANDS"                                        33.57664 33.57664
41 "EMILIA-ROMAGNA"                                       30.84112 30.84112
13 "EXTREMADURA"                                          26.38889 26.38889
10 "GALICIA"                                              31.03448 31.03448
 7 "HESSEN"                                               32.77311 32.77311
30 "ILE DE FRANCE"                                        26.21951 26.21951
38 "LAZIO"                                                 27.7027  27.7027
32 "LIGURIA"                                              37.69231 37.69231
45 "LISBOA E VALE DO TEJO"                                22.77228 22.77228
31 "LOMBARDIA"                                             44.3038  44.3038
49 "MADEIRA"                                              23.85321 23.85321
20 "MADRID"                                               41.71779 41.71779
23 "MEDITERREAN FR"                                             22       22
16 "MURCIA"                                               34.16667 34.16667
63 "NAVARRA - RIOJA"                                      41.13475 41.13475
 8 "NIEDERSACHSEN"                                        43.79085 43.79085
36 "NOORD NEDERLAND - GRONINGEN"                          47.29729 47.29729
 5 "NORDRHEIN-WESTFALEN"                                  39.70037 39.70037
43 "NORTE"                                                21.14804 21.14804
26 "NORTH FR"                                             17.04545 17.04545
66 "NORTH UK"                                             26.44628 26.44628
67 "NORTH WEST UK"                                        32.37705 32.37705
51 "NORTHERN IRELAND"                                     43.62416 43.62416
34 "OOST NEDERLAND"                                       64.13793 64.13793
11 "PAIS VASCO"                                           40.33796 40.33796
29 "PARIS BASIN EAST/WEST"                                 14.1791  14.1791
57 "PIEMONTE - VALLLE D'AOSTA"                            37.76224 37.76224
39 "PUGLIA"                                               29.16667 29.16667
 2 "REG.BRUXELLES-CAP./BR"                                26.89805 26.89805
 3 "REGION WALLONNE"                                      28.87218 28.87218
65 "RHEINLAND-PFALZ SAARL"                                42.51208 42.51208
 6 "SCHLESWIG-HOLSTEIN"                                   34.18803 34.18803
50 "SCOTLAND"                                             39.24051 39.24051
61 "SICILIA - SARDEGNA"                                   26.86567 26.86567
25 "SOUTH EAST FR"                                        24.78633 24.78633
69 "SOUTH EAST UK"                                        39.62617 39.62617
24 "SOUTH WEST FR"                                        30.18868 30.18868
53 "SOUTH WEST UK"                                        34.25414 34.25414
40 "TOSCANA"                                              35.52631 35.52631
58 "TRENTINO ALTO ADIGE - VENETO - FRIULI VENEZIA GIULIA" 48.96265 48.96265
59 "UMBRIA - MARCHE"                                       35.9375  35.9375
 1 "VLAAMS GEWEST"                                        37.72414 37.72414
52 "WALES"                                                40.75235 40.75235
28 "WEST FR"                                              26.71756 26.71756
56 "WEST MIDLANDS"                                        41.42259 41.42259
35 "WEST NEDERLAND"                                       53.16456 53.16456
55 "YORKSHIRE AND HUMBERS"                                 34.0708  34.0708
37 "ZUID NEDERLAND"                                             50       50
end
I generate the following function in mata:

Code:
mata:
function SinvD(vi, vj)
{
return (1/sqrt((vi-vj)*(vi-vj)'))
}
end
Then I type:

Code:
spmatrix userdefined W`v'=SinvD(trust trust2)
When running, i got the following error message:

Code:
. spmatrix userdefined Wtrust=SinvD(trust trust2)
user-defined function returned inappropriate value
    When working on row 60 of the matrix, the user-defined function returned missing values.
r(459);
However, I cannot understand where this error comes from. I do not have any missing value in the data. Notice that If I use the following data (their structure is the same as above), it runs smoothly:


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte _ID str52 regionname float(control control2)
60 "ABRUZZI - MOLISE - BASILICATA"                         50.2924  50.2924
46 "ALENTEJO"                                             61.23738 61.23738
44 "ALGARVE"                                              63.16425 63.16425
15 "ANDALUCIA"                                            66.64336 66.64336
12 "ARAGON"                                               60.03899 60.03899
62 "ASTURIAS-CANTABRIA"                                   61.26402 61.26402
48 "AZORE ISLANDS"                                        58.78553 58.78553
 4 "BADEN-WUERTTEMBERG"                                   67.37697 67.37697
17 "BALEARES"                                               53.125   53.125
 9 "BAYERN"                                               67.61789 67.61789
64 "BREMEN HAMBURG"                                       70.76023 70.76023
42 "CALABRIA"                                             54.33604 54.33604
33 "CAMPANIA"                                             62.90082 62.90082
18 "CANARIAS"                                               67.212   67.212
21 "CASTILLA-LA MANCHA"                                   63.17967 63.17967
19 "CASTILLA-LEON"                                        60.98516 60.98516
22 "CATALUNA"                                             60.86318 60.86318
47 "CENTRO (P)"                                           63.31699 63.31699
14 "COMUNIDAD VALENCIANA"                                 64.48045 64.48045
68 "EAST ANGLIA"                                          69.62963 69.62963
27 "EAST FR"                                              59.93266 59.93266
54 "EAST MIDLANDS"                                        70.89948 70.89948
41 "EMILIA-ROMAGNA"                                       62.22223 62.22223
13 "EXTREMADURA"                                          65.83125 65.83125
10 "GALICIA"                                              62.91752 62.91752
 7 "HESSEN"                                               65.68987 65.68987
30 "ILE DE FRANCE"                                        58.97898 58.97898
38 "LAZIO"                                                64.07407 64.07407
32 "LIGURIA"                                              64.34853 64.34853
45 "LISBOA E VALE DO TEJO"                                63.20115 63.20115
31 "LOMBARDIA"                                            63.11858 63.11858
49 "MADEIRA"                                              60.85627 60.85627
20 "MADRID"                                                64.7702  64.7702
23 "MEDITERREAN FR"                                       59.91285 59.91285
16 "MURCIA"                                               61.51111 61.51111
63 "NAVARRA - RIOJA"                                      68.47912 68.47912
 8 "NIEDERSACHSEN"                                        67.83459 67.83459
36 "NOORD NEDERLAND - GRONINGEN"                                60       60
 5 "NORDRHEIN-WESTFALEN"                                  67.86022 67.86022
43 "NORTE"                                                59.54501 59.54501
26 "NORTH FR"                                             58.55181 58.55181
66 "NORTH UK"                                             63.74269 63.74269
67 "NORTH WEST UK"                                        65.56403 65.56403
51 "NORTHERN IRELAND"                                     71.61314 71.61314
34 "OOST NEDERLAND"                                       53.69176 53.69176
11 "PAIS VASCO"                                           63.40095 63.40095
29 "PARIS BASIN EAST/WEST"                                57.61317 57.61317
57 "PIEMONTE - VALLLE D'AOSTA"                            60.84291 60.84291
39 "PUGLIA"                                               65.39683 65.39683
 2 "REG.BRUXELLES-CAP./BR"                                64.07563 64.07563
 3 "REGION WALLONNE"                                      63.26399 63.26399
65 "RHEINLAND-PFALZ SAARL"                                65.95441 65.95441
 6 "SCHLESWIG-HOLSTEIN"                                    66.2458  66.2458
50 "SCOTLAND"                                             67.74318 67.74318
61 "SICILIA - SARDEGNA"                                   59.67658 59.67658
25 "SOUTH EAST FR"                                        56.64845 56.64845
69 "SOUTH EAST UK"                                         67.5137  67.5137
24 "SOUTH WEST FR"                                        56.08466 56.08466
53 "SOUTH WEST UK"                                        65.85366 65.85366
40 "TOSCANA"                                              49.69136 49.69136
58 "TRENTINO ALTO ADIGE - VENETO - FRIULI VENEZIA GIULIA"   65.722   65.722
59 "UMBRIA - MARCHE"                                      55.99647 55.99647
 1 "VLAAMS GEWEST"                                        60.17209 60.17209
52 "WALES"                                                66.30566 66.30566
28 "WEST FR"                                              58.45411 58.45411
56 "WEST MIDLANDS"                                        60.98766 60.98766
35 "WEST NEDERLAND"                                       58.64074 58.64074
55 "YORKSHIRE AND HUMBERS"                                68.10857 68.10857
37 "ZUID NEDERLAND"                                       57.18254 57.18254
end
Any advise?

Thanks in advance.