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

Re: st: Saving intermediate results (variables) when running -simulate-

From   Maarten buis <>
Subject   Re: st: Saving intermediate results (variables) when running -simulate-
Date   Wed, 22 Aug 2007 18:46:01 +0100 (BST)

--- Rachel <> wrote:
> I am using simulate to run a series of regressions and return the
> coefficients and standard errors.  What's the easiest way to have
> Stata save the values of the independent and the residuals for each
> observation after each repetition?

I am assuming you do not want to save the dataset but some coeficients.
(If you want to save the dataset aswell it is better to just create one
big dataset in one go and not loop over various randomly generated
smaller datasets, which is essentially what -simulate- does.)

what about this:
*------------------ begin example -----------------
capture program drop simprog
program simprog, eclass
drop _all
set obs 1000
gen x=uniform()
drawnorm resid
local beta=2
gen y=`beta'*x+resid
regress y x
matrix b = e(b)
matrix V = e(V)
local rmse = e(rmse)
ereturn post b V
ereturn scalar rmse = `rmse'

simulate _b _se rmse=e(rmse), reps(20): simprog
*------------------ end example -------------------

Hope this helps,

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

Want ideas for reducing your carbon footprint? Visit Yahoo! For Good
*   For searches and help try:

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