Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • New usort command - byable sorting with [if] [in] and locale support

    Thanks to Kit Baum, SSC now offers an alternative command to sort and gsort.

    TITLE
    'USORT': module to perform locale-based ascending and descending sort that
    supports conditional statements, observation ranges, and user-defined
    handling of substrings and missing values

    DESCRIPTION/AUTHOR(S)

    This program is a byable sort command, which allows a) custom
    first and last substrings, including system (.) and all remaining
    missing values, b) gsort-like syntax for the ascending and
    descending order, as well as c) conditional [if] and range [in]
    sorting. The program is built around the Stata sort command and
    adds the data-sorted flag (sorted by) to the dataset if all rows
    are selected and applies Mata _collate() otherwise. Sorting large
    datasets might be taxing on machine memory or disk space.

    KW: sort
    KW: conditional
    KW: descending order

    EXAMPLES
    Code:
        Setup:
            . sysuse auto
    
        Sort observations in ascending order by price:
            . usort price
    
        Sort observations in ascending order by make in Czech, grouped by foreign, with VW models placed at
        the top:
            . bysort foreign: usort make, first(VW, pos) loc(cs_CS)
    
        Sort observations in descending order by mpg and price:
            . usort -mpg -price
    
        Sort observations in descending order by price for domestic cars only:
            . usort -mpg -price if ! foreign

  • #2
    If you find a bug in usort, please post it here

    Comment


    • #3
      Two major bugs were fixed in version 1.1.1: there was a problem with natural sorting, and by/bysort produced a descending order. Furthermore, usort now supports wildcards. You can type
      Code:
      . usort -a*
      which will sort all variables beginning with "a" in descending order.

      Comment


      • #4
        Hello Ilya Bolotov. Version 1.1.1 does not seem to be available yet. I have tried updating two different ways, and still have version 1.1.0. See below.

        Code:
        . which usort
        c:\ado\plus\u\usort.ado
        *! version 1.1.0  07oct2024  I I Bolotov
        
        . adoupdate usort, update
        note: ado update updates community-contributed files; type update to check for updates to official Stata.
        
        Checking status of specified packages:
        
          [284] usort at http://fmwww.bc.edu/repec/bocode/u:
                installed package is up to date
        
        (no packages require updating)
        
        . which usort
        c:\ado\plus\u\usort.ado
        *! version 1.1.0  07oct2024  I I Bolotov
        
        . ssc install usort, replace
        checking usort consistency and verifying not already installed...
        all files already exist and are up to date.
        
        . which usort
        c:\ado\plus\u\usort.ado
        *! version 1.1.0  07oct2024  I I Bolotov
        Cheers,
        Bruce
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          Originally posted by Ilya Bolotov View Post
          If you find a bug in usort, please post it here
          Perhaps not a bug, but usort does not seem to recognise Nordic characters, e.g. “ö”, “æ” or “å”.
          Building on the help-file:
          Code:
          sysuse auto
          rename price æprice
          usort æprice
          gives:
          invalid syntax
          r(100);

          Comment

          Working...
          X