空間權(quán)重矩陣與相關(guān)性檢驗(Stata)
1 空間相關(guān)性檢驗
cd "D:\Allcode\Stata\Spatial-Econometrics\chapter01"
*將權(quán)重數(shù)據(jù)轉(zhuǎn)化為矩陣
spatwmat using data\testwm.dta,name(W) // 或者使用 matlist W
* 矩陣查看,這里為0-1矩陣
由于窗口限制,不能很好顯示完整。
1.1 全局空間相關(guān)性檢驗
use data\test01.dta,clear
*變量描述
describe
/*
Contains data from data\test01.dta
Observations: 49
Variables: 6 21 Feb 2020 13:14
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Variable Storage Display Value
name type format label Variable label
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
id byte %8.0g Neighborhood id value
hoval float %9.0g Housing value (in $1,000)
income float %9.0g Household income (in $1,000)
crime float %9.0g Residential burglaries & vehicle thefts per 1,000 households
x float %9.0g x coordinate of centroid (in arbitrary digitizing units)
y float %9.0g y coordinate of centroid (in arbitrary digitizing units)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by:
end of do-file
*/
數(shù)據(jù)集test01是關(guān)于美國俄亥俄州哥倫布市的截面數(shù)據(jù),hoval是房價,income表示收入,crime為犯罪率。下面進行全局空間自相關(guān)檢驗
* 全局空間自相關(guān)檢驗(雙邊檢驗)_莫蘭指數(shù)
spatgsa crime,weights(W) moran twotail
1.2 局部空間自相關(guān)檢驗
* 局部空間自相關(guān)檢驗(雙邊檢驗)_莫蘭指數(shù)
spatlsa crime,weights(W) moran twotail
1.3 散點圖
* 行標準化權(quán)重矩陣
spatwmat using data\testwm.dta,name(W1) standardize
* 可視化
spatlsa crime,weights(W1) moran graph(moran) symbol(n)
2 權(quán)重矩陣
2.1 截斷距離權(quán)重矩陣
* 導(dǎo)入數(shù)據(jù)
use data\test02.dta,clear
部分數(shù)據(jù)結(jié)構(gòu)
* 生產(chǎn)截斷二進制距離矩陣(標準化)
spatwmat,name(W2) xcoord(x) ycoord(y) band(0 12) binary standardize
* 查看矩陣
matrix list W2
* 將矩陣W2轉(zhuǎn)化為文本txt
* 可能無法識別mat2txt命令,需要 ssc install mat2txt
mat2txt,matrix(W2) saving(out\weight) replace
* 將weight.txt轉(zhuǎn)化為excel格式
dataout using out\weight.txt,excel replace //ssc install dataout
轉(zhuǎn)化的矩陣后綴不是xlsx,而是xml,此時用excel打開即可
2.2 反距離權(quán)重矩陣
**# 5 反距離權(quán)重矩陣
spwmatrix gecon y x,wname(weight1) wtype(inv)
* 查看反距離權(quán)重矩陣
matlist weight1
* 保存為txt文件
mat2txt,matrix(weight1) saving(out\weight1) replace
* 轉(zhuǎn)化為excel數(shù)據(jù)
dataout using out\weight1.txt,excel
反二次方權(quán)重矩陣可以通過反距離權(quán)重相乘得到文章來源:http://www.zghlxwxcb.cn/news/detail-454468.html
* 反二次距離矩陣
mat weight2 = hadamard(weight1,weight1)
matlist weight2
mat2txt,matrix(weight2) saving(out\weight2) replace
dataout using out\weight2.txt,excel
生成新的權(quán)重矩陣可以用來檢驗空間相關(guān)性和空間計量建模。文章來源地址http://www.zghlxwxcb.cn/news/detail-454468.html
到了這里,關(guān)于空間權(quán)重矩陣與相關(guān)性檢驗(Stata)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!