*! version 1.21 9 June 202
help moransi

Title

moransi -- Moran's I statistic

Syntax

moransi varname [if] [in],
lat(varname)
lon(varname)
swm(swmtype)
dist(#)
dunit(km|mi)
[options]

* lat(varname) specify the variable of latitude

* lon(varname) specify the variable of longitude

* swm(swmtype) specify a type of spatial weight matrix

* dist(#) specify the threshold distance for the spatial weight matrix

* dunit(km|mi) specify the unit of distance (kilometers or miles)

dms convert the degrees, minutes, and seconds format to a decimal format

approx use bilateral distance approximated by the simplified version of the Vincenty formula

detail display summary statistics of the bilateral distance

nomatsave does not save the bilateral distance matrix on the memory

generate stores the spatial lag of varname in the dataset.

* lat(), lon(), swm(), dist(), and dunit()
are required.

Description

moransi calculates Moran's I statistic.

Options

lat(varname) specifies the variable of latitude in the dataset. The
decimal format is expected in the default setting. A positive value denotes
the north latitude, whereas a negative value denotes the south latitude. lat() is required.

lon(varname) specifies the variable of longitude in the dataset. The
decimal format is expected in the default setting. A positive value denotes
the east longitude, whereas a negative value denotes the west longitude. lon() is required.

swm(swmtype) specifies a type of spatial weight matrix. One of the
following four types of spatial weight matrix must be specified: bin
(binary), knn (k-nearest neighbor), exp (exponential), or
pow (power). The parameter k must be specified for the k-nearest
neighbor as follows: swm(knn #). The distance decay parameter
# must be specified for the exponential and power function
types of spatial weight matrix as follows: swm(exp #) and
swm(pow #). swm() is required.

dist(#) specifies the threshold distance # for the spatial weight
matrix. The unit of distance is specified by the dunit() option. Regions
located within the threshold distance # take a value of 1 in the
binary spatial weight matrix or a positive value in the nonbinary spatial
weight matrix, and take 0 otherwise. dist() is required.

dunit(km|mi) specifies the unit of distance. Either km
(kilometers) or mi (miles) must be specified. dunit() is required.

dms converts the degrees, minutes, and seconds format to a decimal
format.

approx uses the bilateral distance approximated by the simplified
version of the Vincenty formula.

detail displays summary statistics of the bilateral distance.

nomatsave does not save the bilateral distance matrix r(D) and spatial
weight matrix r(W) on the memory.

generate stores the spatial lag of varname in the dataset.

Examples

Case 1: Binary spatial weight matrix

. moransi CRIME, lat(y_cntrd) lon(x_cntrd) swm(bin) dist(50) dunit(km)

Case 2: Knn spatial weight matrix

. moransi CRIME, lat(y_cntrd) lon(x_cntrd) swm(knn 1) dist(50) dunit(km)

Case 3: Nonbinary spatial weight matrix by exponential function

. moransi CRIME, lat(y_cntrd) lon(x_cntrd) swm(exp 0.03) dist(.) dunit(km)

Case 4: Nonbinary spatial weight matrix by power function

. moransi CRIME, lat(y_cntrd) lon(x_cntrd) swm(pow 1) dist(.) dunit(km)

Case 5: approx option

. moransi CRIME, lat(y_cntrd) lon(x_cntrd) swm(pow 1) dist(.) dunit(km) approx

Case 6: generate option

. moransi CRIME, lat(y_cntrd) lon(x_cntrd) swm(pow 1) dist(.) dunit(km) generate

Results can be displayed in a map using the spshape2dta and grmap commands for Stata 15
or later (for the earlier version, shp2dta and spmap commands).

Stored results

moransi stores the following in r():

Scalars

r(I) Moran's I statistic

r(EI) Expected value of I

r(seI) Standard Error of I

r(zI) z-value of I

r(pI) p-value of I

r(N) number of observations

r(td) threshold distance

r(dd) distance decay parameter

r(knn) parameter k for swm(knn #)

r(dist_mean) mean of distance

r(dist_sd) standard deviation of distance

r(dist_min) minimum value of distance

r(dist_max) maximum value of distance

Macros

r(cmd) moransi

r(varname) name of variable

r(swm) type of spatial weight matrix

r(dunit) unit of distance

r(dist_type) exact or approximation

Matrices

r(D) lower triangle distance matrix

r(W) spatial weight matrix

Author

Keisuke Kondo

Research Institute of Economy, Trade and Industry

Tokyo, Japan

kondo-keisuke@rieti.go.jp

References

Kondo, K. (2016). "Hot and cold spot analysis using Stata," Stata Journal, volume 16, number 3: st0446

Kondo, K. (2017). "SPGEN: Stata module to generate spatially lagged variables,"
Statistical Software Components, Boston College. https://ideas.repec.org/c/boc/bocode/s458105.html