Stata 15 help for clonevar

[D] clonevar -- Clone existing variable

Syntax

clonevar newvar = varname [if] [in]

Menu

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

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


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