Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: encoding unique letter into a unique number for combinedcombinations


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: encoding unique letter into a unique number for combinedcombinations
Date   Wed, 14 Feb 2007 11:04:42 -0500

Thanks for the fix (and the kudos).
And yes, better to leave the oldvar, I got carried away by brevity...

clonevar newvar=myvar
forv i=1/26 {
   replace newvar = subinstr(newvar,char(`i'+64),string(`i',"%02.0f"),.)
}


Nick Cox wrote:
There is a typo here in that the format %02.0f should
be in " ". And I would definitely leave the old variable
in place. Otherwise this solution is neater than mine.
Nick [email protected]
Jeph Herrin

If your example is strictly true (you have all
uppercase letters, you want to map A->1,..., Z->26),
then:

forv i=1/26 {
replace myvar = subinstr(myvar,char(`i'+64),string(`i',%02.0f),.)
}
T.J. Volant
How
can I program so that it will encode each unique
letter into a unique number? Example:
I got hundreds of combinations of strings like:
ABC
ABB
ACA
Then, encode only gives me 1,2,3 in order. But I would
like to label letter A=01, B=02, C=01 etc, and then
have encode give me 010203, etc. How can I program
this?
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index