That's a rather narrow minded way to thinking about the issue.
I've accepted a counter offer twice, and both times I was glad that I did.
There could be many other reasons for a company not paying what you can get somewhere else. A very trivial one is the yearly update cycle: that may happen in January whereas you get an offer in June. Companies that hire don't align to the schedule of your current one.
And hiring companies inherently know asking somebody to quit and somewhere else carries a risk that needs some amount of kind of reward.
Hell, how can one personally even know what he/she is worth? There are so many factors at play. It'd be narrow minded to expect pricing perfection on something nobody really can get right.
You'll get more pay but you're stuck in the same company run by the same narrow minds.