Middle income countries are also facing demographic busts (although years later compared to rich countries). Competing for highly-skilled human capital, not massive third world immigration is essential, the main reason beaing that advanced economies with generous welfare are most affected by falling birth rates, and migrants to rich countries take as little as a single generation to adopt similar reproductive patterns relative to native populations (i.e. sub-replacement TFR: asian and east-asian to north america are the greatest example of this, but also hispanics and muslims to a lesser extent have collapsing birth rates). Even more dangerous to a stable economy is, that with a generous welfare system an invereted population pyramid will not be enough to sustain it, aging immigrant populations will exacerbate the problem: again, sub-replacement TFR in at most 2 gens. At most it will delay the demographic problem, however I personally think that focus on industrial automation will be more important.
See also my comment from a previous thread: https://news.ycombinator.com/item?id=34909400