全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
3421 0
2010-09-21
clear
set more off
capture program drop buffon   
program define buffon, rclass
version 11.1
syntax [, obs(integer 1000), grade(int 100) ]
drop _all
local obs2 = int(`obs’*1.5)
set obs `obs2'
tempvar x0 y0 x1 y1 x2 y2
gen `y 0’ = uniform()
gen `x0’ = uniform()
keep if `y0’^2+`x0’^2<=1
keep if _n<=`obs’
gen `x1’ = uniform()*100
gen `y1’ = uniform()*100
gen `x2’ = `x1’+`x0’/sqrt(`x0’^2+`y0’^2)
gen `y2’ = `y1’+`y0’/sqrt(`x0’^2+`y0’^2)
gen hit = (int(`x1')~=int(`x2'))
sum hit
local temp = r(mean)
local pi = 2/`temp'
return scalar pi = `pi'
end
simulate pi=r(pi) , reps(1000): buffon, obs(10000)

此程序运行后,提示
`obs’ invalid name
an error occurred when simulate executed buffon
r(198);
end of do-file
怎么解决呀?
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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