Statalist The Stata Listserver


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

st: RE: RE: RE: New values for a value labelled variable,


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

Evidently I misunderstood your explanation of your 
value labels. As always, it helps to follow Stata's 
own conventions and not invent your own. e.g. 

12 "joe" 
23 "mike" 

But the FAQ mentions maps your numeric identifiers 
to identifiers 1 up according to when first seen 
in the dataset. The rest of the problem is assigning 
the value labels of one variable to the values of another. 
This task is done directly by -labmask- from -labutil-
on SSC. 

Alternatively, as Michael Blasnik pointed out, once
you have a string variable version of the labels, Roger
Newson's -sencode- allows another solution. 

Nick 
[email protected] 

Serguei Kaniovski
 
> The variable MYID contains the values 12, 23, 12, 45, 24, which are 
> labeled as "joe", "mike", "joe", "helen", "tom".
> 
> decode myid, gen(MYID)
> split MYID, p(-) destring
> 
> would work if the values themselves were: "12-joe", 
> "23-mike", "12-joe", 
> "45-helen", "24-tom".
> 
> Since names are labels, not values
> decode myid, gen(MYID)
> split MYID, p(-) destring
> 
> generates only one variable containing the labels as values.

 Serguei Kaniovski schrieb:
 
> > 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index