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

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

From |
"Impavido, Gregorio" <GImpavido@imf.org> |

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

Subject |
RE: st: RE: RE: -encode- with predetermined sorting |

Date |
Tue, 12 Jun 2012 17:35:21 -0400 |

Nick, Thank you also for these other alternatives. Gregorio -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: Tuesday, June 12, 2012 5:19 PM To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: RE: -encode- with predetermined sorting My point 2 was about your original example. From the details here the flavour of your problem is a bit clearer, and now I advise checking out -labmask- (SJ) and also SJ-8-2 gr0034 . . . . . . . . . . Speaking Stata: Between tables and graphs (help labmask, seqvar if installed) . . . . . . . . . . . . N. J. Cox Q2/08 SJ 8(2):269--289 outlines techniques for producing table-like graphs and also -sencode- (SJ, SSC), -encode- is an official command. It's not usually difficult to write your own alternative if it doesn't do what you want. Nick On Tue, Jun 12, 2012 at 3:52 PM, Impavido, Gregorio <GImpavido@imf.org> wrote: > Thank you Nick. Your suggestions prompted me to do a little more homework: hence, my belated response. > > My original question is about both the points you raise (I think). > > Regarding your point 2., my loop below produces such labels in advance following the sorting of a. But in 2. below you suggest that this could be done with a one line command. Are you thinking of some use of -levelsof-? Because if I have (say) many values in b, a one line of the type -label define lblname 1 "a" 4 "b" ... - is rather tedious (although it forces the idiosyncratic sorting I want). But most importantly it is not readily changeable if I want to change the sort order (BTW: The whole use of this is to produce -graph twoyay bar- charts where the xlabels are sorted in any arbitrary fashion; contrary to -graph bar-, there is no -sort()- option in -graph twoway bar- (that I could find...)) > > Regarding your point 1., I managed to force -enocode- to use the arbitrary sorting produced in advance (by the loop below) by coding -encode a, gen(c2) label(lblname)-. This produces the same variable c produced by -label values c lblname- below. Then, I am more confused: is there a concrete advantage then in using -encode- afterall if I have to specify the label name in advance? Wouldn't be more useful if encode had a -sort(varlist)- option? Nick Cox > 1. The value labels for an idiosyncratic -encode- need to exist in advance. Idiosyncratic just means here an encoding that -encode- would not produce by default. > > 2. In your case you could define them with a single command line, which would be quicker to type and to execute than your code. > > I am guessing that your question is more about the first than the second. Impavido, Gregorio > I have the following dataset: > > . list > > +--------+ > | a b | > |--------| > 1. | 10 a | > 2. | 40 b | > 3. | 30 c | > 4. | 20 d | > +--------+ > > If I encode b and generate c, I get: > > . list *, nolabel > > +-------------+ > | a b c | > |-------------| > 1. | 10 a 1 | > 2. | 40 b 2 | > 3. | 30 c 3 | > 4. | 20 d 4 | > +-------------+ > > Now, I want to have a different sort order for c, say as a function of a: > > . list *, nolabel > > +-------------+ > | a b c | > |-------------| > 1. | 10 a 1 | > 2. | 40 b 4 | > 3. | 30 c 3 | > 4. | 20 d 2 | > +-------------+ > > Is there a more rapid way than the following to obtain what I want? > > a > gen c = _n > forvalues i=1/4 { > label define lblname `i' "`: di b[`i']'", add > } > label values c lblname * * 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: -encode- with predetermined sorting***From:*"Impavido, Gregorio" <GImpavido@imf.org>

**st: RE: -encode- with predetermined sorting***From:*Nick Cox <n.j.cox@durham.ac.uk>

**st: RE: RE: -encode- with predetermined sorting***From:*"Impavido, Gregorio" <GImpavido@imf.org>

**Re: st: RE: RE: -encode- with predetermined sorting***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: RE: RE: Combining multiple observations by an ID variable** - Next by Date:
**st: RE: RE: RE: Combining multiple observations by an ID variable** - Previous by thread:
**Re: st: RE: RE: -encode- with predetermined sorting** - Next by thread:
**st: RE: RE: -encode- with predetermined sorting** - Index(es):