How to compare two entities by one of their attributes?

Solution 1:

You need to store the NBT field in a scoreboard with execute store and data get, then subtract one from the other and check for 0.