Announcement

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

  • "command sortl is unrecognized"

    I'm trying to sort factor loadings. Tried to install the package, but when I search for "sortl" the package is not listed. Is there somewhere else I can access the package?
    Last edited by Teresa Mungazi; 05 Dec 2023, 13:59.

  • #2
    Please show what you have typed, exactly, and what Stata did in response, exactly.

    Comment


    • #3
      I typed "sortl" in the search bar and below is what I got.




      search for sortl (manual: [R] search)
      ---------------------------------------------------------------------------------------------------------------------------

      Search of official help files, FAQs, Examples, and Stata Journals

      Search of web resources from Stata and other users

      (contacting http://www.stata.com)

      listutil from http://fmwww.bc.edu/RePEc/bocode/l
      'LISTUTIL': modules to manipulate lists of words / These functions
      manipulate lists of words. For details, see the / help file. / Author:
      Nicholas J. Cox, University of Durham / Support: email
      [email protected] / Distribution-Date: 20010523

      (click here to return to the previous screen)

      (end of search)

      Comment


      • #4
        Sorting a matrix of factor loadings can be done on a do-it-yourself basis. Note first that your -factor- command leaves behind the loading matrix as a matrix named e(L) that can be seen by giving the -ereturn list- command. You can use Stata's -mata- language to sort this matrix and put it into a Stata matrix. For example, let's say you want to sort your loading matrix in increasing order of the elements in the first column. You could do this immediately after your -factor- command:

        Code:
        // Copy your e(L) matrix into a matrix called L in Mata
        mata: L = st_matrix("e(L)")
        // Sort the L matrix by its first column.
        mata: L = sort(L,1)
        // Copy that matrix to a Stata matrix named Lsort, and display it.
        mata: st_matrix("Lsort", L)
        mat list Lsort
        It's possible to do this is one line of Mata code, but I think it's easier to understand in multiple lines.

        Comment


        • #5
          Mike's code sorts the unrotated factor loadings. You typically want the rotated ones. Mike's code generally applies to the rotated matrix, too, but the adaptation might be challenging for the inexperienced Stata user.

          I suggest you type

          Code:
          ssc install sortl
          Or, optionally, type

          Code:
          ssc install rotate2
          I wrote the latter unaware of Dirk Enzmann's sortl.

          Comment


          • #6
            #3 reports on a false positive. sortl is found as part of a command name sortlist within listutil on SSC, which was a bundle of utilities. I say "was" but "is" remains true, except that it should all be ignored unless you find code using it.

            The best that can be said about this package is that it sowed the seeds of its own destruction, as I suspect that it encapsulated a felt need on Statalist for various utilities, which was moderately soon satisfied by macro functions introduced into Stata and also functionality introduced in Mata. I recall a long conversation with Bill Gould about the need, which was met quite differently.

            Comment


            • #7
              daniel klein is right about the rotated loading matrix being more useful for most purposes. I don't think, though, that working with the rotated matrix is particularly more complicated. After the -rotate- command, the rotated matrix is in the ereturn list as e(r_L), so one could change only the first line of my code to reflect that, and run that modified code after the -rotate- command:

              Code:
              rotate
              mata: L = st_matrix("e(r_L)")
              // etc.

              Comment


              • #8
                What I was trying to imply in #5 -- and should probably have spelled out in the first place -- was that you probably want a couple of more features. For example, you typically want to sort on absolute loadings while still showing the original ones in the output. To make sense of those sorted loadings, you would also want the row names, i.e., variable names (or labels) of the matrix sorted. Those are the minimum changes that I would suggest. None of this stuff is complex but it is challenging for the inexperienced and it certainly would no longer fit so nicely within a couple of lines. Even without additional bells and whistles, like blanking low (absolute) loadings, you would probably wrap that up as a program. Since (at least) two programs exist, I stand by my suggestion to download what is already there.

                There is nothing wrong with, and in fact, it is highly instructive, to show the core concepts behind such programs as Mike did.
                Last edited by daniel klein; 06 Dec 2023, 13:38.

                Comment


                • #9
                  A slightly tangential note: There were/are some user-written programs around to sort Stata matrices, but when I went to dig one up out of whatever I had installed, I realized that here's a situation in which using Mata is probably easier than using one of them. Daniel again is right here, though, that getting a nicely sorted and documented matrix takes more knowledge than a new user would have. In my own case, the relatively few times I've wanted to sort a Stata matrix (loadings or other) my purposes were pretty "quick and dirty," so I actually haven't bothered with labeling or other niceties.

                  Comment


                  • #10
                    A late response to this discussion (also to @nick cox):

                    At November 20 2009 I made the first version of the .ado program -sortl- available on SSC (see https://www.stata.com/statalist/arch.../msg01122.html). Before I decided to name it "sortl" I searched for programs with this name so that it would not conflict with an already existing program with the same name. I am quite sure (but not 100%) that it could be found as listed on SSC by using "find sortl" in November 2009 -- at any rate, now this is not (longer) possible.

                    My problem: What should I do so that it can be found when using find or search? If I would change its name it could no longer be updated by those who did already install it.

                    Comment


                    • #11
                      Dirk Enzmann

                      You may be confusing find and findit.

                      A direct check on whether an ado exists on SSC is to try to type it using (jn this case)


                      Code:
                      ssc type sorll.ado
                      which works fine for me as of just now as does

                      Code:
                      ssc desc sortl


                      Comment


                      • #12
                        Indeed, I did confuse find and findit, thank you. But that means that findit will not find sortl -- you need to know that it is on SSC.

                        It seems that we have to live with it.

                        Comment


                        • #13
                          Why findit can't find sortl I don't know. On the face of it a package name should be easier to find that part of an ado filename.

                          Comment


                          • #14
                            Thank you alll for yhe useful responses. it worked!

                            Comment


                            • #15
                              In sum, sortl is a single program package on SSC and so you need to install it from SSC.


                              Code:
                              . ssc desc sortl
                              
                              ----------------------------------------------------------------------------------------------------------
                              package sortl from http://fmwww.bc.edu/repec/bocode/s
                              ----------------------------------------------------------------------------------------------------------
                              
                              TITLE
                                    'SORTL': module to sort factor loadings or rotated matrix from PCA or factor
                              
                              DESCRIPTION/AUTHOR(S)
                                    
                                     To make an interpretation of a factor solution easier, sortl
                                    sorts the rotated loadings (pattern matrix) or rotated components
                                    stored by rotate into the matrix e(r_L). It also sorts the matrix
                                    e(Psi) of the unique or unexplained variances created by factor
                                    or by pca into the same order.
                                    
                                    KW: factor loadings
                                    KW: factor
                                    KW: pca
                                    KW: rotate
                                    
                                    Requires: Stata version 9
                                    
                                    Distribution-Date: 20091120
                                    
                                    Author: Dirk Enzmann, University of Hamburg
                                    Support: email [email protected]
                                    
                              
                              INSTALLATION FILES                                (type net install sortl)
                                    sortl.ado
                                    sortl.hlp
                              ----------------------------------------------------------------------------------------------------------
                              (type ssc install sortl to install)
                              
                              .

                              Comment

                              Working...
                              X