ONCE referred to even in China’s media as the country’s “sex capital”, the southern city of Dongguan remains the subject of many lewd jokes. Tens of thousands of sex workers used to practise in the city, servicing people working in its vast sprawl of factories as well as visitors drawn by its sleaze. That began to change early in 2014, when the local government launched an unusually fierce anti-vice campaign. In the first few days alone some 6,000 police raided 2,000 saunas, karaoke bars and other such venues. They hauled away many of their staff and patrons.

Four years later punters can still buy sex in Dongguan, as they can across China. A taxi-driver explains that instead of operating in posh hotels and “super saunas”, as many of them used to, Dongguan’s sex workers now mainly ply their trade more discreetly. He offers an appointment with a woman he knows. Yet city officials have done a far more thorough job of clamping down on the business than most locals expected. They have persisted with their efforts, even though their campaign has damaged service industries in Dongguan (also sometimes called “sin city” in China’s English-language press) that depended on the sex trade. Many of Dongguan’s prostitutes were migrants from rural areas. A lot of them appear to have left town.

The Communist Party has long portrayed prostitution as a form of exploitation and itself as a liberator of women who engage in it (with the help of thought reform in labour camps). After seizing power in 1949, the party used its control of the economy to provide alternative jobs for many prostitutes. Before long it claimed to have wiped out the trade entirely.

Prostitution returned in force after China began liberalising its economy in 1978. The government encouraged foreign investment and relaxed restrictions on migration from the countryside to cities. Rural women took the opportunity to seek better-paid work. Businesspeople from Hong Kong, Taiwan and elsewhere began piling in to build factories, including in Dongguan. Many of the migrants found jobs on the new production lines. Some sought work in new red-light districts.

Experts reckon there may be millions of sex workers in China, most of them women. Despite numerous campaigns against the business, prostitution is probably becoming more common. Surveys carried out over 20 years by Pan Suiming and fellow researchers at Renmin University in Beijing found that the proportion of Chinese men who admit to having hired a prostitute doubled to around one in seven in the decade to 2015. They believe it might reach more than one in six by 2020. China’s skewed sex ratio, caused by a traditional preference for sons that has encouraged abortions of female fetuses (a problem exacerbated by a now-abandoned policy of limiting couples to having only one child) means that there will be growing demand for commercial sex from men unable to find wives.

Most Chinese sex workers choose the trade freely, says Ding Yu of Sun Yat-sen University in Guangzhou. Some prefer it to jobs that are commonly done by poor women from the countryside, such as in shops or factories. They gamble that, in spite of being illegal, prostitution will offer more chance to save money. Others become sex workers only as a last resort. China’s limited social safety-net can leave those who are ill, unemployed or on the run from violent men with few other options, says Lijia Zhang, a writer who has researched China’s sex business.

The penalties are harsh. Sex workers and their clients can be fined and locked up without trial for up to 15 days. Prostitutes caught repeatedly can be sent, also without trial, to “custody and education” centres, a type of jail where they can be held for up to two years. Pimps can be sentenced to up to ten years in prison. There is less risk of public shaming. In 2010 the government banned police from parading sex workers in the streets, once a frequent form of punishment. But health campaigners criticise a common police practice of using the presence of condoms as evidence that any woman found during a raid on a massage parlour, hair salon or karaoke club is engaged in prostitution (this makes sex workers less likely to carry or stock them, says Tingting Shen of Asia Catalyst, a charity). Tales abound of sex workers swallowing used condoms when police storm in.

For all the crackdowns, however, official statistics show a drop of two-thirds in the number of prostitution-related cases investigated by the police since a peak in 2001 (see chart). One reason is that police forces can no longer take a cut of the fines they collect, so they have less incentive to target petty criminals, according to Mr Pan of Renmin University. Their reduced income from this source has been offset by better funding. The number of custody and education centres has been falling too, from 183 in 2000 to 116 by 2014.