Advanced Search
MyIDEAS: Login to save this software component or follow this series

NEARSTAT: Stata module to calculate distance-based variables and export distance matrix to text file


Author Info

  • P. Wilner Jeanty

    (The Kinder Institute for Urban Research/Hobby Center for the Study of Texas, Rice University)


Using Mata, Stata's new matrix language, nearstat calculates distances, generates distance-based variables, and exports the distances to a Stata matrix, a Mata file, or a text file. To generate the variables, nearstat performs, for each observation in a Stata dataset, a series of computational tasks including, but not limited to, calculating distance-weighted descriptive statistics over all neighbors, nearest neighbors, and neighbors falling in a specified distance band; calculating distance to nearest neighbors; counting the number of neighbors falling in a specified distance band; and determining whether a specified (e.g., first, second, third,...) nearest neighbor falls within a certain distance band. Distance is calculated as the Great Circle or crow-fly distance depending on whether spherical or Cartesian coordinates are supplied to nearstat.

Download Info

If you experience problems downloading a file, check if you have the proper application to view it first. In case of further problems read the IDEAS help page. Note that these files are not on the IDEAS site. Please be patient as the files may be large.
File URL:
File Function: program code
Download Restriction: no

File URL:
File Function: program code
Download Restriction: no

File URL:
File Function: Mata object library
Download Restriction: no

File URL:
File Function: help file
Download Restriction: no

Bibliographic Info

Software component provided by Boston College Department of Economics in its series Statistical Software Components with number S457110.

as in new window
Programming language: Stata
Requires: Stata version 10.1
Date of creation: 26 Jan 2010
Date of revision: 07 Feb 2012
Handle: RePEc:boc:bocode:s457110

Note: This module should be installed from within Stata by typing "ssc install nearstat". Windows users should not attempt to download these files with a web browser.
Contact details of provider:
Postal: Boston College, 140 Commonwealth Avenue, Chestnut Hill MA 02467 USA
Phone: 617-552-3670
Fax: +1-617-552-2308
Web page:
More information through EDIRC

Order Information:

Related research

Keywords: spatial data; nearest neighbors; Great Circle distance; spherical coordinates;


This item is not listed on Wikipedia, on a reading list or among the top items on IDEAS.


Access and download statistics


When requesting a correction, please mention this item's handle: RePEc:boc:bocode:s457110. See general information about how to correct material in RePEc.

For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: (Christopher F Baum).

If you have authored this item and are not yet registered with RePEc, we encourage you to do it here. This allows to link your profile to this item. It also allows you to accept potential citations to this item that we are uncertain about.

If references are entirely missing, you can add them using this form.

If the full references list an item that is present in RePEc, but the system did not link to it, you can help with this form.

If you know of missing items citing this one, you can help us creating those links by adding the relevant references in the same way as above, for each refering item. If you are a registered author of this item, you may also want to check the "citations" tab in your profile, as there may be some citations waiting for confirmation.

Please note that corrections may take a couple of weeks to filter through the various RePEc services.