Stata 15 help for _stubstar2names


[P] _stubstar2names -- Parsing new variable lists


_stubstar2names new_var_spec , nvars(#) [ zero outcome singleok nosubcommand ]

where new_var_spec is either newvarlist or stub*; see newvarlist.


_stubstar2names is a programmer's tool that helps with parsing a newvarlist; see newvarlist. This tool requires the programmer to specify how many new variable names are expected. This tool will turn stub* into a list of names that begin with stub and are indexed by sequential integers.


nvars(#) is required, and specifies the number of new variable names.

If supplied with newvarlist, this option enforces that there are # names in newvarlist.

If supplied with stub*, this option identifies how many names to generate. By default, the names will be stub1, stub2, ... stub#.

zero indicates that the generated names start with stub0 instead of stub1. This option is only effective when _stubstar2names is supplied with stub*.

outcome modifies the error message produced when new_var_spec is a newvarlist with the incorrect number of variables. By default, the error message mentions "equations" and the equation() instead of "outcomes" and the outcome().

singleok indicates that new_var_spec is allowed to contain one name, even if #>1 in the nvars() option.

nosubcommand limits the error message display when the list of new names is not equal to nvars(). No reference to the use of option equation() (or outcome()) is given.


. _stubstar2names ex*, nvars(5) . sreturn list

macros: s(stub) : "1" s(typlist) : "float float float float float" s(varlist) : "ex1 ex2 ex3 ex4 ex5"

. _stubstar2names ex, nvars(5) too few variables specified r(102);

. _stubstar2names ex, nvars(5) single . sreturn list

macros: s(stub) : "0" s(typlist) : "float" s(varlist) : "ex"

. _stubstar2names ex*, nvars(5) zero . sreturn list

macros: s(stub) : "1" s(typlist) : "float float float float float" s(varlist) : "ex0 ex1 ex2 ex3 ex4"

. _stubstar2names double ex*, nvars(5) . sreturn list

macros: s(stub) : "1" s(typlist) : "double double double double double" s(varlist) : "ex1 ex2 ex3 ex4 ex5"

. sysuse auto, clear (1978 Automobile Data)

. _stubstar2names ex1 ex2 ex3 mpg, nvars(4) mpg already defined r(110);

Stored results

_stubstar2names stores the following in s():

Macros: s(varlist) list of new variable names s(typlist) list of types for the new variables s(stub) 0, or 1; indicator for stub* in new_var_spec

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