THREE years ago Jenny Salgado, a Dominican shop assistant, moved to Highlandtown, a neighbourhood of pleasant terraces and unpleasant derelict factories in Baltimore. She moved because the cost of living in New York was too high. When she arrived the shop she works in, stuffed with piñatas and religious statuettes, was one of only a few Hispanic businesses. Now there are many more. “It’s good now if you speak Spanish,” she smiles.

Baltimore had been losing people for 60 years. To address this its mayor, Stephanie Rawlings-Blake, wants to make it the most immigrant-friendly city in the world. Its libraries provide Spanish-language exercise classes. To help those with no papers, the city is introducing micro-loans which require no credit checks. In 2012 Ms Rawlings-Blake announced that city police would no longer routinely check the immigration status of citizens or enforce any federal immigration law unless explicitly required to. The then governor, Martin O’Malley, a Democrat, made it possible for illegal immigrants to get driving licences.

Such welcoming policies are spreading. Rustbelt cities like Cleveland, Dayton and Philadelphia all avidly court immigrants. Rick Snyder, the Republican governor of Michigan, has asked the federal government to offer 50,000 visas to people who agree to live in Detroit. His administration has directed cash towards NGOs that market Motown to immigrants and made it easier for skilled migrants to get professional licences. Like Baltimore, Detroit woos refugees brought to America under federal programmes—and even tries to poach those who may have settled elsewhere.

A welcome mat is a powerful weapon against urban decay. When a city’s population falls, tax receipts tumble and services atrophy. Half-deserted neighbourhoods breed crime, driving yet more people to leave. No city has escaped this death spiral without attracting new residents, says Steve Tobocman of Global Detroit, an NGO. Immigrants are especially likely to move into the most blighted neighbourhoods and spruce them up.

Several studies suggest that when immigrants arrive, crime goes down, schools improve and shops open up. In Detroit, immigrants living near the tiny separate city of Hamtramck have formed local watches to guard against thieves. Their neighbourhoods are not just safer; they are also among the only places where it is as easy to buy fresh vegetables as drugs and alcohol.

But attracting new immigrants to the cities which most need them is hard, argues Audrey Singer of the Brookings Institution, a think-tank. They care about the same things as everyone else: safe streets, good schools and jobs. Cities which have lost population for decades struggle with all of these. Detroit and Baltimore have not fared equally well. The number of immigrants in Baltimore, long stagnant, increased by 50% between 2000 and 2013, helping the city to record its first growth in population in decades. Detroit’s immigrant population, by contrast, fell slightly, adding to its overall decline.

In Baltimore immigrants such as Ms Salgado are settling because they are drawn by cheap housing in a region that mostly lacks it. New arrivals from New York buy ruined houses and shops, typically paying $40,000 or $50,000 in cash. In places such as Highlandtown, which bustles with Ethiopian, Moroccan and Mexican restaurants, that has started a cycle of gentrification, as affluent young whites have been lured by the new urban vibe.

Detroit has not failed to attract new immigrants, says Mr Tobocman: Mexican restaurants and Bangladeshi mosques are proof of that. But it has struggled to retain them. Some immigrants say: “Yeah, you can buy a house for $20,000, but pretty quickly you realise that it’s dangerous, the schools suck and all of the jobs are in the suburbs,” he says.

Clarification: This article has been amended to make it clearer that Steve Tobocman was referring to some immigrants' views of Detroit, not his own.