Announcement

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

  • After frlink, can we check which observation in frame2 didn't matach in frame1?

    After frlink, can we check which observation in frame2 didn't match in frame1?
    If we use two datasets and use command merge, we can check this via _merge==2, how about frlink?
    Thanks!

  • #2
    There does not seem to be a direct way. The example below demonstrates an inelegant indirect approach, I'm sure it could be improved upon.
    Code:
    webuse persons
    frame create txcounty
    frame txcounty {
        webuse txcounty
    } 
    
    frlink m:1 countyid, frame(txcounty) generate(linkvar)
    
    frame put linkvar, into(links)
    frame links {
        egen keep = tag(linkvar)
        keep if keep
        drop keep
    }
    
    frame txcounty {
        generate linkvar = _n
        frlink 1:1 linkvar, frame(links) generate(match)
        list if missing(match)
    }
    Code:
    . webuse persons
    
    . frame create txcounty
    
    . frame txcounty {
    .     webuse txcounty
    (Median income in Texas counties)
    . } 
    
    . 
    . frlink m:1 countyid, frame(txcounty) generate(linkvar)
      (all observations in frame default matched)
    
    . 
    . frame put linkvar, into(links)
    
    . frame links {
    .     egen keep = tag(linkvar)
    .     keep if keep
    (16 observations deleted)
    .     drop keep
    . }
    
    . 
    . frame txcounty {
    .     generate linkvar = _n
    .     frlink 1:1 linkvar, frame(links) generate(match)
      (4 observations in frame txcounty unmatched)
    .     list if missing(match)
    
         +----------------------------------------+
         |  countyid   median~e   linkvar   match |
         |----------------------------------------|
      4. |    Harris      58664         4       . |
      6. |   El Paso      44120         6       . |
      7. |     Bowie      49153         7       . |
      8. | Galveston      69674         8       . |
         +----------------------------------------+
    . }
    
    .

    Comment


    • #3
      Originally posted by William Lisowski View Post
      There does not seem to be a direct way. The example below demonstrates an inelegant indirect approach, I'm sure it could be improved upon.
      Code:
      webuse persons
      frame create txcounty
      frame txcounty {
      webuse txcounty
      }
      
      frlink m:1 countyid, frame(txcounty) generate(linkvar)
      
      frame put linkvar, into(links)
      frame links {
      egen keep = tag(linkvar)
      keep if keep
      drop keep
      }
      
      frame txcounty {
      generate linkvar = _n
      frlink 1:1 linkvar, frame(links) generate(match)
      list if missing(match)
      }
      Code:
      . webuse persons
      
      . frame create txcounty
      
      . frame txcounty {
      . webuse txcounty
      (Median income in Texas counties)
      . }
      
      .
      . frlink m:1 countyid, frame(txcounty) generate(linkvar)
      (all observations in frame default matched)
      
      .
      . frame put linkvar, into(links)
      
      . frame links {
      . egen keep = tag(linkvar)
      . keep if keep
      (16 observations deleted)
      . drop keep
      . }
      
      .
      . frame txcounty {
      . generate linkvar = _n
      . frlink 1:1 linkvar, frame(links) generate(match)
      (4 observations in frame txcounty unmatched)
      . list if missing(match)
      
      +----------------------------------------+
      | countyid median~e linkvar match |
      |----------------------------------------|
      4. | Harris 58664 4 . |
      6. | El Paso 44120 6 . |
      7. | Bowie 49153 7 . |
      8. | Galveston 69674 8 . |
      +----------------------------------------+
      . }
      
      .
      Thanks William for your kind and quick reply!

      Comment

      Working...
      X