Creating spatial weight matrix using Geoda and Stata

先使用Geoda生成gal文件,然后使用下面的stata commands来生成空间加权矩阵文件:

ssc install spwmatrix

* remove the first and last lines of the txt file spwmatrix import using
spwmatrix import using C:\Users\*USER*\Desktop\Tutorial\Weights_file.gal, wname(weights) xport(weights, txt)

insheet using "C:\Users\*USER*\Desktop\Tutorial\weights.txt", delim(" ") clear
save "weights.dta"

gen id = _n
order id, first

rename v(#) m(#)
rename v(##) m(##)
rename v(###) m(###)

gsort -id
drop id

gen id = _n
order id, first

Source: [Source 1] [Source 2]