**[D] expand** -- Duplicate observations

__Syntax__

**expand** [**=**]*exp* [*if*] [*in*] [**,** __gen__**erate(***newvar***)**]

__Menu__

**Data > Create or change data > Other variable-transformation commands** **>**
**Duplicate observations**

__Description__

**expand** replaces each observation in the dataset with n copies of the
observation, where n is equal to the required expression rounded to the
nearest integer. If the expression is less than 1 or equal to missing,
it is interpreted as if it were 1, and the observation is retained but
not duplicated.

__Option__

**generate(***newvar***)** creates new variable *newvar* containing **0** if the
observation originally appeared in the dataset and **1** if the
observation is a duplicate. For instance, after an **expand**, you could
revert to the original observations by typing **keep** **if** *newvar***==0**.

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse stackxmpl**

List the original data
**. list**

Replace each observation with 2 copies of the observation (original
observation is retained and 1 new observation is created)
**. expand 2**

List the results
**. list**

---------------------------------------------------------------------------
Setup
**. webuse stackxmpl, clear**

List the original data
**. list**

Replace each observation with *x* copies of that observation, where *x* is
the value of **b** for that observation
**. expand b**

List the results
**. list**

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