help for stvarag

Aggregated Values of String Variable(s)

stvarag collects aggregated values of string variable(s) by vertical way (i.e. row-by-row).

Syntax

stvarag strvarlist [if] [in] , [ by(varlist) generate(newvarlist) suffix(string) dups uniq nogen parse(parse_strings) order notrim ]

Where the type of strvarlist must be string.

by(varlist) is optional, defines group (time) variable(s). It is applied to panel, longitudinal or multidimensional data.

generate(newvarlist) is optional, defines the name(s) of new aggregated variable(s), and not allow with option suffix(string) or nogen.

suffix(string) is optional, supplles a suffix for new variable(s). The default is to replace the original variable(s).

dups is optional, generates a new variable on duplicate values of strvarlist, named with suffix as _dups.

uniq is optional, generates a new variable on unique values of strvarlist, named with suffix as _uniq.

nogen is optional, not generate new aggregated variables; should be set with dups or uniq, but not wtih generate(newvars) or suffix(string).

parse(parse_strings) is optional, parses on specified strings; The default is to parse on spaces (i.e. parse(" ")).

order is optional, sorts contents of the new variable(s) in ascending order. The default is keeping the original order.

notrim is optional, doesn't trim leading or trailing spaces of original and new variable(s). The default is to trim them.

*** Important Notes:

1. The option generate(newvarlist), suffix(string) or nogen should be set at most one, and if neither is set, the default is replacing original variable(s);

2. If the option generate(newvarlist) is set, its number and order must be correspond one-to-one with strvarlist;

3. If the option dups is set, a string appears n times in the variable with suffix _dups, which means n + 1 times in the original variable;

4. If the option parse(parse_strings) is "null", it means no parse string (i.e. null space) are used for joining;

5. The command stvarag may generate some variables named with suffixes as follows: _dups , _uniq ,

So, you should avoid to including variables names with these suffixes.

Examples

Basic examples:

. clear

. input double year str43 nball

. 2019	"Antetokounmpo,	George,	Jokic,	Harden,	Curry"

. 2018 "James, Durant, Davis, Harden, Lillard"

. 2017 "James, Leonard, Davis, Harden, Westbrook"

. end

. stvarag nball

. stvarag nball, p(;) g(new)

. stvarag nball, p(,) n d

. stvarag nball, p(,) s(N)

. stvarag nball, p(,) s(N) d u

. stvarag nball, p(,) s(N) d u o

. fdtax ,f(,) t(" ")

. stvarag nball, s(N) d u o

. stvarag nball, p(null)

Run the command row-by-row (non-aggregate), similar to the command stvarud:

. gen id=_n

. replace nball = "James, Durant, Davis, Harden, Lillard, James" in 2

. stvarag nball, by(id) p(,) u n

Authors

Dejin Xie, School of Economics and Management, Nanchang University, China.

E-mail: xiedejin@ncu.edu.cn.

Also see

Help: local, functions; stvarcom, ecollapse (if they are installed).