Stata 15 help for newvarlist

Title

[U] 11.4.2 Lists of new variables

Description

A newvarlist is a list of new variables:

1. A newvarlist can literally be a list of one or more newvars, listed one after another:

x x myvar inc92

2. You may use a dash to specify a set of variables:

p1-p90 (means p1 p2 ... p90) inc90-inc99 (means inc90 inc91 ... inc99)

3. You may specify a storage type in front of any element of the list. The numeric storage types are byte, int, long, float, and double. The string storage types are str#, where # is replaced with an integer between 1 and 2045, inclusive, representing the maximum length of the string, or strL. For example, you may type

double x str2 name int myvar double inc92

4. You may use parentheses to collect groups:

double(x myvar inc92) int(p1-p90)

The parentheses around p1-p90 were not necessary, but they clarify the meaning.

5. When you do not specify the type, the default type -- which is usually float -- is assumed:

double x myvar inc92 (myvar and inc92 will be float)

The default usually is float, but you can change it to double if you wish; see set type.

Because the default is float or double, you must specify str# if you want to create a string variable. Some commands understand str (without the number) and determine the length themselves. The generate command does not even require that str be specified; it creates a str# variable, where # is the smallest string that will hold the result.

Examples

--------------------------------------------------------------------------- Enter data on variable x from keyboard . input x

x 1. 1 2. 2 3. end

Add data for variables y and z and make them type double . input double (y z) y z 1. 3 4 2. 5 6

Add data for variable s and make it type str2 . input str2 s

s 1. ab 2. cd

Describe the data . describe

--------------------------------------------------------------------------- Setup . webuse genxmpl2 . generate str9 lastname = word(name, 2)

--------------------------------------------------------------------------- Setup . webuse genxmpl2, clear

Equivalent to above generate command . generate str lastname = word(name, 2)

--------------------------------------------------------------------------- Setup . webuse genxmpl2, clear

Equivalent to above generate command . generate lastname = word(name, 2) ---------------------------------------------------------------------------


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