Announcement

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

  • inlist alternatives?

    inlist seems to have a very small limit for the number of arguments /size of list it can take.
    i'd like to use it in a keep statement, hence looking for alternatives that can take larger lists...i want to keep about 50 vars from among 450...so, while if..or is an option, it's not very palatable.
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    Well, I agree with you that the limit of ten string arguments in -inlist()- is rather confining, and I do hope that in future versions of Stata that will be relaxed. That said, however, I fail to see the relevance of -inlist()- to "i want to keep about 50 vars from among 450." To -keep- those 50 variables you just develop a local macro containing the names of the 50 variables and then refer to that in your -keep- statement. There is no way I can think of to use -inlist()- here. What am I missing?

    Comment


    • #3
      Ah, fair point. Never used a local like that, but makes sense.
      Thank you for your help!

      Stata SE/17.0, Windows 10 Enterprise

      Comment


      • #4
        I tried
        Code:
        local countries2remove `""ASM","CHI","CUW","DJI","ERI","FRO","GIB","GUM","IMN","LBR","LIE","MAF","MCO","MNE","MNP","NCL","NRU","PLW","PRI","PRK","PSE","PYF","QAT","SMR","SOM","SRB","SSD","STP","SXM","SYR","TCA","TLS","VGB","VIR","XKX""'
        drop if inlist(countrycode,`countries2remove')
        But getting
        Code:
        expression too long
        Thank you for your help!

        Stata SE/17.0, Windows 10 Enterprise

        Comment


        • #5
          With strings, -inlist()- only allows a maximum of 10 arguments. Since you have, I believe, 35 countries there, you will have to break this up into 4 groups, each containing 9 of the countries (8 in the last one) and do separate inlist() functions for those.

          Comment


          • #6
            See also the FAQ

            FAQ . . . . . . . . . . . Defining group characteristics to create subsets
            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C. F. Baum
            7/11 How do you efficiently define group characteristics
            in your data in order to create subsets?

            https://www.stata.com/support/faqs/d...s-for-subsets/

            Comment


            • #7
              Originally posted by Clyde Schechter View Post
              With strings, -inlist()- only allows a maximum of 10 arguments.
              Yes, that was the whole reason to use the local macro instead of the actual list of variables...

              Originally posted by Clyde Schechter View Post
              To -keep- those 50 variables you just develop a local macro containing the names of the 50 variables and then refer to that in your -keep- statement.
              Turns out, I misunderstood this.
              Thank you for your help!

              Stata SE/17.0, Windows 10 Enterprise

              Comment

              Working...
              X