Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: stats
See also: frequency descriptive discrete

Quantlet: categorize
Description: creates dummy variables from a data with respect to distinct realizations. The default reference category is the minimal value in each column. Alternatively, categorization can be done by giving a value or the index (rank among the realizations) in a column.

Usage: {xc,xcvars}=categorize(x {,reftype,refvalue} {,xvars})
Input:
x n x p matrix, the columns correspond to the variables.
reftype optional, either "value" when reference values shall be given or "index" when indices of reference values shall be given.
refvalue optional, p x 1 vector, reference values or indices of reference values. If it is impossible to use one of these values, the corresponding variable is not categorized.
xvars optional, p x 1 string vector, variable names.
Output:
xc n x pc matrix, the categorized data.
xcvars pc x 1 string vector, variable names of categorized data, where the numbers of categories are preceeded by "#". If xvars was not given, the variable names for x are set as "Variable 1", "Variable 2" etc.

Example:
library("stats")
randomize(0)
x=ceil(normal(50,3)-0.5)
{xc,xcvars}=categorize(x,"value",1|0|NaN)

Result:
The first variable (column) is categorized with value "1"
as reference, the second with value "0", and the third is
kept as it is, since there are no NaN's in x.



Author: M. Mueller, 19970502
(C) MD*TECH Method and Data Technologies, 05.02.2006