Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: monte carlo simulation
From
"Benjamin W. Hong" <[email protected]>
To
<[email protected]>
Subject
RE: st: monte carlo simulation
Date
Tue, 26 Feb 2013 00:12:23 -0000
Nick,
Thank you very much!
Ben
------------------------------------
Benjamin Won-Ki Hong
Master of Science in Finance and Investment
Financial Risk Manager - Certified by the Global Association of Risk
Professionals
Phone: +44-752-121-9910
E-mail: [email protected]
Address: 17/4 Lutton Place. EH8 9PD, Edinburgh, UK
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, February 25, 2013 12:49 AM
To: [email protected]
Subject: Re: st: monte carlo simulation
You are writing for Stata 10, in which it is possible and simpler to write
-rnormal()- rather than the older nested call. There is no problem with
writing what you did otherwise.
Nick
On Sun, Feb 24, 2013 at 9:38 PM, Benjamin Hong <[email protected]>
wrote:
> Dear Nick,
>
> Thank you very much! and thanks for spelling corrections :) Can I ask
> one more question?
> why did you change "gen u=invnorm(uniform())" to "gen u = rnormal()"?
>
> Thanks!
>
> Best
> Ben
>
> 2013/2/24 Nick Cox <[email protected]>:
>> You are trying to call -benreg- from a call to -simulate- _within-
>> -benreg-. That's not the way to use -simulate-.
>>
>> I see no -end- statement marking the end of the program definition.
>>
>> You may have some previous version of the program in memory.
>>
>> This will work
>>
>> program benreg, rclass
>> version 10.0
>> syntax [, c(real 1)]
>> clear
>> set obs 10000
>> gen u = rnormal()
>> gen x = rnormal()
>> gen y = 2 + 3*x^3+u
>> sum
>> reg y x
>> return scalar b0=_b[_cons]
>> return scalar b1=_b[x]
>> end
>>
>> simulate b_0=r(b0) b_1=r(b1), reps(10000): benreg
>>
>> Standard spelling is Monte Carlo (a placename).
>>
>> Nick
>>
>> On Sun, Feb 24, 2013 at 8:57 PM, Benjamin Hong <[email protected]>
wrote:
>>> 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!
*
* 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/
*
* 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/