egen

by varlist: egen var1=command(varlist)

Command GroupCommandDescriptionby
anycount(varlist), values(numlist)counts number of variables equal to any member of numlist (integers only)
anymatch(varlist), values(numlist) 1 if any variables equal to any member of numlist (integers only)
anvyvalue(varname), values(numlist) returns varname if varname value equal to any member of numlist (integers only)
concat(varlist), punct(pchars) creates a string comprising values of varlist
count(exp) counts nonmissing observations of variable exp
cut(varname), {at(#,#,...#)|group(#)} [icodes label] creates a new categorical variable based on varname
diff(varlist) tests whether values of varlist are equal
ends(strvar) returns last word of strvar
group(varlist) creates categorical variable for values in varlist
Stats
(by allowed)
max(exp) returns max of variable exp
mean(exp) returns mean of variable exp
min(exp) returns min of variable exp
median(exp) returns median of variable exp
pctile(exp), p(#) returns #th percentile of variable exp
rank(exp) returns rank of variable exp
sd(exp) returns standard deviation of variable exp
total(exp) returns sum of variable exp
Stats by Row rowmax(varlist) returns max of values in varlist
rowmean(varlist) returns mean of values in varlist
rowmin(varlist) returns min of values in varlist
rowmedian(varlist) returns median of values in varlist
rowpctile(varlist), p(#) returns #th percentile of values in varlist
rowsd(varlist) returns standard deviation of values in varlist
rowtotal(varlist) returns sum of values in varlist