Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: Returning a local macro within -simulate- command: Type mismatch error?


From   Rachel <academicgirl@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: Returning a local macro within -simulate- command: Type mismatch error?
Date   Thu, 29 May 2008 15:02:32 -0400

Thanks, Nick.

Also, an issue with the program you suggested below is that it takes
c(seed) as an argument, but doesn't return it.  I'd like the
simulation to return the value of c(seed) within each iteration.

If anyone else has any ideas, please let me know.

Thanks,
Rachel


On 5/29/08, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> Good question, except that I am not clear on what you are trying to do.
> The seed at the beginning of your process, together with your number of
> observations, would seem enough to characterise a particular simulation.
>
>
> As I understand it, -simulate- is executed just once, and so any
> initialisations are carried out just once. Whether you pass stuff as c()
> or r() makes no difference to that.
> In particular, anything passed as a macro, or in equivalent form, will
> get evaluated just once.
>
> You'll likely get a better answer from others who do this kind of thing
> much more than I do.
>
> Nick
>
> Rachel
>
> Nick,
>
> Thanks very much for the reply.  In fact, I am using Stata 10.  But
> suppose I want to capture the state of c(seed) not just at the end of
> each run of the program, but at several points therein.  It seems
> that, to do this, one would have to copy c(seed) to an r-class result?
>  For example:
>
> program define TrialProgram
>         clear
>        set obs 9000
>         capture drop x y
>         drawnorm x y
> //Want to return c(seed) here
>         regress y x
>         drawnorm z1 z2
> //Want to return the NEW state of c(seed) here
>         regress z1 z2
>  end
>
>
> Rachel
>
>
> On Thu, May 29, 2008 at 1:17 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
>> -capture drop x y- is redundant given -clear-.
>>
>> -----Original Message-----
>> From: owner-statalist@hsphsun2.harvard.edu
>> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
>> Sent: 29 May 2008 18:11
>> To: statalist@hsphsun2.harvard.edu
>> Subject: st: RE: Returning a local macro within -simulate- command:
> Type
>> mismatch error?
>>
>> Is this Stata 10? (If you are using an earlier version, you are asked
> to
>> state that fact.)
>>
>> This seems to work for me in Stata 10:
>>
>> capture program drop TrialProgram
>> program define TrialProgram
>>        clear
>>        set obs 9000
>>        capture drop x y
>>        drawnorm x y
>>        regress y x
>> end
>>
>> simulate _b _se, seed(`c(seed)') noisily reps(30): TrialProgram
>>
>> Notice that you can cut out the middle macro. There is no need to copy
>> from c(seed) to a r-class result, as c(seed) remains accessible.
>>
>> Nick
>> n.j.cox@durham.ac.uk
>>
>> Rachel
>>
>> I'm running a simulation and would like to know the state of the
>> random number generator in each loop.   A simplified version of the
>> program is below.  I'm getting the error "Type mismatch r(109)"
>> apparently as a result of the way I'm returning the local macro
>> seedinit.
>>
>> I may be missing something obvious, but I'd appreciate any suggestions
>> about how to fix this error.  Thanks very much.
>>
>> capture program drop TrialProgram
>> program define TrialProgram, rclass
>> clear
>> set obs 9000
>> local seedinit1=c(seed)
>> capture drop x y
>> drawnorm x y
>> regress y x
>> return local seedinit "`seedinit1'"
>> end
>>
>>
>> simulate _b _se seedinit=r(seedinit), noisily reps(30): TrialProgram
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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