Many survey questionnaires use a Likert or Likert-like scale, e.g.:
- Strongly Agree
- Strongly Disagree
- About Half the Time
Below is another example of non-numeric values in a variable:
When analyzing data, it is often desirable to have numeric values (e.g., 0, 1, 2, 3, 4 or 1, 2, 3, 4, 5) instead of non-numeric ones. Stata recognizes these non-numeric values as “string” values, and their variables are called “string variables.”
In Stata, there are a few ways of converting string variables (with non-numeric values) to numeric variables (with numeric values). The commonest way to achieve this is probably by using the
encode command, i.e.:
. encode oldvar, generate(newvar)
where oldvar is the name of the old variable and newvar is the name of the new variable. If we use the encode command, the new numeric variable will have value labels added to it.
Another way of doing the same thing is by using the
egen command, i.e.:
. egen newvar = group(oldvar)
The new variable will have numeric values without value labels.