Announcement

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

  • Problems with inlist function

    I've been trying to use these three codes to create a depression score. One of the members helped me with these codes. My Stata shows "command inlist is unrecognizable". I don't know how to fix this problem. Is there a particular order for entering these codes? Please help.

    inlist(D1, 2, 3) & inlist(D2, 2, 3)
    egen third = anycount(D3-D8), values(2 3)
    gen major = inlist(D1, 2, 3) & inlist(D2, 2, 3) & third >= 5

  • #2
    the first statement is covered by the third; further, the first statement was obviously educational and is not meant to be used; do not use the first statement above as it is both illegal and unnecessary

    Comment


    • #3
      Hopefully this will state things more clearly. -inlist- is not a standalone command. It's a function. You were supposed to enter it as part of a command, like -gen- (which is short for generate).

      You'll see the third line you typed, i.e.

      Code:
      gen major = inlist(D1, 2, 3) & inlist(D2, 2, 3) & third >= 5
      contains the first line that you tried to type. The first argument for -inlist- (e.g. D1) checks that variable (e.g. the variable D1). If D1's value was any of the values that followed (e.g. here, you specified 2 and 3), -inlist- will return a true. So, the code above evaluates a total of 3 variables, and if all 3 are true, it will return a 1 overall.

      If you ran all 3 lines of code as a block, you would exit with an error because the first line is faulty (hence, the next 2 lines are never evaluated). You were supposed to run just the second and third lines of code, i.e.

      Code:
      egen third = anycount(D3-D8), values(2 3) 
      gen major = inlist(D1, 2, 3) & inlist(D2, 2, 3) & third >= 5
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment


      • #4
        This question arises from, and was already answered in, https://www.statalist.org/forums/for...pression-score

        Whether a question deserves a new thread is a fine judgment. When a question is closely related to an existing thread, it's a good idea to provide a cross-reference, as just above. Any way, Weiwen Ng nicely expanded on the original idea.

        Comment


        • #5
          Nick Cox , I was not sure whether to continue the existing thread or create a new one because I was asked to create a new thread for asking a new question in my previous post. And I was not sure if you would have wanted me to tag you in my new thread. I really appreciate your kind responses.
          Last edited by jill urbaeva; 09 Oct 2018, 15:22.

          Comment


          • #6
            Weiwen Ng, thank you so much for your detailed response.

            Comment

            Working...
            X