Announcement

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

  • Dropping observations without corresponding partnerID

    !Sorry in advance, I haven't been able to extract the exact example with dataex!
    Stata 18 on Windows


    My sample looks roughly like that:
    Year HouseholdID PersonalID PartnerID
    2005 10 107 108
    2006 10 107 108
    2007 10 107 108
    2008 10 107 108
    2009 10 107 108
    2005 11 113 -
    People living in the same household as their partner get assigned their partner's PersonalID as PartnerID. As shown in the example above, some people (107) have an assigned partner (108) but their partner isn't part of this sample (PersonalID 108 is missing). I now want to drop all the people whose partners are not part of my dataset (in this case: dropping 107).

    I have tried things like:
    gen partner_missing = missing(PartnerID)
    drop if partner_missing
    drop partner_missing


    but this only drops observations like 113 which are not supposed to be dropped.

    What else can I try to yield my desired result?
    Thanks in advance!


  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year byte householdid int(personalid partnerid)
    2005 10 107 108
    2006 10 107 108
    2007 10 107 108
    2008 10 107 108
    2009 10 107 108
    2005 11 113   .
    end
    
    frame put personalid, into(found)
    frame found: contract *
    frlink m:1 partnerid, frame(found personalid)
    drop if missing(found) & !missing(partnerid)
    frame drop found
    drop found
    Res.:

    Code:
    . l
    
         +---------------------------------------+
         | year   househ~d   person~d   partne~d |
         |---------------------------------------|
      1. | 2005         11        113          . |
         +---------------------------------------+
    Last edited by Andrew Musau; 11 Mar 2024, 07:05.

    Comment


    • #3
      worked out perfectly, thanks so much!

      Comment

      Working...
      X