Call your variable -myid-. First create the
string equivalent:
decode myid, gen(MYID)
Then split into numeric and name parts:
split MYID, p(-) destring
You should have MYID1 with the numbers
and MYID2 with the names. If not, my
code is wrong or you are not explaining
everything.
Getting first occurrence in the dataset
was discussed on the list only a few weeks ago
and has been written up as an FAQ.
http://www.stata.com/support/faqs/data/distinctvalues.html
(So, evidently, you did not follow advice
and look at the FAQs on this problem.)
Use that to get a -myid1-.
Now recombine
egen work = concat(myid1 MYID2), p(-)
and get back in the realm of value-labelled
numbers:
encode work, gen(newid)
Nick
[email protected]
Serguei Kaniovski
> I have a variable with (many) value labels, say
>
> 12-joe
> 23-mike
> 12-joe
> 45-helen
> 24-tom
> ...
>
> I would like to create a new variable with consecutive values
> assigned
> to the old labels, e.g.
>
> 1-joe
> 2-mike
> 1-joe
> 3-helen
> 4-tom
> ...
>
> It is important that the sequence of names is preserved.
*
* 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/