help expand dialog: expand
-------------------------------------------------------------------------------
Title
[D] expand -- Duplicate observations
Syntax
expand [=]exp [if] [in] [, generate(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
---------------------------------------------------------------------------
Also see
Manual: [D] expand
Help: [D] contract, [D] expandcl, [D] fillin