Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: 'Re-ordering' the labels of a variable


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   RE: st: 'Re-ordering' the labels of a variable
Date   Thu, 25 Mar 2010 12:33:39 +0100

<>

No need to define the -label- beforehand:


*******
clear*

cap which sencode
if _rc ssc inst sencode

input str1 stringvar byte freq  
B 3 
A 5
H 5
S 6
Q 4
I 3
end

expand freq
sencode stringvar, gen(numvar)
list, noo

la li numvar
ta numvar

hist numvar, xlab(, valuelabel)
*******


HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ronan Conroy
Sent: Donnerstag, 25. März 2010 12:06
To: [email protected]
Subject: Re: st: 'Re-ordering' the labels of a variable

On 25 Márta 2010, at 10:30, Karen Wright wrote:

> Dear All,
>
> I have a diagnosis (string) variable which can take the value: B, A,  
> H, S, Q or I.  Stata (10.0) cleverly changes this order to an  
> alphabetical order, however this does not make sense when trying to  
> display a simple histogram of the distribution.  I would like to  
> force stata to display them in my original order as it is sensible  
> when considering the ordering of the diagnosis catergories.

Use sencode, one of those utilities you simply must have. Define the  
label first, then use it to map the encoding.

. lab def dx 1 "B" 2 "A" 3 "H" 4 "S" 5 "Q" 6 "I",modify
. sencode dx, label(dx) replace


Ronan Conroy
=================================

[email protected]
Royal College of Surgeons in Ireland
Epidemiology Department,
Beaux Lane House, Dublin 2, Ireland
+353 (0)1 402 2431
+353 (0)87 799 97 95
+353 (0)1 402 2764 (Fax - remember them?)
http://rcsi.academia.edu/RonanConroy

P    Before printing, think about the environment





*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index