Suppose x is a continuous variable, we want to convert it to categorical. For example, we want to assign 1 to top 30%, 2 to middle 40%, and 3 to last 30%.
Stata
We can use xtile or egen cut in stata.
set obs 1000 |
R
cut{base} divides the range of x into intervals and codes the values in x according to which interval they fall. The leftmost interval corresponds to level one, the next leftmost to level two and so on.
cut(x, |
Matlab
ordinal is what you want, ref.
See also categorical.
p = 0:.25:1; |