Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Saving matrices with -simulate-


From   Bert Jung <[email protected]>
To   [email protected]
Subject   st: Saving matrices with -simulate-
Date   Sun, 8 May 2011 11:25:33 -0400

Dear Statalisters,

I am using -simulate- to write a bootstrap routine.  In addition to
the usual statistics (coefficient estimates), I would like -simulate-
to save additional information that my program returns as a matrix.

In the following toy example, -myboot- returns the coefficients and a
matrix "seed" with the random seed that I created inside the program.
But "seed" is not saved in every bootstrap iteration; -simulate- only
saves the coefficients.  (This is just for illustration, of course.)

Thanks for any pointers.

Best, Bert



cap program drop myboot
program define myboot, eclass

	local seed = round( runiform()*1000000, 1 )
	set seed `seed'
	
	bsample
	
	reg mpg rep78 trunk weight
	
	mat seed = ( `seed' )
	mat list seed
	
	ereturn matrix seed=seed
	
end

	
sysuse auto, clear

reg mpg rep78 trunk weight
mat coeffs = e(b)

simulate , reps(10): myboot

ereturn list
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index