cd D:\statasp\stata制空间权重矩阵代码数据
set matsize 11000
use county_jingweidu.dta, clear
//(1)计算01矩阵
spatwmat, name(W01) xcoord(x) ycoord(y) band(0 12) binary standardize
matlist W01
mat2txt,matrix(W01) saving(3180)replace //矩阵保存为txt文件
dataout using 3180.txt,word excel //矩阵转换为word和excel文件
//(2)反距离矩阵和地理矩阵平方的好方法
clear all
// ssc install spwmatrix
cd D:\statasp\stata制空间权重矩阵代码数据
use county_jingweidu.dta, clear
spwmatrix gecon y x, wname(winvsq) wtype(inv)
matlist winvsq
mat2txt,matrix(winvsq) saving(3180d)replace //矩阵保存为txt文件,县级太多,跑不出来,考虑减少样本
dataout using 3180d.txt,word excel //矩阵转换为word和excel文件
mat w1=hadamard(winvsq,winvsq) //距离倒数的平方
matlist w1
mat2txt,matrix(w1) saving(3180d)replace //矩阵保存为txt文件
dataout using 3180.txt,word excel //矩阵转换为word和excel文件
clear all
cd D:\statasp
use city_jingweidu.dta, clear
//(1)计算01矩阵
spatwmat, name(W01) xcoord(x) ycoord(y) band(0 12) binary standardize
matlist W01
mat2txt,matrix(W01) saving(310)replace //矩阵保存为txt文件
dataout using 310.txt,word excel //矩阵转换为word和excel文件,地级城市
//(2)反距离矩阵和地理矩阵平方的好方法
clear all
// ssc install spwmatrix
cd D:\statasp
use city_jingweidu.dta, clear
spwmatrix gecon y x, wname(winvsq) wtype(inv)
matlist winvsq
mat2txt,matrix(winvsq) saving(310d)replace //矩阵保存为txt文件
dataout using 310d.txt,word excel //矩阵转换为word和excel文件
mat w1=hadamard(winvsq,winvsq) //距离倒数的平方
matlist w1
mat2txt,matrix(w1) saving(310d)replace //矩阵保存为txt文件
dataout using 310.txt,word excel //矩阵转换为word和excel文件
clear all
cd D:\statasp
use jingweidu.dta, clear
(1)计算01矩阵
spatwmat, name(W01) xcoord(x) ycoord(y) band(0 12) binary standardize
matlist W01
mat2txt,matrix(W01) saving(100)replace //矩阵保存为txt文件
dataout using 100.txt,word excel //矩阵转换为word和excel文件,省级矩阵
(2)反距离矩阵和地理矩阵平方的好方法
clear all
ssc install spwmatrix
cd D:\statasp
use jingweidu.dta, clear
spwmatrix gecon y x, wname(winvsq) wtype(inv)
matlist winvsq
mat2txt,matrix(winvsq) saving(111)replace //矩阵保存为txt文件
dataout using 111.txt,word excel //矩阵转换为word和excel文件
mat w1=hadamard(winvsq,winvsq) //距离倒数的平方
matlist w1
mat2txt,matrix(w1) saving(130)replace //矩阵保存为txt文件
dataout using 130.txt,word excel //矩阵转换为word和excel文件