# How to convert abstract value into number in Stata?

I have a variable called aa, it has 5 values: very satisfied, satisfied,dissatisfied,very dissatisfied,neither satisfied nor dissatisfied.

I need to convert the value of "very satisfied" into "5", "satisfied" into "4", and so on.
I tried this command:

xtile bb=aa,nq(5)


but the outcome is weird, because it only those 5 value into 1, 4, 5. I cannot find the number of 2 and 3 in the result. This means "very dissastified" and "dissatisfied"are converted into the same number "5", "very satisfied" and "satisfied" are converted to the same number, "1". I don't know why, who can help me out?

-
Stating the software you are using would likely help. This is such a simple question it is hard not to suggest to just read the manual, this meta thread gives lists of useful links to various software packages. – Andy W Jul 26 '11 at 20:35
Use encode, not xtile, as in encode aa, gen(bb). – whuber Jul 26 '11 at 20:55
@Andy The manual for data management alone is 586 pages. The trick lies in figuring out the name of what you want to do. Stata comes with a decent GUI, but following the chain Data|Create or change data|... doesn't bring up anything obvious. It turns out you need to choose Encode value labels from string variable, which even I (as a native English speaker with some Stata familiarity) find less than clear. – whuber Jul 26 '11 at 21:02
@whuber, I agree that finding what you need itself takes some practice with the language (of either that particular package or statistics/programming lingo in general). That being said, learning such data management tasks will be essential for any type of project, and hence the OP needs to learn in general how to accomplish such tasks on their own. Knowing the right words to search is key, in this case, if one did a google search for "string Stata" several webpages detailing how to do accomplish what the OP desires would be on the first page. – Andy W Jul 26 '11 at 21:25

This is a strange way to approach it, frankly. Your aa variable must already be a numeric variable, as trying to run xtile with a string variable produces an expected error:

    . sysuse auto, clear
. xtile qmake = make , nq(5)
type mismatch
r(109);


So if you were able to run xtile bb=aa,nq(5), you must have a numeric variable aa, and now you want 5 quintiles of it. If you have only 10% of very dissatisfied and 10% of dissatisfied customers in the sample (coded in bb as 1 and 2, respectively), then of course they'll be clumped together as the result of computing quintiles: they are both in the bottom quintile.

Typing describe aa will tell you what the storage type is, and typing

    tabulate aa
tabulate aa, nolabel


will show you frequencies with and without the labels. (I suspect you ran the first one, freaked out that this is a string variable, and then decided to convert it, even though it was not necessary since it was a numeric variable, to begin with.)

To convert strings to numbers, you can use destring. To convert numbers, you can use recode.

-