*! version 1.0
help postsim

Title

postsim -- Post-estimation simulation

Syntax

postsim
exp_list
[, options]
: command

Main
reps(#) perform # replications; default is
reps(1000)

Options
saving(filename, ...)
save results to filename;
save values in double precision;
overwrite filename;
append results to filename

Advanced
seed(#) set random-number seed to #

forcepsd force the covariance matrix to be positive
semidefinite

svy is allowed; see [SVY] svy.

postsim is intended for use in conjunction with simqoi.

Description

postsim simulates the main and ancillary parameters of a statistical
model from their asymptotic sampling distribution
(Gelman et al, 2013, ch. 4).
Specifically, typing

. postsim exp_list, reps(#): command

executes command, and simulates reps(#) values of the parameters
in exp_list from a multivariate normal distribution with vector of means e(b) and covariance matrix e(V) (See ereturn).

command defines the estimation command to be executed.
Most Stata commands and user-written programs can be used with postsim,
as long as they have e(b) e(V) properties and follow
standard Stata syntax.
The by prefix may not be part of command.

exp_list specifies the parameters to be simulated from the
execution of command.
exp_list is optional and defaults to _b.

The expressions in exp_list are assumed to conform to the following
grammar.
Note that exp_list should not be enclosed in parentheses,
though individual expressions may be.

exp_list contains (name: elist)

elist

eexp

elist contains newvarname = (exp)

(exp)

eexp is specname

[eqno]specname

specname is _b

_b[]

eqno is ##

name

exp is a standard Stata expression; see help exp.

Because statistical simulation is a random process, the values generated
are a function of the current random-number seed or the number specified with
set seed().
If you want to be able to reproduce results, set the random-number
seed by specifying the seed(#) option or by typing

. set seed #

where # is a seed of your choosing, before running postsim; see
[R] set seed.

Options

Main

reps(#) specifies the number of replications or simulations to be performed.
The default is 1000.
The approximation to the asymptotic distribution becomes more accurate as #
increases.

Options

saving(filename[, suboptions]) creates
a Stata data file (.dta file) consisting of, for each parameter in
exp_list, a variable containing simulated values.

double specifies that the results for each replication be stored as
doubles, meaning 8-byte reals.
By default, they are stored as floats, meaning 4-byte reals.

replace specifies that filename be overwritten, if it exists.

append appends simulated data to the end of filename.

Advanced

seed(#) sets the random-number seed.
Specifying this option is equivalent to typing the following command prior
to calling postsim:

. set seed #

forcepsd modifies the covariance matrix to be positive semidefinite (psd),
and so be a proper covariance matrix.
If the covariance matrix is not positive semidefinite, it will have negative eigenvalues.
By setting negative eigenvalues to 0 and reconstructing, we obtain the least-squares
positive-semidefinite approximation.
This approximation is a singular covariance matrix.

Examples

Setup

. sysuse auto

Simulate model parameters

. postsim, saving(sims): probit foreign weight mpg

. describe using misms

Setup

. webuse nhanes2d

. svyset

Logistic regression using survey data

. postsim, saving(sims, replace): svy: logit highbp height weight age female

Saved results

postsim saves the following in r():

Scalars

r(N_reps) number of replications

Macros

r(prefix) postsim

r(cmdline) command as typed

r(seed) initial random-number seed

Matrices

r(b) simulated estimates

r(V) simulated variance-covariance matrix

References

Andrew Gelman, John B. Carlin, Hal S. Stern, David B. Dunson, Aki Vehtari, and Donald B. Rubin. 2013.
Bayesian Data Analysis.
CRC Press.

Author

Javier Márquez Peña,

Buendía & Laredo, Mexico City.

javier.marquez@buendiaylaredo.com

http://javier-marquez.com/software/moreclarify

Also see

Help: simqoi, estsimp (if installed);

[R] bootstrap, [R] jackknife, [R] permute, [R] simulate