help mata mm_freq()-------------------------------------------------------------------------------

Title

mm_freq() -- Compute frequency counts

Syntax

real colvectormm_freq(x[,w,levels])

real colvector_mm_freq(x[,w,levels])

real colvectormm_freq2(x[,w])

real colvector_mm_freq2(x[,w])where

x:transmorphic matrixcontaining data, rows are observations

w:real colvectorcontaining weights

levels:transmorphic matrixcontaining levels of data, in ascending order

Description

mm_freq()returns the frequency counts of the "levels" (unique rows) ofx. That is,mm_freq()computes the frequency distribution ofx. The frequency counts are returned in ascending sort order of the levels ofx.

wspecifies weights associated with the observations inx. Omitw, or specifywas 1 to obtain unweighted results.

levelsspecifies the levels to be counted.levelsmust be sorted in ascending order. Iflevelsis omitted,mm_freq()determines the frequency counts of all levels ofx. Furthermore,levels==. indicates to determine the counts of all levels and, additionally, return the levels ofxinlevels.

mm_freq2()returns for each row ofxthe number of duplicates inx(or the sum of weights associated with the duplicates, respectively).

_mm_freq()and_mm_freq2()are likemm_freq()andmm_freq2(), but assume thatxis sorted.

RemarksExample:

: x = (1\2\3\.\1\3\1\1\2\3\.) : mm_freq(x,1) 1 +-----+ 1 | 4 | 2 | 2 | 3 | 3 | 4 | 2 | +-----+

: x, mm_freq2(x,1) 1 2 +---------+ 1 | 1 4 | 2 | 2 2 | 3 | 3 3 | 4 | . 2 | 5 | 1 4 | 6 | 3 3 | 7 | 1 4 | 8 | 1 4 | 9 | 2 2 | 10 | 3 3 | 11 | . 2 | +---------+

: l = (0\1\2) : f = mm_freq(x,1,l) : l, f 1 2 +---------+ 1 | 0 0 | 2 | 1 4 | 3 | 2 2 | +---------+

Note that

: f = mm_freq(x,1,l=.) : l, f 1 2 +---------+ 1 | 1 4 | 2 | 2 2 | 3 | 3 3 | 4 | . 2 | +---------+

is equivalent to

: l = uniqrows(x) : f = mm_freq(x,1,l) : l,f 1 2 +---------+ 1 | 1 4 | 2 | 2 2 | 3 | 3 3 | 4 | . 2 | +---------+

Furthermore,

mm_freq()may also be used with strings:: s = ("a"\"b"\"c"\"b") : mm_freq(s,1) 1 +-----+ 1 | 1 | 2 | 2 | 3 | 1 | +-----+

Conformability

mm_freq(x,w,levels),_mm_freq(x,w,levels):x:n x cw:n x1 or 1x1levels:l x corlevels==.result:l x1.

mm_freq2(x,w),_mm_freq2(x,w):x:n x cw:n x1 or 1x1result:n x1.

DiagnosticsNone.

Source codemm_freq.mata

AuthorBen Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also seeOnline: help for

[M-5] uniqrows(),[M-4] utility,mm_levelsof(),moremata