**[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
-------------------------------------------------------------------------
__str__**ata(***varlist***)** variables identifying strata
__cl__**uster(***varlist***)** variables identifying resampling clusters
__id__**cluster(***newvar***)** create new cluster ID variable
__w__**eight(***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 **fweight**s, 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**

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