Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: monte carlo simulation


From   Benjamin Hong <benjamin1459@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: monte carlo simulation
Date   Sun, 24 Feb 2013 20:57:55 +0000

Dear all,

Hi, I am trying to do basic monte carlo simulation with Stata, but for
some reason it doesnt work.
Would you tell me the reason?

below is my code
-------------------
program define benreg, rclass
version 10.0
syntax [, c(real 1)]
drop _all
set obs 10000
gen u=invnorm(uniform())
gen x=invnorm(uniform())
gen y = 2 + 3*x^3+u
reg y x
sum
return scalar b0=_b[_cons]
return scalar b1=_b[x]
simulate b_0=r(b0) b_1=r(b1), reps(10000): benreg
----------------------------
it always returns "non r-class program may not set r()" after reg y x.
(before return scalar)

I appreciate if somebody gives me advise!

Thanks in advance.

Best,

Ben




******************************************
Benjamin (Wonki) Hong
Certified Financial Risk Manager
MSc Finance, Edinburgh University
Phone: +44(0)752-121-9910
E-mail: benjamin1459@gmail.com
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index