Announcement

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

  • #16
    I think you just got your latitudes and longitudes mixed up. Latitudes must be specified first in order and must be within [-90, 90].

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(district_id1 x_stub1 y_stub1)
      1  77.57578 14.484938
      2  79.01996  13.46324
      3  78.78391 14.461876
      4   82.0033 17.190853
      5  80.07764 16.291048
      6  80.79324 16.568815
      7  78.01077 15.522762
      8  79.74493  14.42524
      9  79.51898 15.611388
     10  83.66933 18.534872
     11  82.71606 17.879093
     12  81.40018 16.892174
     13  92.67226 24.683865
     14  92.57874  26.71558
     15  90.23173 26.291393
     17  94.96799  27.42658
     18  93.13989 26.046877
     19  93.02378   25.3485
     20  92.68436  26.22977
     21  94.25702  26.72941
     22  86.95314  25.04594
     23  84.60091 26.878845
     24  86.06253 26.107756
     25  84.92094 24.800936
     26  86.29471  25.16689
     27  85.40443  26.18871
     28  85.32538  25.35474
     29  87.53761  25.91772
     30     86.77  25.99135
     31  84.55655 26.146526
     32  84.03043  25.17149
     33  81.26424 19.232664
     34  82.28456 22.336386
     35  81.10991   21.2673
     36  83.55159 22.384794
     37  82.21187  21.00315
     38  82.93346 23.386633
     44  73.71906 20.782715
     45 72.662796 23.203684
     58  77.11015  30.38144
     59  77.03268  28.17054
     60   75.5223  29.28937
     61  76.31522 29.425783
     62  76.75643  29.74056
     63  76.15585  28.32321
     64  76.68118  28.83104
     65  76.67768   31.3584
     66  76.46109  32.70605
     67  76.33959   31.9426
     68  78.40654 31.572264
     69  77.39387 31.888023
     70  77.75434 32.413715
     71  77.65334  31.17899
     72  77.00079  31.61929
     73  76.91825  31.03793
     74   77.4459  30.65933
     75  75.12834  33.75286
     76   74.4601  34.38276
     77  75.84465 33.417263
     78  74.82651  32.69138
     79  75.57309 32.555298
     80  78.02759 34.283478
     81  74.30234  33.64733
     82  74.38713  33.20358
     83  74.87225  34.08359
     84  75.07751  33.02404
     85  86.40241  23.74969
     86  85.58877  24.11807
     87  84.10754 24.010754
     88  84.89087 23.071264
     89    87.245 24.493023
     90  85.85558  22.54394
     91   77.4726 12.913547
     92  74.82811 16.113764
     93  76.44615 15.046112
     94  77.22865 17.942135
     95  75.81337 16.560215
     96  75.68145 13.428985
     97  76.41669 14.223225
     98  75.79681 12.323008
     99  75.41306 15.144032
    100   76.8756 17.054512
    101  76.10504 12.978118
    102  78.01498 13.370895
    103  76.79259 12.604687
    104  76.75268 12.079443
    105  74.60293 14.774975
    106  76.63239  15.87672
    107 75.326836 14.036293
    108  75.08897 13.120307
    109  76.94049 13.513035
    110  76.47502  9.438544
    111  75.46492 12.129185
    112  76.56656  10.01389
    113  76.90978  9.106371
    114  76.92366  9.794156
    115 75.952866 11.549033
    116  76.15894 11.137506
    117  76.56069 10.794156
    118  76.31778 10.473877
    end
    
    tempfile dataset2
    save `dataset2'
    
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(district_id x_stub y_stub)
      1  77.57578 14.484938
      2  79.01996  13.46324
      3  78.78391 14.461876
      4   82.0033 17.190853
      5  80.07764 16.291048
      6  80.79324 16.568815
      7  78.01077 15.522762
      8  79.74493  14.42524
      9  79.51898 15.611388
     10  83.66933 18.534872
     11  82.71606 17.879093
     12  81.40018 16.892174
     22  86.95314  25.04594
     23  84.60091 26.878845
     24  86.06253 26.107756
     25  84.92094 24.800936
     26  86.29471  25.16689
     27  85.40443  26.18871
     28  85.32538  25.35474
     29  87.53761  25.91772
     30     86.77  25.99135
     31  84.55655 26.146526
     32  84.03043  25.17149
     39  72.22892  22.71804
     40 71.157364 21.376474
     41  71.92759 24.218157
     42   73.2238  21.75263
     43  71.79604 21.631826
     44  73.71906 20.782715
     45 72.662796 23.203684
     46 69.938225  22.25322
     47  70.36705 21.291815
     48 72.901024 22.702017
     49  69.92829  23.64138
     50  72.25824   23.6403
     51  73.84151  22.89135
     52  70.76935 22.250036
     53  73.14674 23.633554
     54  73.34554  21.23379
     55  71.53689 22.785044
     56  73.53912 22.231274
     57  73.12912  20.58801
     58  77.11015  30.38144
     59  77.03268  28.17054
     60   75.5223  29.28937
     61  76.31522 29.425783
     62  76.75643  29.74056
     63  76.15585  28.32321
     64  76.68118  28.83104
     85  86.40241  23.74969
     86  85.58877  24.11807
     87  84.10754 24.010754
     88  84.89087 23.071264
     89    87.245 24.493023
     90  85.85558  22.54394
     91   77.4726 12.913547
     92  74.82811 16.113764
     93  76.44615 15.046112
     94  77.22865 17.942135
     95  75.81337 16.560215
     96  75.68145 13.428985
     97  76.41669 14.223225
     98  75.79681 12.323008
     99  75.41306 15.144032
    100   76.8756 17.054512
    101  76.10504 12.978118
    102  78.01498 13.370895
    103  76.79259 12.604687
    104  76.75268 12.079443
    105  74.60293 14.774975
    106  76.63239  15.87672
    107 75.326836 14.036293
    108  75.08897 13.120307
    109  76.94049 13.513035
    110  76.47502  9.438544
    111  75.46492 12.129185
    112  76.56656  10.01389
    113  76.90978  9.106371
    114  76.92366  9.794156
    115 75.952866 11.549033
    116  76.15894 11.137506
    117  76.56069 10.794156
    118  76.31778 10.473877
    119  77.00609  8.603258
    183  86.78558 21.288477
    184  84.08356  20.26519
    185  83.34911  20.67327
    186  86.14165  20.55069
    187  85.16365  20.92387
    188   84.4937 19.466806
    189  82.93784 20.060373
    190  85.70293 21.532385
    191  82.68578 18.988888
    192  86.40359  21.90428
    193  85.40851 20.060816
    194  84.01537   21.4042
    195  84.52103   22.0683
    196  74.89443 31.517076
    197  75.11371  30.18027
    198  74.59668 30.522146
    end
    
    geonear district_id y_stub x_stub using `dataset2', n(district_id1 y_stub1 x_stub1) ign long within(2000) near(2)
    Res.:

    Code:
    . l in 1/100, sepby(district_id)
    
         +---------------------------------+
         | distri~d   distri~1   km_to_d~1 |
         |---------------------------------|
      1. |        1          7   124.49904 |
      2. |        1        109   127.97384 |
      3. |        1         97    128.2082 |
      4. |        1          3   130.09966 |
      5. |        1        102   132.63457 |
      6. |        1         93   136.55177 |
      7. |        1         91   175.08588 |
      8. |        1        106   184.93033 |
      9. |        1          2   192.84612 |
     10. |        1        103    225.5649 |
     11. |        1        101   230.88844 |
     12. |        1          8   233.65575 |
     13. |        1         96   235.73967 |
     14. |        1          9   243.36752 |
     15. |        1         99   243.76493 |
     16. |        1        107   247.44494 |
     17. |        1        104   281.91882 |
     18. |        1        100   295.38236 |
     19. |        1         95   298.16032 |
     20. |        1         98   307.91562 |
     21. |        1        108   308.43498 |
     22. |        1        105   321.46761 |
     23. |        1          5    335.0626 |
     24. |        1         92    345.8944 |
     25. |        1        111   347.53595 |
     26. |        1        115   370.78345 |
     27. |        1         94   386.20473 |
     28. |        1        116   402.66387 |
     29. |        1          6   415.32911 |
     30. |        1        117   424.91232 |
     31. |        1        118   466.44348 |
     32. |        1         12   489.11211 |
     33. |        1        112   509.10259 |
     34. |        1        114   526.38356 |
     35. |        1          4   561.06588 |
     36. |        1        110   573.75786 |
     37. |        1        113   602.44307 |
     38. |        1         33   657.76167 |
     39. |        1         11   666.05978 |
     40. |        1         10   790.29795 |
     41. |        1         44   810.67965 |
     42. |        1         35   841.67975 |
     43. |        1         37   875.23592 |
     44. |        1         34   1004.2289 |
     45. |        1         36   1080.8018 |
     46. |        1         45   1098.4013 |
     47. |        1         38   1138.5955 |
     48. |        1         88   1225.9856 |
     49. |        1         90   1250.3528 |
     50. |        1         87   1261.1894 |
     51. |        1         86   1360.9247 |
     52. |        1         32   1366.0153 |
     53. |        1         25   1380.2876 |
     54. |        1         85   1385.1127 |
     55. |        1         28    1454.087 |
     56. |        1         31    1486.165 |
     57. |        1         26   1496.3581 |
     58. |        1         89   1503.9542 |
     59. |        1         59   1522.8017 |
     60. |        1         22   1529.0296 |
     61. |        1         27   1535.0869 |
     62. |        1         63   1545.7015 |
     63. |        1         23   1558.9418 |
     64. |        1         24   1565.1552 |
     65. |        1         30    1597.665 |
     66. |        1         64   1597.8699 |
     67. |        1         29     1640.56 |
     68. |        1         60   1659.6449 |
     69. |        1         61    1666.382 |
     70. |        1         62   1698.4279 |
     71. |        1         58   1768.2518 |
     72. |        1         74   1798.5594 |
     73. |        1         73   1841.8299 |
     74. |        1         71   1856.3107 |
     75. |        1         15   1858.4849 |
     76. |        1         65   1878.4715 |
     77. |        1         68   1901.9032 |
     78. |        1         72   1906.1506 |
     79. |        1         69   1935.2231 |
     80. |        1         13   1943.3494 |
     81. |        1         67   1945.2603 |
     82. |        1         70   1993.6713 |
         |---------------------------------|
     83. |        2        102   109.18274 |
     84. |        2          3   113.92714 |
     85. |        2          8    132.5268 |
     86. |        2         91   178.32182 |
     87. |        2          1   192.84612 |
     88. |        2        109   224.91612 |
     89. |        2          9   244.82698 |
     90. |        2          7   253.47023 |
     91. |        2        103   259.48765 |
     92. |        2        104    290.0449 |
     93. |        2         97   293.48832 |
     94. |        2        101    320.1085 |
     95. |        2         93   328.50123 |
     96. |        2          5   334.34711 |
     97. |        2         96   361.06691 |
     98. |        2        106   371.44352 |
     99. |        2         98    371.6489 |
    100. |        2          6   394.34502 |
         +---------------------------------+
    
    .

    Comment


    • #17
      Thanks a lot, I also want to keep the year variable from my dataset after running the geo-near command. This is so because there are different neighbors for the same districts ( as the district gets treated and comes out over time). I need to know the year variable so that I can merge it back with the main dataset to run my regressions.

      Comment


      • #18
        Keep the combinations that you need per district_id after running geonear then use joinby to link these combinations to the dataset with years.

        Comment

        Working...
        X