Joseph Coveney suggested -encode- after
-label define- while Michael Blasnik
pointed to the -subinstr()- function.
Another solution is not needed therefore,
but there is in -egenmore- on SSC a
user-written -egen- function, -ston()-
(think _s_tring to _n_umeric) which offers
an alternative. Using that we have, say,
foreach v of var party? {
egen `v'n = ston(`v'), from(c d l n) to(1/4)
}
-ston()- has a twin -ntos()- to do the inverse.
Nick
[email protected]
Clive Nicholas asked
> . list part* in 1/20
>
> +-----------------------------------+
> | party1 party2 party3 party4 |
> |-----------------------------------|
> 1. | l c d n |
> 2. | l c d n |
> 3. | l d c n |
> 4. | l d c n |
> 5. | l c d n |
...
> Although I've successfully converted these into numeric
> variables, I need
> to convert these letters into _real_ numbers, such that c=1,
> d=2, l=3 and
> n=4. I'm finding that if this isn't done, I can't perform any analysis
> with them.
*
* 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/