Announcement

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

  • Empty/NULL list

    Hi - I'm using some of the macro lists described here: http://www.stata.com/manuals13/pmacrolists.pdf.

    I'm wondering if I can create a NULL (empty) list "list0" such that

    Code:
    loc mylist : list mylist & list0
    works (i.e., does not change the contents of "mylist"), for example. Is this possible?

  • #2
    Yes; it's possible. I guess there is a reason for asking!

    Code:
    local frog
    
    local toad 42
    
    local dragon : list toad & frog

    Comment


    • #3
      I'll start by saying that I think I've interpreted this question differently than Nick did.

      The definition of the "&" operator in this context is to return every element that is common to both macros. So having an empty (null) macro on the right of the "&" will not do what you hope, it will have nothing in common with the macro on the left.

      I'm guessing you are trying to write general code to loop through a list of macros to find any element(s) common to all of them, and you'd prefer not to have to treat the first time through the loop too much differently. In that case, initializing the result to one of macros, rather than to null, will do the trick.
      Code:
      . local m1 duck duck goose
      
      . local m2 frog toad duck
      
      . local m3 duck frog goose
      
      . local and1 : list m1 & m2
      
      . local and1 : list and1 & m3
      
      . display "`and1'"
      duck
      
      . local and2 `m1'
      
      . foreach m in m1 m2 m3 {
        2. local and2 : list `m' & and2
        3. }
      
      . display "`and2'"
      duck
      
      .
      If neither Nick's answer nor mine suffices, could you explain your objective in using the command you enquire about? Perhaps Statalist can solve your problem even if we can't answer your particular question in the affirmative.

      Comment


      • #4
        William makes a very good point: Stata presumably is just ignoring the macro with no contents, as it is wont to do, so returns the intersection as being equal to the non-empty set. Depending on taste, that's a bug if it's not a feature.

        Here as elsewhere, Stata acts like an extreme materialist in ignoring all entities that don't exist concretely.It flunks on the metaphysics of what might exist but does not.
        Last edited by Nick Cox; 16 Nov 2015, 13:59.

        Comment


        • #5
          Thanks for the replies. I'm silly and typed "&" instead of "|"... sorry!

          You're right that mylist & NULL = NULL. But if I do as Nick described (local with no assignment), then mylist | list0 = mylist, which is what I want.

          Comment


          • #6
            Sorry I overlooked the simpler explanation for your question: everyone here surely knows that All's NULL that ANDs NULL. [groan]

            Comment


            • #7
              There's stiff competition here for making the worst jokes.

              Comment

              Working...
              X