Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

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

Date |
Thu, 25 Mar 2010 19:32:38 +0100 |

<> " The need to make this kind of detail clear is constant!" My code earlier included the lines ******* cap which sencode if _rc ssc inst sencode ******* which hopefully limited confusion as to the origin of the command... " Martin's example achieves that by construction; I saw nothing that made that certain to be true of Karen's data in the original post." Very true, I got carried away by the "facility" of my approach via -input-, so apologies to Ronan Conroy! HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: Donnerstag, 25. März 2010 19:17 To: statalist@hsphsun2.harvard.edu Subject: RE: st: 'Re-ordering' the labels of a variable Let's all be clear on various details here. 1. -sencode- is user-written and downloadable from various sources, SJ, SSC and the author's (Roger Newson's) own website. The need to make this kind of detail clear is constant! 2. The original purpose of -sencode- was _s_equential encoding in contrast to -encode-'s default alphabetic encoding. Unless you can be certain that first occurrences in the data match the desired ordering, then specifying -label()- _is_ essential for the desired outcome. Martin's example achieves that by construction; I saw nothing that made that certain to be true of Karen's data in the original post. 3. Although -sencode- is undeniably useful, and its existence underlines a view elsewhere expressed that -encode- should be revisited by StataCorp to make it more comprehensive, I see nothing here that could not also be achieved directly with -encode-. Nick n.j.cox@durham.ac.uk Martin Weiss 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) ******* Ronan Conroy On 25 Márta 2010, at 10:30, Karen Wright wrote: > 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 * * 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/

**References**:**st: 'Re-ordering' the labels of a variable***From:*"Karen Wright" <Karen.Wright@icr.ac.uk>

**Re: st: 'Re-ordering' the labels of a variable***From:*Ronan Conroy <rconroy@rcsi.ie>

**RE: st: 'Re-ordering' the labels of a variable***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**RE: st: 'Re-ordering' the labels of a variable***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: 'Re-ordering' the labels of a variable** - Next by Date:
**st: Box plots** - Previous by thread:
**RE: st: 'Re-ordering' the labels of a variable** - Next by thread:
**Re: st: 'Re-ordering' the labels of a variable** - Index(es):