slnau1978 发表于 2010-2-8 09:28 
问题(2)的编程,但是这里的return scalar b1 = _b[x1],不能跟其他编程一样使用。很迷惑!
*****************************************************
……
在NL回归中,参数与解释变量之间并不存在一一对应的关系,因此无法通过引用变量名称的方式来引用参数。
正确的方式是引用NL回归后的返回矩阵 e(b) 中的元素。
你的程序修改如下:
cap program drop nlssim_1
program define nlssim_1,rclass
version 10.0
drop _all
use C:\data-10.dta
gen v2=1/(exp(1*x1+1*x2+1*x3)) /*方案一的假定*/
gen f=rnormal(-(ln(v+1))/2,ln(v+1))
gen y=exp(1*x1+1*x2+1*x3+f)
replace y=0 if dc==0
nl: y x1 x2 x3
nl (y = exp({b1=1}*x1+{b2=1}*x2+{b3=1}*x3))
mat B = e(b)
return scalar b1 = B[1,1]
end
*------------------------------------------
simulate b1=r(b1) , reps(10) saving (sl1): nlssim_1
sum