Posting Monte Carlo results (STB-20: ssi6) --------------------------- ^postfile^ varlist ^using^ filename [^, e^very^(^#^)^ ^replace^] ^post^ exp exp ... exp ^postclos^ Description ----------- ^postfile^, ^post^, and ^postclos^ are utility commands to assist Stata programmers in performing Monte Carlo type experiments. ^postfile^ declares the variable and file names of a (new) Stata data set for containing results. ^post^ adds a new observation to the declared data set. ^postclos^ declares an end to the posting of observations. All three commands leave the data in memory undisturbed. After postclos, the previously declared data set contains the posted results and may be loaded with ^use^; see ^help use^. Options ------- ^every(^#^)^ specifies how often posted results are to be written to disk. ^post^ attempts to be efficient by buffering results and writing to disk only occasionally. ^every()^ should not be specified; the default value ^every(32)^ -- 23 for nonIntercooled versions of Stata -- is believed to be fastest. If ^every()^ is specified, it is taken as merely a suggestion; values that are too large (larger than 208 for Intercooled and 23 for regular Stata) are treated as meaning ^every(32)^ and ^every(23)^. ^replace^ indicates that the file specified (may) already exist and, if it does, ^postfile^ may erase the file and create a new one. Remarks ------- The basic outline for a simulation using post is: ^program define^ progname ^postfile^ ... ^using^ filename-for-results repeatedly { draw a sample make a calculation ^post^ ... } ^postclos^ ^use^ the results stored in filename-for-results ^end^ That is, declare the variable names and filename for the results once at the outset of the program using ^postfile^. Repeatedly store results into the file using ^post^. At the conclusion, close the file using ^postclos^. After that, the file of results exists and may be used. Example 1 --------- Make a data set containing means and variances of 100-observation samples from a log-normal distribution. Perform the experiment 10,000 times: ^program define lnsim^ ^version 3.1^ ^postfile mean var using results, replace^ ^quietly {^ ^local i = 1^ ^while `i' <= 10000 {^ ^drop _all^ ^set obs 100^ ^gen z = exp(invnorm(uniform()))^ ^summarize z ^ ^post _result(3) _result(4)^ ^local i=`i'+1^ ^}^ ^}^ ^postclos^ ^use results, clear^ ^end Also see -------- STB: ssi6 (STB-20) On-line: help for ^simul^