Stata Egen

The egen command is an extended generate command.


Usage


Egen Functions

AnyCount

anycount(varlist), values(numlist) returns the number of variables in varlist equal to any integer value in numlist.

AnyMatch

anymatch(varlist), values(integer numlist) returns 1 if any variable in varlist is equal to any integer value in numlist, and 0 otherwise

AnyValue

anyvalue(varname), values(integer numlist) returns the name of varname if varname is equal to any integer value in numlist

Concat

concat(varlist) returns the end-to-end concatenation of each variable in varlist. Numeric variables in varlist are implicitly converted to string values.

To insert a string between each variable in varlist, try concat(varlist), punct(string).

Count

count(expression) returns the number of non-missing observations in expression.

Cut

cut(varname), at(numlist)

cut(varname), group(number)

Diff

diff(varlist)

Ends

ends(varname)

Fill

fill(numlist)

Group

group(varlist) returns a sequential identifier for each unqiue combination of the values in varlist.

To generate an identifier for groups of duplicates, try:

sort keyvarlist
by keyvarlist: gen dup = cond(_N==1,0,_n)
egen grp = group(keyvarlist)

Iqr

iqr(expression)

Kurt

kurt(expression)

Mad

mad(expression)

Max

max(expression)

MDev

mdev(expression)

Mean

mean(expression)

Median

median(expression)

Min

min(expression)

Mode

mode(varname)

Pc

pc(expression)

Pctile

pctile(expression)

Rank

rank(expression)

RowFirst

rowfirst(varlist)

RowLast

rowlast(varlist)

RowMax

rowmax(varlist)

RowMean

rowmean(varlist)

RowMedian

rowmedian(varlist)

RowMin

rowmin(varlist)

RowMiss

rowmiss(varlist)

RowNonMiss

rownonmiss(varlist)

RowPctile

rowpctile(varlist)

RowSd

rowsd(varlist)

RowTotal

rowtotal(varlist)

Sd

sd(expression)

Seq

seq()

Ske3w

skew(expression)

Std

std(expression)

Tag

tag(varlist)

Total

total(expression)


See also

Stata manual for egen


CategoryRicottone

Stata/Egen (last edited 2023-06-08 01:05:43 by DominicRicottone)