tempfile A
drop _all
use A
sort id year
save `A'
use B
sort id year
merge id year using `A'
keep if _merge == 3
drop _merge
the above will keep the common cases, but if you have other variables, depending on which one to keep, you can use different options. Please see "help merge" for details.