stata根据经纬度生成空间权重矩阵

实用

clear all
cd C:\desk\2019全国行政区划
 use 284个城市经纬度.dta, clear
   //1)计算01矩阵,此方法不靠谱,建议gis加geoda
 spatwmat, name(W01) xcoord(lon1) ycoord(lat1) band(0 12) binary 
 //加standardize为标准化
 matlist W01
 mat2txt,matrix(W01) saving(284)replace  //矩阵保存为txt文件
dataout using 284.txt,word excel  //矩阵转换为word和excel文件,省级矩阵
 //2)反距离矩阵和地理矩阵平方的好方法
  clear all
cd C:\desk\2019全国行政区划
    use 284个城市经纬度.dta, clear
  spwmatrix gecon lat1 lon1, wname(w02) wtype(inv)
          matlist w02
mat2txt,matrix(w02) saving(284距离)replace  //矩阵保存为txt文件
 dataout using 284距离.txt,word excel  //矩阵转换为word和excel文件
 mat w1=hadamard(w02,w02)  //距离倒数的平方
 matlist w1
mat2txt,matrix(w1) saving(284平方)replace  //矩阵保存为txt文件
dataout using 284平方.txt,word excel  //矩阵转换为word和excel文件

实践过得代码

cd C:\Users\Admin\Desktop\2022-1115
use"经纬度数据.dta" ,replace //你的dta文件,注意要带经纬度
spatwmat, name(W01) xcoord(x) ycoord(y) band(0 12) binary standardize 
matrix list W01 //列出矩阵
matrix A = W01
clear
svmat A, names(w) 

mat2txt,matrix(W01) saving(100.txt) replace //矩阵保存为txt文件。mat2txt需要安装
dataout using 100.txt,word excel //矩阵转换为word和excel文件,保存在默认的存储文件夹下

网络资源

clear all
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文件

  • 7
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小蜗笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值