全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2075 10
2014-02-12
各位前輩,
      最近遇到一個比較棘手的問題,我現有一個省份的鄉鎮市區的boundary的座標(經緯度),希望通過stata來計算這些鄉鎮市區的面積和中心,請問各位前輩具體的語法應該怎麼寫。我之前在網路查過一個Pro.Nick寫的Program ,試著運行但是數據沒有什麽變化,即是我的data當中并沒有產生一個新的叫area的變項。
      以下是語法
      *! NJC 1.0.0 15 August 2003
program polyarea, rclass
version 12
syntax varlist(min=2 max=2 numeric) [in]

tokenize `varlist'
args x y

marksample touse, novarlist
qui count if `touse' & (missing(`x') | missing(`y'))
if r(N) {
di as err "missing values in data"
exit 198
}

tempvar order area

gen long `order' = _n
su `order' if `touse', meanonly

qui gen `area' = `touse' * ///
(`x'[_n + 1] - `x') * (`y'[_n + 1] + `y') / 2
qui replace `area' =       ///
(`x'[`r(min)'] - `x') * (`y'[`r(min)'] + `y') / 2 in `r(max)'
su `area', meanonly

di as res %9.0g abs(r(sum))
return scalar area = abs(r(sum))
end


謝謝各位前輩,希望斑竹不要再刪除我的帖子。謝謝。
附件列表

data sample.xlsx

大小:294.24 KB

 马上下载

二维码

扫码加我 拉你入群

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

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

全部回复
2014-2-13 05:19:02
it looks like the program return the area in scalar, not a variable in data.  If you do

sca list area

does it show anything?
二维码

扫码加我 拉你入群

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

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

2014-2-13 13:54:50
jjjj6666 发表于 2014-2-13 05:19
it looks like the program return the area in scalar, not a variable in data.  If you do

sca list  ...
thanks a lot for your concern ,I have tried your suggestion"sca list area"but failed    Stata showed the result below
sca list area
scalar area not found
r(111);

二维码

扫码加我 拉你入群

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

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

2014-2-14 01:07:52
sorry, it return the sca in return list, using "di r(area)" instead.

also, when calling this program, did you get any error?
二维码

扫码加我 拉你入群

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

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

2014-2-14 03:20:23
jjjj6666 发表于 2014-2-14 01:07
sorry, it return the sca in return list, using "di r(area)" instead.

also, when calling this prog ...
hello,so grateful for your help.I have tried "di r(area)"but nothing showed in the scree.That is the trouble it seems that the program runs successfully without any erro ,but I can't get the value of area.
二维码

扫码加我 拉你入群

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

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

2014-2-14 04:27:17
can you post the data with the x y variables only if it's not big? It seems the program will output something, at least.
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群