Creating factor variables in resultssets and other datasets
Factor variables are defined as categorical variables with integer values, which may represent values of some other kind, specified by a value label. We frequently want to generate such variables in Stata datasets, especially resultssets, which are output Stata datasets produced by Stata programs such as the official Stata statsby command and the SSC packages parmest and xcontract. This is because categorical string variables can only be plotted after conversion to numeric variables and because these numeric variables are also frequently used in defining a key of variables, which identify observations in the resultsset uniquely in a sensible sort order. The sencode package is downloadable, and frequently downloaded, from SSC and is a “super†version of encode, which inputs a string variable and outputs a numeric factor variable. Its added features include a replace option allowing the output numeric variable to replace the input string variable, a gsort() option allowing the numeric values to be ordered in ways other than the alphabetical order of the input string values, and a manyto1 option allowing multiple output numeric values to map to the same input string value. The sencode package is well established and has existed since 2001. However, some tips will be given on ways of using it that are not immediately obvious but which the author has found very useful over the years when mass-producing resultssets. These applications use sencode with other commands, such as the official Stata command split and the SSC packages factmerg, factext, and fvregen.
Year of publication: |
2013-09-16
|
---|---|
Authors: | Newson, Roger Benedict |
Institutions: | Stata User Group |
Saved in:
freely available
Saved in favorites
Similar items by person
-
Scenario comparisons: How much good can we do?
Newson, Roger Benedict, (2012)
-
Easy-to-use packages for estimating rank and spline parameters
Newson, Roger Benedict, (2014)
-
Homoskedastic adjustment inflation factors in model selection
Newson, Roger Benedict, (2009)
- More ...