Announcement

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

  • Dropping obs in a frame and expand to linked frame the selection

    Hi,
    I'm currently working on a frame linked m:1 to another.
    I deleted some obs from the dataset and now i would like to drop the linked observations in the linked dataset.

    As a frame linked to another I have the linking variable were i can find the list of remaining linked observations in the linked dataset but I don't know haw to take this list and drop obs in the linked dataset using this list.

    ideas?

  • #2
    You've left it to my imagination to make up an example that demonstrates my understanding of what you are trying to do, so this may not totally solve your problem because I've made the simplest possible example given your description.
    Code:
    clear all
    cls
    // set up the frame with one observation per id
    frame create frame_1
    frame change frame_1
    input int (id code)
    1 11
    2 22
    3 33
    end
    
    // set up the frame with multiple observations per id
    frame create frame_m
    frame change frame_m
    input int (id gnxl)
    1 101
    1 102
    1 103
    2 .
    3 301
    3 303
    end
    
    // link the two frames
    frlink m:1 id, frame(frame_1) generate(lvm)
    
    // drop the observations for id 2
    drop if id==2
    
    // mark one observation for each distinct id remaining
    egen tokeep = tag(id)
    
    // create a new frame with a list of remaining distinct ids
    frame put id if tokeep, into(whatsleft)
    
    // link frame_1 to the list of remaining ids
    frame change frame_1
    frlink 1:1 id, frame(whatsleft) generate(lv1) 
    list, clean
    
    // now just drop if lv1==.
    Code:
    . // link the two frames
    . frlink m:1 id, frame(frame_1) generate(lvm)
      (all observations in frame frame_m matched)
    
    . 
    . // drop the observations for id 2
    . drop if id==2
    (1 observation deleted)
    
    . 
    . // mark one observation for each distinct id remaining
    . egen tokeep = tag(id)
    
    . 
    . // create a new frame with a list of remaining distinct ids
    . frame put id if tokeep, into(whatsleft)
    
    . 
    . // link frame_1 to the list of remaining ids
    . frame change frame_1
    
    . frlink 1:1 id, frame(whatsleft) generate(lv1) 
      (1 observation in frame frame_1 unmatched)
    
    . list, clean
    
           id   code   lv1  
      1.    1     11     1  
      2.    2     22     .  
      3.    3     33     2  
    
    . 
    . // now just drop if lv1==.
    .

    Comment

    Working...
    X