楼主: nuli2012
2346 5

[数据管理求助] 已知每个农户的经纬度,求距离每个农户最近的五个农户,hhcode代表农户 [推广有奖]

  • 7关注
  • 1粉丝

已卖:665份资源

讲师

59%

还不是VIP/贵宾

-

威望
0
论坛币
2961 个
通用积分
6.2220
学术水平
39 点
热心指数
46 点
信用等级
39 点
经验
1207 点
帖子
222
精华
0
在线时间
881 小时
注册时间
2010-2-9
最后登录
2025-12-29

楼主
nuli2012 在职认证  发表于 2015-6-4 15:19:02 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
hhdata-311-new-2.dta (362.66 KB, 需要: 8 个论坛币)



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:code 经纬度 ODE COD 经纬度

本帖被以下文库推荐

沙发
andruw(真实交易用户) 在职认证  发表于 2015-6-4 15:40:41
哪个变量是经纬度?

藤椅
nuli2012(未真实交易用户) 在职认证  发表于 2015-6-4 15:42:30
andruw 发表于 2015-6-4 15:40
哪个变量是经纬度?
latitude
longitude

板凳
nuli2012(未真实交易用户) 在职认证  发表于 2015-6-4 15:46:23
andruw 发表于 2015-6-4 15:40
哪个变量是经纬度?
longitude
latitude

报纸
andruw(真实交易用户) 在职认证  发表于 2015-6-4 16:57:12
  1. gen distance1 = .
  2. gen distance2 = .
  3. gen distance3 = .
  4. gen distance4 = .
  5. gen distance5 = .

  6. gen close1 = .
  7. gen close2 = .
  8. gen close3 = .
  9. gen close4 = .
  10. gen close5 = .



  11. local n = _N
  12. quietly{
  13. forval i = 1/`n' {
  14.         forval j = 1/`n' {
  15.                 if hhcode[`i'] & hhcode[`j'] & (`i' != `j'){
  16.                         scalar d = (longitude[`i'] - longitude[`j'])^2 + (latitude[`i'] - latitude[`j'])^2
  17.                          if d < distance1[`i'] {
  18.                           replace distance5 = distance4 in `i'
  19.                           replace close5 = close4 in `i'
  20.                           replace distance4 = distance3 in `i'
  21.                           replace close4 = close3 in `i'
  22.                           replace distance3 = distance2 in `i'
  23.                           replace close3 = close2 in `i'
  24.                           replace distance2 = distance1 in `i'
  25.                           replace close2 = close1 in `i'
  26.                           replace distance1 = d in `i'
  27.                           replace close1 = hhcode[`j'] in `i'
  28.                           }
  29.                          if d < distance2[`i'] & d > distance1[`i'] {
  30.                           replace distance5 = distance4 in `i'
  31.                           replace close5 = close4 in `i'
  32.                           replace distance4 = distance3 in `i'
  33.                           replace close4 = close3 in `i'
  34.                           replace distance3 = distance2 in `i'
  35.                           replace close3 = close2 in `i'
  36.                           replace distance2 = d in `i'
  37.                           replace close2 = hhcode[`j'] in `i'
  38.                           }
  39.                          if d < distance3[`i'] & d > distance1[`i']  & d > distance2[`i'] {
  40.                           replace distance5 = distance4 in `i'
  41.                           replace close5 = close4 in `i'
  42.                           replace distance4 = distance3 in `i'
  43.                           replace close4 = close3 in `i'
  44.                           replace distance3 = d in `i'
  45.                           replace close3 = hhcode[`j'] in `i'
  46.                           }
  47.                          if d < distance4[`i'] & d > distance3[`i'] & d > distance1[`i']  & d > distance2[`i'] {
  48.                          replace distance5 = distance4 in `i'
  49.                          replace close5 = close4 in `i'
  50.                          replace distance4 = d in `i'
  51.                          replace close4 = hhcode[`j'] in `i'
  52.                          }
  53.                          if d < distance5[`i'] & d > distance4[`i'] & d > distance3[`i'] & d > distance1[`i']  & d > distance2[`i'] {
  54.                          replace distance5 = distance4 in `i'
  55.                          replace close5 = hhcode[`j'] in `i'
  56.                          }
  57.                 }
  58.         }
  59. }
  60. }


  61. drop distance1 distance2 distance3 distance4 distance5
复制代码
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
nuli2012 + 2 + 1 + 1 + 1 谢谢你~~~~

总评分: 论坛币 + 2  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

地板
andruw(真实交易用户) 在职认证  发表于 2015-6-4 17:02:33
andruw 发表于 2015-6-4 16:57
抛砖引玉,ssc应该有简单的方法。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-30 10:34