A specter is haunting the modern world yet again—the specter of nationalism. From Brexit to electoral cycles in Europe and the United States, the “nation” is reasserting itself as the primary unit of economic, social, and political realms. The tide has changed against globalism rather unexpectedly.

To be sure, there is no single factor that explains why we risk undoing globalization, which has shaped much of our lives in recent decades. Yet, there are many factors that explain pieces of the puzzle. The global economy is almost a decade into the worst economic recovery since the Great Depression, and there is no end in sight. A record high number of people have been forcibly displaced across borders, and more may be on their way as conflict and terrorism escalates. Together, these alone leave little mystery on why protectionist reflexes are triggered in many countries. Add the growing disappointment with conventional international mechanisms, which have profoundly failed to solve the most prominent problems of our time, and we get the recipe for nationalism: Aren’t foreigners stealing jobs by migrating and Chinese doing the same via free trade?

Much ink has been spilled against such premises of rising nationalism. But a curious observation remains to be explained: Why do nationalist arguments tend to resonate with old people? Take the recent case of Brexit. Only a quarter of youth (ages 18-24) voted for the “leave” camp. In comparison, six out of ten old people (ages 65+) wanted to leave. The youth were quick to announce the stark contrast in social media and clarify their position! So, what is it that the old know about globalization that the young fail to see?

In a recent study, my colleagues Richard Chisik and Dhimitri Qirjo and I tried to explain how demographic aging—an increase in the share of old people in the country—could shift the economic policy preferences in an economy. Because nationalist sentiments often involve objections to free trade and migration, we paid particular attention to those policies. We came up with three interesting results that may help us understand how aging and nationalism are linked.

First, an aging population becomes more dependent on imports. To see this, note that the old consume more services like long-term care and the young consume more goods like smartphones. Therefore, the higher the share of old people in the population, the higher the demand for services, which cannot be imported, and the lower the demand for goods that can be imported. As a result, more firms find it lucrative to get into the services business when demand pushes the price of services up. Some firms may cease producing goods and become service providers, and others move overseas where demand for goods like smartphones remains large. The economy then relies on imported rather than domestically produced goods.

Technically speaking, aging has a firm delocation effect, or movement of firms and their resulting employment from one country to another, and this happens even if producing in other countries is not dirt cheap. By itself, delocation is not necessarily a bad thing for the aging society: The economy would be producing more services because it would be consuming more of them. The problem is that industries like those producing smartphones are often more innovative than non-tradable services like long-term care and restaurants. As a result, the aging country would potentially lose income in the long-term as its workers would miss an opportunity to become more productive.

Second, when aging occurs, more firms move overseas if trade barriers are low. When firms can freely ship back their products after moving overseas, moving closer to a larger overseas market becomes more appealing as the home market is not lost. If, however, the aging country imposes egregiously high tariffs on imports, smartphone producers might rethink their relocation decisions.

Third, nationalists may have a point about free trade at first glance, but more in-depth analysis proves otherwise. From the nationalist point of view, erecting barriers at the border, be it made of concrete or import tariffs, may appear to make sense economically. However, this logic is terribly shortsighted: It is based on a static view of a world where actions cause no reactions. More specifically, it fails to recognize that when one country erects barriers its partners will do the same in response. In the end, a trade war may be triggered, only to be accompanied by a rising wave of protectionism, which would hurt the aging country more than the partner. Yes, some firms would come back home, but the losses from paying more for imports and earning less from exports are much greater than these gains. In comparison, allowing in young immigrants provides a better mechanism to mitigate the firm delocation effect as it will aggravate no reaction from trade partners.

Altogether, it is interesting to see that rising nationalism might have deep roots in demography. Going forward, more effort needs to be devoted to understanding the relationship between the two. Demographic factors will not disappear, and they may lead to shortsighted moves in the absence of countervailing measures. For now, however, we should find ways to steer nations away from disastrous unilateralism. One message needs to be communicated clearly: One may wish to jump the queue while others wait, but when everybody does so, nobody gets to eat the cake.