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

Re: st: Extracting repetition number in simulate

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

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

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 )

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

Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
*   For searches and help try:

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