help simulate
-------------------------------------------------------------------------------
Title
[R] simulate -- Monte Carlo simulations
Syntax
simulate [exp_list] , reps(#) [options] : command
options description
-------------------------------------------------------------------------
nodots suppress the replication dots
noisily display any output from command
trace trace the command
saving(filename, ...) save results to filename
nolegend suppress table legend
verbose display the full table legend
seed(#) set random-number seed to #
-------------------------------------------------------------------------
All weight types supported by command are allowed; see weight.
Description
simulate eases the programming task of performing Monte Carlo-type
simulations. Typing
. simulate exp_list , reps(#) : command
runs command for # replications and collects the results in exp_list.
command defines the command that performs one simulation. Most Stata
commands and user-written programs can be used with simulate, as long as
they follow standard Stata syntax. The by prefix may not be part of
command.
exp_list specifies the expression to be calculated from the execution of
command. If no expressions are given, exp_list assumes a default,
depending upon whether command changes results in e() and r(). If
command changes results in e(), the default is _b. If command changes
results in r() (but not e()), the default is all the scalars posted to
r(). It is an error not to specify an expression in exp_list otherwise.
Options
reps(#) is required -- it specifies the number of replications to be
performed.
nodots suppresses display of the replication dots. By default, one dot
character is displayed for each successful replication. A red `x' is
displayed if command returns an error or if one of the values in
exp_list is missing.
noisily requests that any output from command be displayed. This option
implies the nodots option.
trace causes a trace of the execution of command to be displayed. This
option implies the noisily option.
saving(filename [, suboptions]) creates a Stata data file (.dta file)
consisting of (for each statistic in exp_list) a variable containing
the replicates.
See prefix_saving_option, for details about suboptions.
nolegend suppresses display of the table legend. The table legend
identifies the rows of the table with the expressions they represent.
verbose requests that the full table legend be displayed. By default,
coefficients and standard errors are not displayed.
seed(#) sets the random-number seed. Specifying this option is
equivalent to typing the following command before calling simulate:
. set seed #
Examples
Make a dataset containing means and variances of 100-observation samples
from a lognormal distribution. Perform the experiment 10,000 times:
program define lnsim, rclass
version 11
syntax [, obs(integer 1) mu(real 0) sigma(real 1) ]
drop _all
set obs `obs'
tempvar z
gen `z' = exp(rnormal(`mu',`sigma'))
summarize `z'
return scalar mean = r(mean)
return scalar Var = r(Var)
end
. simulate mean=r(mean) var=r(Var), reps(10000): lnsim, obs(100)
Make a dataset containing means and variances of 50-observation samples
from a lognormal distribution with a normal mean of -3 and standard
deviation of 7. Perform the experiment 10,000 times:
. simulate mean=r(mean) var=r(Var), reps(10000): lnsim, obs(50) mu(-3)
sigma(7)
Also see
Manual: [R] simulate
Help: [R] bootstrap, [R] jackknife, [R] permute