Statalist


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

Re: st: Extracting repetition number in simulate


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Extracting repetition number in simulate
Date   Tue, 20 Nov 2007 19:54:47 +0000 (GMT)

--- Rachel <[email protected]> wrote:
> Is there a way to display the repetition number in simulate as the
> program is running (assuming the noisily option is specified)?  For
> example, is there a way to have Stata display the number i as it is
> running the ith repetition.  I realize that I could simply set this
> up by using a dummy scalar i and iterating it within the program, but
> that would necessitate setting it to zero before every run of
> -simulate-.  I was wondering whether there is an easier way.

This is the best I can do:
*---------------- begin example -------------------
capture program drop lnsim
program define lnsim, rclass
    version 10
    syntax [, obs(integer 1) mu(real 0) sigma(real 1) ]
    drop _all
    set obs `obs'
    tempvar z
    gen `z' = exp(`mu' + `sigma'*invnormal(uniform()))
    summarize `z'
    return scalar mean = r(mean)
    return scalar Var  = r(Var)
    di _n as txt "simulation " as result scalar(i) _n
    scalar i = scalar(i) + 1
end

scalar i = 1
simulate mean=r(mean) var=r(Var), reps(100) noi: lnsim, obs(100)
*---------------------------- end example ----------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

-- Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ 
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index