Statalist The Stata Listserver

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

st: RE: New values for a value labelled variable

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: New values for a value labelled variable
Date   Thu, 14 Sep 2006 13:38:53 +0100

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 

Getting first occurrence in the dataset 
was discussed on the list only a few weeks ago 
and has been written up as an FAQ.

(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

encode work, gen(newid) 

[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:

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