```help mata mm_cut()
-------------------------------------------------------------------------------

Title

mm_cut() -- Categorize a data vector

Syntax

real colvector mm_cut(x, at [, sorted])

where

x:  real colvector containing data points

at:  real vector containing cutting points, in ascending order

sorted:  real scalar indicating that the data are sorted

Description

mm_cut() may be used to categorize the values of x according to the
cutting points supplied by at (at must be sorted in ascending order).
That is, mm_cut() returns a colvector containing at if
at<=x[i]<at, at if at<=x[i]<at, ..., at[length(at)] if
at[length(at)]<=x[i] for each i=1,...,rows(x).

sorted!=0 indicates that x is sorted in ascending order. If sorted!=0 is
specified, mm_cut() skips the internal sorting and saves some time.

Remarks

Example:

: x = uniform(9,1) \ 0.5

: x, mm_cut(x, (0,0.25,0.5,0.75))
1             2
+-----------------------------+
1 |  .6262498463            .5  |
2 |  .4967679521           .25  |
3 |  .9357729778           .75  |
4 |  .1331598342             0  |
5 |   .532077587            .5  |
6 |  .1199395712             0  |
7 |  .8957326778           .75  |
8 |  .7477880118            .5  |
9 |  .9198338806           .75  |
10 |           .5            .5  |
+-----------------------------+

Note that

: mm_cut(x, rangen(min(x),max(x),n+1)[|1 \ n|])

categorizes x into n equally spaced intervals.

Conformability

mm_cut(x, at, sorted)
x:  n x 1
at:  r x 1 or 1 x c
sorted:  1 x 1
result:  n x 1.

Diagnostics

mm_cut() returns missing if x is missing or if x is smaller than the
first cutting point.

mm_cut() produces erroneous results if at is not sorted.

Source code

mm_cut.mata

Author

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

Also see

Online:  help for [M-5] range(), [M-4] utility, moremata
```