Announcement

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

  • Compare elements of locals and return distingushing elements

    Dear all,

    I have the following three locals:
    Code:
    local house "1 2 3 4"
    local garden "1 2 3"
    local cat " 4 2 3 1"
    Using the following code:
    Code:
    local same : list house === cat
    display "`same'"
    local distinct : list house === garden
    display "`distinct'"
    Stata tells me (by displaying 1 and 0, respectively), that cat and house contain the same elements whereas house and garden do not. However, I am not only interested in whether two locals contain the same elements but in case they do not, I would also like to know 1.) which elements are different and 2.) in which local those unique elements are contained. Ideally, I would like to have a new local containing those elements that are contained in one local but not in the other (e.g. 4 is contained in house but not in garden, thus, I would like to have another local difference that contains the 4 as only element. Additionally, it would be great if Stata could tell me that the 4 is contained in house but not in garden.)

    Any ideas/solutions how to implement that?

    Thank you very much in advance.

    Best,
    Nina

  • #2
    Code:
    local difference1 : list house - garden
    local difference2 : list garden - house
    display "`difference1'"
    display "`difference2'"
    yields

    Code:
    . local difference1 : list house - garden
    
    . local difference2 : list garden - house
    
    . display "`difference1'"
    4
    
    . display "`difference2'"
    
    
    . 
    end of do-file
    Best
    Daniel

    Comment

    Working...
    X