Statalist


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

RE: st: RE: Simpler question: Returning a local macro within -simulate- command


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: Simpler question: Returning a local macro within -simulate- command
Date   Fri, 30 May 2008 17:35:51 +0100

This is I think the same question as the one before last, and I don't
have a better answer. 

It sounds as if you want something like this: 

capture program drop TrialProgram
program define TrialProgram, rclass
	clear
	set obs 9000
	capture drop x y
	drawnorm x y
	regress y x
	return local seed "`c(seed)'" 
end

simulate _b _se seed=r(seed), noisily reps(30): TrialProgram

However, I have not tried very hard but I can't get -simulate- to spit
out a string variable. 

My only other thought is to forget -simulate-, which is at heart a
convenience wrapper. 
Set up your own loop and emit whatever numeric and string (the seed)
results you want using -postfile-. 

Nick
n.j.cox@durham.ac.uk 

Rachel

Nick,

Yes, but I'd like it to be contained--perhaps as constant variable--
in the data file that results from -simulate-.  This is because I'm
generating a large number of files of this type. Is there any way to
do this?  If there's no way, I'll simply record it manually.

Thanks,
Rachel

On Fri, May 30, 2008 at 9:29 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> I don't think you need to do that.
>
> If what you want is to record the value of c(seed) that -simulate-
> starts with, then you only need record what is c(seed) just before you
> run -simulate-. So
>
> local seed `c(seed)'
>
> and/or
>
> di `c(seed)'
>
> will do that.
>
> Nick
>
> Rachel
>
> Here's a simpler question: How can I have simulate *return* just the
> initial value of c(seed)?  Nick suggested the following code, which
> takes c(seed) as an argument, but doesn't return it.  Thanks in
> advance for your help.
>
> capture program drop TrialProgram
> program define TrialProgram
>       clear
>       set obs 9000
>       capture drop x y
>       drawnorm x y
>       regress y x
> end

*
*   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