By competing for their talent. I'm not a huge proponent of capitalism, but that's the world we live in and the world we'll die in. These countries simply aren't competitive in a way to encourage their people to stay. There are innumerous ways to combat this. But our current thinking is so clouded by short sighted profit that today's outcomes shouldn't surprise anyone.
They don't leave irreversibly, they can go back if the political and institutional milieu in their home country improves, and bring valuable insights from abroad. This dynamic has been quite common wrt. those who migrated to the Americas throughout the 19th and 20th centuries.
It's a nice sentiment, but you also can't ignore that, if people like myself are willing to go through the oftentimes extremely stressful task of emigrating with all the things that entails, there's probably a reason for it. It's not like you can just pick up and leave, after all
Also, that situation is a lot more likely to occur in the mother country than most people's host countries, if it doesn't happen already. There's a reason it was the East germans fleeing, and not the other way around.
And I find it so tragic. It means that the best elements of a given country are being sucked out of it. How can this country ever get better if the best elements just leave it ? Immigration exists because some parts of the world just suck, with corrupt governments, wars, you name it. I don't see how anyone can be happy of migrations, it means fleeing your home and leaving your roots. I don't think most migrations are something to be happy about.