Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Query re -sortpreserve-


From   Roger Newson <[email protected]>
To   [email protected]
Subject   st: RE: Query re -sortpreserve-
Date   Fri, 20 Jun 2003 18:12:22 +0100

Fellow Statalisters (especially those in charge of the [P] manual)

Thanks to Patrick Joly for pointing out this important typo in -[P] sortpreserve-. I have inserted the underscores in the program I am working on, and it works fine now.

Another useful point not mentioned in -[P] sortpreserve- is that -sortpreserve- preserves not only the original sorting order of the observations but also the value returned by the -sortedby- extended macro function. This is a good reason for using -sortpreserve-, instead of attempting to sort the data back into the original order manually by creating your own -tempvar-, setting it to _n and sorting by your -tempvar- at the end. Thanks again to Patrick for informing me privately on this point.

Best wishes

Roger

At 12:02 20/06/03 -0400, Patrick Joly wrote:

Roger Newson
> I am trying to use -sortpreserve- in Stata 7 and Stata 8
> under Windows
> 98/SE. However, there is one problem. My -sortpreserve-
> programs do not
> seem to be generating a -`sortindex'- temporary variable, as -[P]
> sortpreserve- says they should. (A simple example under Stata
> 8 is given
> below.) Why should this be the case?
>
> Best wishes (and thanks in advance)
>
> Roger
>
> . prog def nutz1,sortpreserve
>    1. version 8.0
>    2. disp as text "Sort index var: |`sortindex'|"
>    3. sort `sortindex'
>    4. end
>
> . nutz1
> Sort index var: ||
> varlist required
> r(100);


There is a typo in the manual under [P] sortpreserve (p. 402 under section
'How sortpreserve works').  A leading underscore is missing from the macro
name used for the sortpreserve variable.  References to `sortindex' should
be replaced by `_sortindex' everywhere.  The following will work:

prog def nutz1,sortpreserve
        version 8.0
        disp as text "Sort index var: |`_sortindex'|"
        sort `_sortindex'
end


. nutz1
Sort index var: |__000000|


Patrick Joly
[email protected]
[email protected]
*
*   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/

--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
  or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

*
*   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