Neighbours leave when they feel ignored, so the fix is mostly attention.
Talk to them regularly, send letters with a gift attached, and follow through on any requests they make. If one does bring up the idea of moving away, choose the option asking them to stay — that alone will often change their mind.
Consistency matters more than any single gesture, so make the rounds of your town a habit.