Announcement

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

  • saving results from -list- as a local "list"

    I'm running into a problem that I'm having trouble solving, because it uses the term "list" twice and so search engines aren't giving me good results.

    I am running -list- to give me id's for particular observations. It's something like this:
    Code:
    list public_id if _merge==2
    This will give me a list of id's ranging from, say, 101-199.

    I then want to save them as a local list. So in the case I'm doing right now, I'm manually taking the id's 105, 124, 174, and 188 and doing something like:
    Code:
    local idlist "105 124 174 188"
    Is there any way to take the list directly from -list- earlier? Is there a better alternative? If someone has already answered this, I'd like to know--like I said, the search engine was giving me some lousy results, so it's very possible someone has answered this already.

  • #2
    I think I got it. This creates it and tests to make sure I did it right. I'll leave this all up in case someone has a better solution and someone needs to do this in the future.

    Code:
    levelsof _public_id if _merge==2, local(idlist)
    foreach l of local idlist {
    di `l'
    }

    Comment


    • #3
      That's good technique and I do like the command levelsof. There can be other solutions, as I imagine your real problem is more than just displaying the levels. which levelsof does any way.

      Method 1 in https://www.stata.com/support/faqs/d...-with-foreach/ could be helpful too.

      Comment


      • #4
        Thank you for posting your solution.

        The levelsof command is designed for exactly the sort of use you have made of it, so I doubt that anyone will have a better solution.

        Comment

        Working...
        X