Announcement

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

  • Finding nearest neighbor using geonear

    Dear stata users,

    I am using - geonear - command to generate firm-level clusters with respect to reference university within 1 mile.
    However, firms are included in several clusters that are near universities.
    What I would like to do is to make firms included in only one cluster which is nearest to the given reference and in same sector (naics6).
    For more information, my master dataset is firm-level panel data merged with patent data and another one is university patent-level data.
    In more detail, below is the previous question that I posted containing the example of my datasets (both firm-level data in #12 and university patent-level data in #27 which is identical below).
    https://www.statalist.org/forums/for...analysis/page2
    Originally posted by Anne-Claire Jo View Post

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long patent_num str10 org_id str70 city str7 state_code str30 bea_code str22 county float(latitude longitude)
    6575965 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    4595014 "UN_208905" "Westport" "CT" "118" "Fairfield" 41.14343 -73.34958
    4916505 "UN_208752" "Honolulu" "HI" "074" "Honolulu" 21.3095 -157.863
    4282965 "UN_209262" "Binghamton" "NY" "162" "Broome" 42.14631 -75.88652
    5157702 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    5034515 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    5049280 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    6185469 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    7355081 "UN_209181" "Rochester" "NY" "139" "Monroe" 43.1683 -77.6026
    5196396 "UN_208904" "Cambridge" "MA" "022" "Middlesex" 42.37704 -71.12561
    4824359 "UN_208853" "Ann Arbor" "MI" "047" "Washtenaw" 42.27938 -83.784
    4581315 "UN_208905" "Norwalk" "CT" "118" "Fairfield" 41.12222 -73.43583
    4946773 "UN_208904" "Cambridge" "MA" "022" "Middlesex" 42.37704 -71.12561
    5754575 "UN_208940" "Scottsdale" "AZ" "128" "Maricopa" 33.521767 -111.90492
    6502576 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    7084407 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    6130254 "UN_1647" "Ann Arbor" "MI" "047" "Washtenaw" 42.27938 -83.784
    4038143 "UN_1647" "Ann Arbor" "MI" "047" "Washtenaw" 42.27938 -83.784
    6166295 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    3948213 "UN_200429" "Des Plaines" "IL" "032" "Cook" 42.04673 -87.8859
    7378498 "UN_211119" "Baltimore" "MD" "174" "Baltimore City" 39.29463 -76.62521
    5888473 "UN_1542" "Los Angeles" "CA" "097" "Los Angeles" 33.97309 -118.2479
    5037746 "UN_208905" "Westport" "CT" "118" "Fairfield" 41.14343 -73.34958
    4816125 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    5925818 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    4974113 "UN_208904" "Cambridge" "MA" "022" "Middlesex" 42.37704 -71.12561
    7219249 "UN_1380" "Albany" "NY" "004" "Albany" 42.6525 -73.7566
    7560287 "UN_209183" "Eugene" "OR" "053" "Lane" 44.07368 -123.07876
    4684891 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    7298820 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    4164214 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    6251322 "UN_209442" "Clemson" "SC" "068" "Pickens" 34.68306 -82.825
    5951881 "UN_208904" "Cambridge" "MA" "022" "Middlesex" 42.37704 -71.12561
    7609220 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    4654598 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    7638300 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    5395521 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    4043934 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    4666847 "UN_208986" "Bedford" "MA" "022" "Middlesex" 42.48429 -71.276794
    6625135 "UN_999999" "Pittsburgh" "PA" "129" "Allegheny" 40.47454 -79.95252
    5452824 "UN_209262" "Binghamton" "NY" "162" "Broome" 42.14631 -75.88652
    7188559 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    5416115 "UN_999999" "College Park" "MD" "174" "Prince Georges" 38.9963 -76.92989
    5888789 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    5719784 "UN_211213" "Seattle" "WA" "152" "King" 47.61143 -122.33046
    5912466 "UN_1542" "Los Alamos" "NM" "147" "Los Alamos" 35.86632 -106.26762
    5820678 "UN_1542" "Los Alamos" "NM" "147" "Los Alamos" 35.86632 -106.26762
    5448513 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    4769326 "UN_1542" "" "CA" "OTHER_USA" "" . .
    6605202 "UN_1542" "Los Alamos" "NM" "147" "Los Alamos" 35.86632 -106.26762
    6448012 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    5625137 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    5362622 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    5385541 "UN_209140" "Loma Linda" "CA" "097" "San Bernardino" 34.0524 -117.2618
    5032519 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    6254865 "UN_208823" "Boulder" "CO" "045" "Boulder" 40.04973 -105.21426
    5595761 "UN_1698" "Norman" "OK" "119" "Cleveland" 35.2212 -97.4448
    6664137 "UN_207741" "Ewing" "NJ" "118" "Mercer" 40.23769 -74.78206
    4409910 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    5530309 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    5335598 "UN_209025" "Phoenix" "AZ" "128" "Maricopa" 33.451 -112.0685
    5302609 "UN_1647" "Ann Arbor" "MI" "047" "Washtenaw" 42.27938 -83.784
    5459235 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    4550187 "UN_1380" "Albany" "NY" "004" "Albany" 42.6525 -73.7566
    5142559 "UN_1380" "Albany" "NY" "004" "Albany" 42.6525 -73.7566
    5212072 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    5272429 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    4897444 "UN_1380" "Albany" "NY" "004" "Albany" 42.6525 -73.7566
    4933639 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    6318146 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    7094205 "UN_999999" "Los Angeles" "CA" "097" "Los Angeles" 33.97309 -118.2479
    4431263 "UN_208905" "Norwalk" "CT" "118" "Fairfield" 41.12222 -73.43583
    5141851 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    6562619 "UN_211119" "Baltimore" "MD" "174" "Baltimore City" 39.29463 -76.62521
    5306447 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    7476384 "UN_1647" "Ann Arbor" "MI" "047" "Washtenaw" 42.27938 -83.784
    4427306 "UN_208905" "Norwalk" "CT" "118" "Fairfield" 41.12222 -73.43583
    5490169 "UN_209046" "Huntsville" "AL" "076" "Madison" 34.726868 -86.56732
    6730686 "UN_209142" "Kansas City" "KS" "084" "Wyandotte" 39.11573 -94.62714
    4352864 "UN_209254" "Saugus" "CA" "097" "" . .
    4701953 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    5416115 "UN_999999" "College Park" "MD" "174" "Prince Georges" 38.9963 -76.92989
    5849719 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    6046925 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    6222209 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    5856252 "UN_1542" "Oakland" "CA" "146" "Alameda" 37.780594 -122.21658
    5747469 "UN_1768" "Austin" "TX" "013" "Williamson" 30.50597 -97.74718
    5486636 "UN_1786" "Madison" "WI" "101" "Dane" 43.073 -89.3817
    5238711 "UN_208904" "Cambridge" "MA" "022" "Middlesex" 42.37704 -71.12561
    4043934 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    4871252 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    4076579 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    4874746 "UN_208904" "Cambridge" "MA" "022" "Middlesex" 42.37704 -71.12561
    6689192 "UN_1542" "Los Alamos" "NM" "147" "Los Alamos" 35.86632 -106.26762
    5049673 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    5757839 "UN_1647" "Ann Arbor" "MI" "047" "Washtenaw" 42.27938 -83.784
    6677444 "UN_209122" "Birmingham" "AL" "019" "Shelby" 33.401558 -86.70551
    4689399 "UN_209184" "Palo Alto" "CA" "146" "Santa Clara" 37.444324 -122.1497
    5650392 "UN_1698" "Norman" "OK" "119" "Cleveland" 35.2212 -97.4448
    4275270 "UN_1542" "Berkeley" "CA" "146" "Alameda" 37.8691 -122.2696
    end

    Could someone please help me with this issue ?
    Thank you very much in advance !

    Best,
    AC
    Last edited by Anne-Claire Jo; 01 Aug 2022, 00:03.

  • #2
    As you are asking for coding help, I recommend that you spend time creating a reproducible example. Assuming that you have already created the clusters following the advice in previous posts, start with:

    However, firms are included in several clusters that are near universities.
    Present a data example that shows this.

    What I would like to do is to make firms included in only one cluster which is nearest to the given reference and in same sector (naics6).
    Based on the data example, show what you mean by "nearest to the given reference", e.g., by showing how you want the final result to look like. Otherwise, it is difficult for anyone to follow what you want.

    Comment


    • #3
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(newid uni_id) long gvkey double year float(latitude longitude) double mi_to_uni_id
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 673      .    .        .        . .
         . 577      .    .        .        . .
         . 577      .    .        .        . .
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      7197 527 180466 2009 42.04673 -87.8859 0
      end
      
      
      . l newid uni_id gvkey year latitude longitude in 20300/20400, sepby(newid)
      
             +-----------------------------------------------------+
             | newid   uni_id   gvkey   year   latitude   longit~e |
             |-----------------------------------------------------|
      20300. |   181      177    1478   1950   40.74838   -73.9967 |
      20301. |   181      921    1478   1950   40.74838   -73.9967 |
      20302. |   181      177    1478   1950   40.74838   -73.9967 |
      20303. |   181      177    1478   1950   40.74838   -73.9967 |
      20304. |   181      177    1478   1950   40.74838   -73.9967 |
      20305. |   181      177    1478   1950   40.74838   -73.9967 |
      20306. |   181      177    1478   1950   40.74838   -73.9967 |
      20307. |   181      177    1478   1950   40.74838   -73.9967 |
      20308. |   181      929    1478   1950   40.74838   -73.9967 |
      20309. |   181      177    1478   1950   40.74838   -73.9967 |
      20310. |   181      177    1478   1950   40.74838   -73.9967 |
      20311. |   181      177    1478   1950   40.74838   -73.9967 |
      20312. |   181      177    1478   1950   40.74838   -73.9967 |
      20313. |   181      516    1478   1950   40.74838   -73.9967 |
      20314. |   181      177    1478   1950   40.74838   -73.9967 |
      20315. |   181      177    1478   1950   40.74838   -73.9967 |
      20316. |   181      714    1478   1950   40.74838   -73.9967 |
      20317. |   181     1076    1478   1950   40.74838   -73.9967 |
      20318. |   181      522    1478   1950   40.74838   -73.9967 |
      20319. |   181      177    1478   1950   40.74838   -73.9967 |
      20320. |   181      516    1478   1950   40.74838   -73.9967 |
      20321. |   181      177    1478   1950   40.74838   -73.9967 |
      20322. |   181      177    1478   1950   40.74838   -73.9967 |
      20323. |   181      915    1478   1950   40.74838   -73.9967 |
      20324. |   181      177    1478   1950   40.74838   -73.9967 |
      20325. |   181      177    1478   1950   40.74838   -73.9967 |
      20326. |   181      177    1478   1950   40.74838   -73.9967 |
      20327. |   181       66    1478   1950   40.74838   -73.9967 |
      20328. |   181     1199    1478   1950   40.74838   -73.9967 |
      20329. |   181      177    1478   1950   40.74838   -73.9967 |
      20330. |   181      714    1478   1950   40.74838   -73.9967 |
      20331. |   181       54    1478   1950   40.74838   -73.9967 |
      20332. |   181      177    1478   1950   40.74838   -73.9967 |
      20333. |   181      177    1478   1950   40.74838   -73.9967 |
      20334. |   181      177    1478   1950   40.74838   -73.9967 |
      20335. |   181      177    1478   1950   40.74838   -73.9967 |
      20336. |   181      177    1478   1950   40.74838   -73.9967 |
      20337. |   181      177    1478   1950   40.74838   -73.9967 |
      20338. |   181       54    1478   1950   40.74838   -73.9967 |
      20339. |   181      522    1478   1950   40.74838   -73.9967 |
      20340. |   181       66    1478   1950   40.74838   -73.9967 |
      20341. |   181      915    1478   1950   40.74838   -73.9967 |
      20342. |   181      177    1478   1950   40.74838   -73.9967 |
      20343. |   181      987    1478   1950   40.74838   -73.9967 |
      20344. |   181      177    1478   1950   40.74838   -73.9967 |
      20345. |   181      177    1478   1950   40.74838   -73.9967 |
      20346. |   181      177    1478   1950   40.74838   -73.9967 |
      20347. |   181      177    1478   1950   40.74838   -73.9967 |
      20348. |   181     1076    1478   1950   40.74838   -73.9967 |
      20349. |   181      412    1478   1950   40.74838   -73.9967 |
      20350. |   181      177    1478   1950   40.74838   -73.9967 |
      20351. |   181      177    1478   1950   40.74838   -73.9967 |
      20352. |   181      177    1478   1950   40.74838   -73.9967 |
      20353. |   181      177    1478   1950   40.74838   -73.9967 |
      20354. |   181      516    1478   1950   40.74838   -73.9967 |
      20355. |   181      921    1478   1950   40.74838   -73.9967 |
      20356. |   181       66    1478   1950   40.74838   -73.9967 |
      20357. |   181       66    1478   1950   40.74838   -73.9967 |
      20358. |   181      177    1478   1950   40.74838   -73.9967 |
      20359. |   181      177    1478   1950   40.74838   -73.9967 |
      20360. |   181      177    1478   1950   40.74838   -73.9967 |
      20361. |   181      921    1478   1950   40.74838   -73.9967 |
      20362. |   181      714    1478   1950   40.74838   -73.9967 |
      20363. |   181      113    1478   1950   40.74838   -73.9967 |
      20364. |   181      177    1478   1950   40.74838   -73.9967 |
      20365. |   181      177    1478   1950   40.74838   -73.9967 |
      20366. |   181      177    1478   1950   40.74838   -73.9967 |
      20367. |   181      144    1478   1950   40.74838   -73.9967 |
      20368. |   181      161    1478   1950   40.74838   -73.9967 |
      20369. |   181      177    1478   1950   40.74838   -73.9967 |
      20370. |   181      177    1478   1950   40.74838   -73.9967 |
      20371. |   181      177    1478   1950   40.74838   -73.9967 |
      20372. |   181     1076    1478   1950   40.74838   -73.9967 |
      20373. |   181      177    1478   1950   40.74838   -73.9967 |
      20374. |   181     1076    1478   1950   40.74838   -73.9967 |
      20375. |   181       54    1478   1950   40.74838   -73.9967 |
      20376. |   181      177    1478   1950   40.74838   -73.9967 |
      20377. |   181      177    1478   1950   40.74838   -73.9967 |
      20378. |   181      161    1478   1950   40.74838   -73.9967 |
      20379. |   181      177    1478   1950   40.74838   -73.9967 |
      20380. |   181      177    1478   1950   40.74838   -73.9967 |
      20381. |   181     1199    1478   1950   40.74838   -73.9967 |
      20382. |   181     1073    1478   1950   40.74838   -73.9967 |
      20383. |   181      177    1478   1950   40.74838   -73.9967 |
      20384. |   181      177    1478   1950   40.74838   -73.9967 |
      20385. |   181      522    1478   1950   40.74838   -73.9967 |
      20386. |   181     1076    1478   1950   40.74838   -73.9967 |
      20387. |   181      177    1478   1950   40.74838   -73.9967 |
      20388. |   181      177    1478   1950   40.74838   -73.9967 |
      20389. |   181      915    1478   1950   40.74838   -73.9967 |
      20390. |   181      177    1478   1950   40.74838   -73.9967 |
      20391. |   181      177    1478   1950   40.74838   -73.9967 |
      20392. |   181      877    1478   1950   40.74838   -73.9967 |
      20393. |   181      177    1478   1950   40.74838   -73.9967 |
      20394. |   181      177    1478   1950   40.74838   -73.9967 |
      20395. |   181      177    1478   1950   40.74838   -73.9967 |
      20396. |   181      177    1478   1950   40.74838   -73.9967 |
      20397. |   181      177    1478   1950   40.74838   -73.9967 |
      20398. |   181      177    1478   1950   40.74838   -73.9967 |
      20399. |   181      177    1478   1950   40.74838   -73.9967 |
      20400. |   181      915    1478   1950   40.74838   -73.9967 |
             +-----------------------------------------------------+
      As you might see above, newid is group of (gvkey latitude longitude) and uni_id is group of (university_id latitude longitude).
      I made clusters of firms (newid) depending on the reference of uni_id.
      However, there are many firm observation (181) that are included in several clusters (uni_id).
      What I would like to do is to make firm allocated in only one cluster.
      But the problem is that with this results, I do not know which university is nearest to each firms.
      In this case, would there be any solution to make firms allocated in one cluster (not just keeping one cluster)?

      Comment


      • #4
        Assuming that latitude and longitude in the dataset relate to

        newid is group of (gvkey latitude longitude)
        [,] the following

        uni_id is group of (university_id latitude longitude)
        implies that each uni_id is associated with a latitude and longitude pair. Call them latitude2 and longitude2 and include them in the dataset, you can use

        Code:
        ssc install geodist
        help geodist
        to calculate the geodetic distance between the two sets of coordinates, sort within clusters and pick out the smallest distance (uni_id) for that particular cluster.

        Comment


        • #5
          Got it ! Thank you very much !

          Comment

          Working...
          X