Stata 15 help for clonevar

[D] clonevar -- Clone existing variable


clonevar newvar = varname [if] [in]


Data > Create or change data > Other variable-creation commands > Clone existing variable


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.


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.


--------------------------------------------------------------------------- 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 ---------------------------------------------------------------------------

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