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" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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 
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 
n.j.cox@durham.ac.uk 

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/



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