$W$ summarizes spatial relations between n spatial units.
$$ \begin{align*} W = \begin{bmatrix} 0 & w_{12} & w_{13} & \ldots & w_{1n} \\ w_{21} & 0 & w_{23} & \ldots & w_{2n} \\ \vdots & &\ddots& & \vdots \\ \vdots & &&\ddots& \vdots \\ w_{n1} & w_{n2} &&\ldots &0 \end{bmatrix}_{n\times n} \end{align*} $$
spmatrix subcommands | with shapefile | without shapefile | ||
---|---|---|---|---|
create contiguity | $\checkmark$ | $\color{red}\times$ | ||
create idistance | $\checkmark$ | $\checkmark$ | ||
userdefined | $\checkmark$ | $\checkmark$ | ||
spfrommata | $\checkmark$ | $\checkmark$ | ||
fromdata | $\checkmark$ | $\checkmark$ |
. use texas, clear
(S.Messner et al.(2000), U.S southern county homicide rates in 1990)
. spset
Sp dataset texas.dta
data: cross sectional
spatial-unit id: _ID
coordinates: _CX, _CY (planar)
linked shapefile: homicide1990_shp.dta
. spmatrix create contiguity W in 1/5, replace norm(none)
. spmatrix matafromsp W id = W
. mata :
------------------------------------------------- mata (type end to exit) -----
: W
[symmetric]
1 2 3 4 5
+---------------------+
1 | 0 |
2 | 0 0 |
3 | 0 1 0 |
4 | 0 1 0 0 |
5 | 1 0 0 1 0 |
+---------------------+
: end
-------------------------------------------------------------------------------
. use texas, clear
(S.Messner et al.(2000), U.S southern county homicide rates in 1990)
. spset
Sp dataset texas.dta
data: cross sectional
spatial-unit id: _ID
coordinates: _CX, _CY (planar)
linked shapefile: homicide1990_shp.dta
. describe _ID _CX _CY
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
_ID int %12.0g Spatial-unit ID
_CX double %10.0g x-coordinate of area centroid
_CY double %10.0g y-coordinate of area centroid
. spmatrix create idistance W in 1/5, replace norm(none)
. spmatrix matafromsp W id = W
. mata :
------------------------------------------------- mata (type end to exit) -----
: W
[symmetric]
1 2 3 4 5
+-----------------------------------------------------------------------+
1 | 0 |
2 | .6166988355 0 |
3 | .4302282965 1.422857832 0 |
4 | .9242522485 1.853277163 .80489678 0 |
5 | 1.838045971 .9280886181 .5617049161 1.859081065 0 |
+-----------------------------------------------------------------------+
: end
-------------------------------------------------------------------------------
See the discussion on normalization in spregress