help spmat contiguity


spmat contiguity -- Create an spmat object containing a contiguity matrix W


spmat contiguity objname [if] [in] using filename, id(varname) [options]

options Description ------------------------------------------------------------------------- * id(varname) ID variable rook rook contiguity normalize(norm) normalization method tolerance(#) numerical tolerance banded banded storage replace replace objname saving(filename, ...) save neighbor info to a text file nomatrix do not create objname ------------------------------------------------------------------------- * Required


spmat contiguity puts a contiguity matrix W into the new spmat object objname. The ijth element of W is 1 if points i and j are neighbors and is 0 otherwise.

spmat contiguity uses both the dataset in memory and a dataset containing the coordinates of polygons. The coordinates dataset must be in the format created by shp2dta or mif2dta.


id(varname) specifies a numeric variable that contains a unique identifier for each observation. This option is required.

rook specifies that only points that share a common edge should be considered neighbors (rook contiguity). The default is to include points that share a common vertex (queen contiguity). Rook contiguity is computationally more difficult than queen contiguity.

normalize(norm) specifies the normalization method. norm can be row, minmax, or spectral.

tolerance(#) specifies the numerical tolerance used in deciding whether two places are rook neighbors. The default is tolerance(1e-7).

banded instructs spmat to store the contiguity matrix in a banded form; see Remarks in spmat tobanded for details.

replace allows objname to be overwritten if it already exists.

saving(filename [, replace]) requests that the matrix be written to filename in the neighbor-list format. The first line of the file contains the total number of places and, if the matrix is banded, the lower and upper band. Each remaining line lists a place ID followed by its neighbors, if any. replace allows filename to be overwritten if it already exists.

nomatrix specifies that the spmat object objname and spatial-weighting matrix W not be created. In conjunction with saving(), this option allows for creating a text file containing a neighbor list without constructing the underlying contiguity matrix.


Setup . clear all . set memory 50m . use pollute

Create the spmat object cobj containing a minmax-normalized contiguity matrix . spmat contiguity cobj using pollutexy, id(id) normalize(minmax)

Also see

Online: spmat, spreg, spivreg, spmap, shp2dta, mif2dta (if installed)