sencode是官方命令encode的增强版(super encode),“s”代表“super”,sencode用于将字符型变量转码为数值型变量,并将字符型变量的值设为标签值。官方命令encode是根据字符变量值的字母数字(alphanumeric order)进行排序,而sencode则可以根据字符变量值的逻辑顺序(logical order)进行排序,逻辑顺序。
Unlike encode, sencode can order the numeric values corresponding to the string values in a logical order instead of ordering them in alphanumeric order of the string value, as encode does.
This logical order defaults to the order of appearance of the string values in the dataset but may be an alternative order specified in the gsort option.
The mapping of numeric code values to string values may be one-to-one so that each string value has a single numeric code or may be many-to-one so that each string value may have multiple numeric codes corresponding to multiple appearances of the string value in the dataset. sencode may be useful when the input string variable is used as a source of axis labels in a Stata graph and the output numeric variable is used as the X-variable or Y-variable.