Stata 15 help for bsample

[R] bsample -- Sampling with replacement

Syntax

bsample [exp] [if] [in] [, options]

where exp is a standard Stata expression specifying the size of the sample; see exp.

exp must be less than or equal to _N (the number of observations) when neither the cluster() nor the strata() option is specified. _N is the default when exp is not specified.

Observations that do not meet the optional if and in criteria are dropped from the resulting dataset.

options Description ------------------------------------------------------------------------- strata(varlist) variables identifying strata cluster(varlist) variables identifying resampling clusters idcluster(newvar) create new cluster ID variable weight(varname) replace varname with frequency weights -------------------------------------------------------------------------

Menu

Statistics > Resampling > Draw bootstrap sample

Description

bsample replaces the data in memory with a bootstrap sample (random sample with replacement) drawn from the current dataset. Clusters can be optionally sampled during each replication in place of observations. Bootstrap samples can also be selected within strata.

Options

strata(varlist) specifies the variables identifying strata. If strata() is specified, bootstrap samples are selected within each stratum, and exp must be less than or equal to _N within the defined strata.

cluster(varlist) specifies the variables identifying resampling clusters. If cluster() is specified, the sample drawn during each replication is a bootstrap sample of clusters, and exp must be less than or equal to N_c (the number of clusters identified by the cluster() option). If strata() is also specified, exp must be less than or equal to the number of within-strata clusters.

idcluster(newvar) creates a new variable containing a unique identifier for each resampled cluster.

weight(varname) specifies a variable in which the sampling frequencies will be placed. varname must be an existing variable, which will be replaced. After bsample, varname can be used as an fweight in any Stata command that accepts fweights, which can speed up resampling for commands like regress and summarize. This option cannot be combined with idcluster().

By default, bsample replaces the data in memory with the sampled observations; however, specifying the weight() option causes only the specified varname to be changed.

Examples

--------------------------------------------------------------------------- Setup . webuse bsample1

Take bootstrap sample of size 200 . bsample 200

--------------------------------------------------------------------------- Setup . webuse bsample1, clear

Take bootstrap samples of size 200 for females and males . bsample 200, strata(female)

--------------------------------------------------------------------------- Setup . webuse bsample1, clear

Take 10% bootstrap samples for females and males . bsample round(0.1*_N), strata(female)

--------------------------------------------------------------------------- Setup . webuse bsample1, clear

Take bootstrap sample of size 200 from females . bsample 200 if female

---------------------------------------------------------------------------


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