When immigrants enter a region, nationalist and populist parties tend to get more votes in the next election. They benefit from an anti-outsider backlash. They also tend to foment that same backlash.

But when economists analyzed 28 elections in 12 European countries over about a decade ending in 2016, they found that only certain groups of immigrants were met with native backlash, and only certain groups of native voters participated in it.

Specifically, nationalist parties stand to gain more votes when the immigrants are unskilled or from outside Europe. When skilled or European immigrants arrive, nationalist parties lose support.

Voters who are less educated, male and from smaller towns react most strongly to changes in the immigrant population, the researchers found. Educated, female and urban voters don’t respond with the same intensity.

Economists Simone Moriconi of IÉSEG School of Management in Paris, Giovanni Peri of the University of California at Davis and Riccardo Turati of Université Catholique de Louvain in Belgium released these findings this week in a working paper from the National Bureau of Economic Research.

The economists rated 126 parties’ manifestos based on mentions of a national way of life and patriotism, as well as attitude toward the European Union. They combined those ratings with surveys that followed individuals’ party support over time, and compared the result with changes in the population of high- and low-skilled immigrants in detailed regions within each country.

Regions in Switzerland, the United Kingdom and Denmark dominated the most-nationalist list, while regions in Belgium, France, Spain and Sweden were among the least nationalist.

The most nationalist parties tended to portray immigrants as “impoverished, unskilled, unproductive” outsiders who “compete for jobs, drain public finances and constitute a threat to national values,” the economists wrote.

Their message hasn’t escaped Lamin Jarju, a refugee from Gambia quoted by The Washington Post’s Michael Birnbaum in a March article about an Italian town celebrating its success at expelling migrants. “They’re talking very badly about immigrants, and they say that if they win, a lot of things will change for us,” Jarju said. “They’re using immigrants to win more votes.”

Most sources agree that immigration is neutral or beneficial to native workers, especially in the long run. However, there’s evidence from the United States that an increase in lower-skilled immigrants lowers wages among less-educated workers in the short term — especially when those workers are earlier immigrants, or members of racial or ethnic minority groups.

There has been less research about the effects of skilled immigration, but studies suggest that skilled workers drive up wages and increase employment, through innovation, entrepreneurship and greater production.

This study reinforces the narrative that uneducated natives feel most threatened, and that unskilled immigrants are considered most threatening.

A widely cited 2010 analysis in American Political Science Review found that voters’ positions on immigration are shaped by social and ethnic concerns, not fear of labor-market competition. Educated voters tend to exhibit less hostility toward immigration — even when it involves skilled workers who might compete for their jobs — because they believe they are acting in the best interests of society.

Across almost every demographic, an influx of non-European immigrants resulted in a bigger surge of support for nationalist parties than an increase in European immigrants, regardless of skill level. Based on the available data, we can’t state categorically that race and ethnic origin are the deciding factors, but Moriconi told us that in general, pro-nationalist sentiment was driven by non-European migrants.

“People with less previous exposure to immigrants respond more significantly to their presence, both in positive and negative terms,” Moriconi and his co-authors wrote.

Moriconi explained that a less-educated, older voter in a small town typically will have had fewer chances to interact with immigrants and non-Europeans than a younger female urban voter who went to college for four years and was born into a more diversifying country. That lack of experience leads him to react more strongly to the rhetoric that follows the first appearances of unskilled, non-European faces in his area.

“People from the European Union are less aware of the contribution that these people from outside Europe can give to the economy,” he said.

In a working paper earlier this year, Georgetown University economist Anna Maria Mayda, Giovanni Peri and Bank of Canada economist Walter Steingress found a similar pattern in the United States, where they looked at support for the Republican Party. Republicans usually pushed “more restrictive immigration policies” during that time, they found.

They analyzed election results between 1990 and 2010 at the county level and found that an increase in low-skilled immigrants raised the Republican share of the vote. An influx of high-skilled migrants preceded a drop in Republican support.

As in Europe, they found a stronger swing toward the party that takes a harder line on immigration, in this case Republicans, in rural counties and in those with more unskilled workers.