Thank you, Maarten. This is what I needed.
Friedrich
On 10/24/07, Maarten buis <[email protected]> wrote:
> --- Friedrich Huebler <[email protected]> wrote:
> > Assume I have a dataset with the variables year1, year2, ..., year19,
> > year20.
> >
> > forval i = 1/20 {
> > gen year`i' = 1
> > }
> >
> > The command -aorder- sorts the variables in ascending order of the
> > number that follows "year". The technical note in [D] order explains
> > that this is by design, "even though to most computer programs,
> > year10 is alphabetically between year1 and year2."
> >
> > There are cases where I would like the variables to be sorted in
> > strict alphabetical order, like this:
> >
> > year1
> > year10
> > ...
> > year19
> > year2
> > year20
> > year3
> > ...
> > year9
> >
> > Any suggestions on how this can be done without specifying the sort
> > order with -order-? It would be nice to have an option like -aorder,
> > strict- that does not try to be as smart as the current version of
> > -aorder-.
>
> You can combine two tricks to do what you want, first the command
> -unab- will put a unabreviated variable list in a local, e.g.
> -unab s : year*- will make a local `s' containing year1 year2 ...
> year20. Than you can use an extended macro function to sort this list
> strictly alphebatically, e.g. -local s : list sort s- will replace the
> local `s' with year1 year10 year2 ... year9. Than you can issue a
> command -sort `s'- See the example below and -help unab- and
> -help macrolists-:
>
> *---------------- begin example ----------------
> sysuse nslw88, clear
> tab grade, gen(ed)
> unab s: ed*
> di "`s'"
> local s : list sort s
> di "`s'"
> order `s'
> *----------------- end example -----------------
> (For more on how to use examples I sent to the Statalist, see
> http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
>
> Hope this helps,
> Maarten
>
> -----------------------------------------
> Maarten L. Buis
> Department of Social Research Methodology
> Vrije Universiteit Amsterdam
> Boelelaan 1081
> 1081 HV Amsterdam
> The Netherlands
>
> visiting address:
> Buitenveldertselaan 3 (Metropolitan), room Z434
>
> +31 20 5986715
>
> http://home.fsw.vu.nl/m.buis/
> -----------------------------------------
>
*
* 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/