help clonevar
-------------------------------------------------------------------------------
Title
[D] clonevar -- Clone existing variable
Syntax
clonevar newvar = varname [if] [in]
Description
clonevar generates newvar as an exact copy of an existing variable,
varname, with the same storage type, values, and display format as
varname. varname's variable label, value labels, notes, and
characteristics will also be copied.
Remarks
clonevar has various possible uses. Programmers may desire that a
temporary variable appear to the user exactly like an existing variable.
Interactively, you might want a slightly modified copy of an original
variable, so the natural starting point is a clone of the original.
Examples
---------------------------------------------------------------------------
Setup
. sysuse auto
Create Mpg variable as an exact copy of existing variable mpg
. clonevar Mpg = mpg
---------------------------------------------------------------------------
Setup
. webuse travel, clear
. describe mode
. label list travel
Create airtrain to be a slightly modified copy of mode
. clonevar airtrain = mode if mode==1 | mode==2
List first through fifth observations on mode and airtrain variables
. list mode airtrain in 1/5
---------------------------------------------------------------------------
Also see
Manual: [D] clonevar
Help: [D] generate, [D] separate