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

  • Nearstat Error Message

    Dear Statalist-Community,

    I am trying to calculate the distance between two datsets using their latitude & longitude locations and the 'nearstat' command.

    Following, the used commands are listed:

    ************************************************** ****************************
    use "$data\Prep_Buffer_DHS.dta", clear

    append using "$data\All_Location_Insa_nodup.dta", keep(id latitude longitude)

    * Sort so that nearstat will run, putting all projects first

    gsort -id

    * First count how many projects are within 200 km to know how many loops->to run nearstat

    foreach dist in 15 25 50 75 100 200 {
    nearstat LATNUM LONGNUM, ///
    near(latitude longitude) distvar(_1LSLAdist`dist') ///
    ncount(numberwithin`dist') dband(0 `dist') favor(speed)

    drop _1LSLAdist15 _1LSLAdist25 _1LSLAdist50 _1LSLAdist75 _1LSLAdist100 _1LSLAdist200

    ************************************************** **********************************

    When I run the 'nearstat' command, I get the following error message:

    'The order for the nearest neighbor cannot be greater than the number of near features.'

    Does anyone know how to interpret the error message? I could'nt find a solution yet.

    Thank you very much for your support in advance and warm greetings !

  • #2
    Welcome to Statalist.

    You have accidentally posted your topic in Statalist's Mata Forum, which is used for discussions of Stata's Mata language, which is different than Stata's command language. Your question will see a more appropriate, and much larger audience if you post it in Statalist's General Forum.