Chinese families have long favoured sons over daughters, meaning the country now has a huge surplus of men. Is it also leading to a profound shift in attitudes to women?

His parents knew exactly what they wanted from their son: they called him Famiao, or "produce descendants". Yet when their first grandchild arrived, they refused to step across the courtyard of the family home to see the new baby. Qiaoyue was a girl.

When finally obliged to meet her, "they didn't even wash her face or comb her hair. I was furious," says their daughter-in-law, Chen Xingxiao.

"My father-in-law's friends would ask him, 'How come you haven't brought your grandchild out for a walk?' He would say, 'If it was a boy I would have done. She's a girl, so I won't.'"

Chen's righteous anger is perhaps more surprising than her in-laws' disdain. China's preference for sons stretches back for centuries. Infanticide, the abandonment of girl babies and favourable treatment of boys in terms of food and health has long produced a surplus of men. In the past two decades, the gap at birth has soared: the advent of ultrasound scans has allowed people to abort female foetuses, even though sex-selective abortion is illegal.

In the early 1980s there were 108 male births to every 100 female, only slightly above the natural rate; by 2000 that had soared to 120 males, and in some provinces, such as Anhui, Jiangxi and Shaanxi, to more than 130. The result is that more than 35 million women are "missing". Though China is not the only country affected – India's situation is similar – it has by far the widest gap; its one-child policy has exacerbated the problem.

The effects of the discrepancy are only now emerging in full. The country has tens of millions of men who are destined to die single. Some fear that the excess will lead to increased sexual violence, general crime and social instability. Yet campaigners see the first signs of hope, as more parents come round to Chen's way of thinking. Official statistics released this summer suggest the sex ratio at birth (SRB) has fallen slightly for two years running, to just over 118 males in 2010.

China's population and family planning chief, Dr Li Bin, said it showed the discrepancy "has been preliminarily brought under control"; while experts are more cautious, they agree that the figures offer some hope. The country's new Five Year Plan sets an ambitious target of cutting the ratio to 112 or 113 by 2016. Could China at last be poised to close the sex gap?

No one is claiming victory quite yet: in fact, the government has just pledged to get tougher, launching a new drive against sex-selective abortion. It is increasing safeguards – such as the requirement that two doctors are present at each ultrasound – and toughening punishments. Institutions, as well as individuals, will be held responsible for breaches; the worst offenders risk having their medical licences withdrawn.

"[In the short term] cracking down on illegal foetal sex testing and sex-selective abortions is very important and effective," says Professor Li Shuzhuo, of the Institute for Population and Development Studies at Xi'an Jiaotong University. But he acknowledges medical staff often find ways to indicate a baby's sex, despite the law. They may nod or shake their head; or use a full stop or comma at the end of medical notes – to indicate that parents have achieved their goal or must continue efforts to have a boy.

Other experts fear that cracking down on sex-selective abortion could lead to unsafe, illicit abortions or infanticide if the underlying wishes of the parents remain unchanged. In other words, the battle for China's baby girls will ultimately depend on changing preferences. But as Li points out, that is a long-term struggle, and society pays a high price in the meantime.

The roots of son-preference lie deep in Chinese culture. Traditionally, the bloodline passes through the male side. Women also "marry out", joining their husband's families and looking after their in-laws, not their own parents. For a long time, a son was your pension. Having a girl was wasteful. "Even though son-preference is not rational from the viewpoint of society as a whole, it is a rational choice for an individual," says Li.

Chen's home lies near lush rice paddies, where farmers in wide-brimmed straw hats bend double. The community used to rely on agriculture and believed a boy was necessary for the heaviest work in the fields.

"I can't really blame [my in-laws]; their view was a common one. We have a saying, 'The better sons you have, the better life we can have,' because men have more strength and can carry out more work," says Chen.

In fact, official policy has adapted to these assumptions. China's strict birth-control rules, introduced just over 30 years ago to curb a soaring population, restrict most couples to one birth. But there are several exemptions. Ethnic-minority families are allowed more than one child; couples who are both only children are permitted to have two. The most striking example is the exception made for rural households. While their urban counterparts are generally restricted to one birth, rural couples are allowed a second - if their first is a girl. The statistics show just how important producing at least one son is: the sex ratios for second and third births are vastly more skewed than for first children.

When Chen's daughter was born, a little over 30 years ago, the consequences of the ultrasound had yet to be felt in Shengzhou. But by 1982, 124 boys were being born for every 100 girls. Five years later that figure had risen again, to 129.

Then something striking happened: the ratio dropped steeply. By 1996 it was 109.5. Soon after, according to statistics, it returned to the natural level.

You do not have to look far for part of the explanation. Shengzhou is, it boasts, International Necktie City of the 21st Century, making 350m ties a year – or 40% of the world's supply – as well as huge quantities of gas stoves and cone diaphragms for speakers.

Its factories offer plenty of jobs for daughters, allowing them to make a hefty economic contribution to the household. Across the country, manufacturers have frequently preferred female employees, regarding them as more careful and less troublesome.

Many rural families have less land than they used to; and machinery is available to work the soil, making brute strength less important. China is beginning to develop a welfare system. And development has brought other changes – couples who move into cities have more exposure to new ideas, and less pressure from extended families, say experts.

Old habits and beliefs are eroding. In villages as well as towns, conjugal ties between husband and wife have become more important, while the filial links between parent and child have become less so. Young couples are more likely to live apart from relatives. Few parents can now count on a dutiful daughter-in-law caring for them; and many are noticing that daughters are doing a better job.

Chen admits that she was initially disappointed when her daughter was born. "Of course, I wanted to have a boy. But after giving birth, I thought: 'I don't care. This is my baby,'" she says.

"I looked around me; one of my neighbours had five sons and one daughter. One day, when he was 60 or 70, he wanted some money from his sons for living costs. He cooked a tableful of dishes and bought wine and invited his sons. But none of them agreed to give the money to him. He was furious and smashed the table with his stick. And I thought: 'Well, sons are useless.'"

Meanwhile, she noticed, daughters were returning to visit their parents, bringing gifts and money. Despite strong pressure from her husband and in-laws, she refused to have another child: Qiaoyue was enough for her.

Anthropologist Yunxiang Yan's work suggests that others in China are drawing similar conclusions – and that it is changing their attitude towards girls.

"You can see clearly that a trend of treating sons and daughters equally is slowly emerging in some regions and developing in others," says Yan, of the University of California, Los Angeles.

Some even think that son preference may partially correct itself. The surplus of men has increased competition for brides, meaning families must buy ever more expensive housing to ensure their sons can marry – increasing the economic attractiveness of daughters.

The government has spent an estimated 300 million yuan (£29.5m) trying to precipitate this shift in preferences. Li is the lead consultant in the Care for Girls programme, which combines carrot and stick with educational projects.

There are punishments for sex-selective abortions and extra subsidies for couples who do not use their right to a second child after having a daughter. One county in Fujian has built houses for daughter-only families.

But Ru Xiaomei, deputy director of the international liaison department at the National Population and Family Planning Commission, says the programme is designed to promote female equality in general. So there are roadside signs telling villagers that girls can continue the family line; focus-group discussions for mothers-in-law; help packages for women starting businesses and extra encouragement for girls to enter schools. Officials have even tried to promote the idea of men marrying into women's families, rather than vice versa.

A pilot programme in 24 areas, selected for their very high imbalances, saw the average ratio fall from almost 134 in 2000 to just under 120 in 2005 – still high, as the experts involved acknowledge, but a substantial improvement. It has since been rolled out across China; Li says it is hard to know how exactly how much of a difference it is making, but is confident it has shown results across the country.

Others have concerns: Dr Lisa Eklund of Sweden's Lund University suggests in a recent thesis on son preference that parts of the programme could backfire. Capitalising on gender norms – such as the idea that women are caring – may increase sympathy for girls in the short term, but in the long run reinforce stereotypes – and, thereby, son preference.

Similarly, the social and economic incentives "are partially based on the assumption that having daughters creates vulnerability ... They convey the message that daughters are not as valuable as sons, and that families with only daughters are in need of financial support," she warns.

Whatever the merits of individual policies, government intervention has helped to rebalance births. In the early 90s, South Korea had Asia's highest ratio at birth; by 2007, it had a normal rate. Experts suggest that reforming the family law system, expanding female employment and increasing urbanisation were key.

"I think that the preference for sons is decreasing in China, especially in the more affluent coastal areas, where the SRB shot up fastest earlier," says Dr Monica Das Gupta of the World Bank, who has been tracking son preference in Asia. "But you shouldn't expect to see the sharp decline you saw in South Korea, because South Korea is a small, homogeneous country ... The new ideas swept through the country very quickly. In China it will take longer because of its size and internal differentiation."

Professor Yuan Xin, of Nankai University's Population and Development Institute, warns that it will take at least 10 or 20 years' more work to end a preference that dates back thousands of years. Others think that is optimistic.

Chen says she has witnessed attitudes in Shengzhou shift in the past few decades. Even her in-laws have been won over, because her daughter treats them so well. "I'm not boasting, but I think I took the lead," she says. "There's been a very positive trend, but I won't say things have changed totally."

Recently, a neighbour agreed to have a second child under intense pressure from her husband's family, joking that she was damned if the next child was a girl. "It was twin daughters," says Chen ruefully. "The mother-in-law still wants boys."

Additional research by Han Cheng

• This article was amended on 3 November 2011. The original incorrectly said that 300m yuan was roughly equivalent to £2.4m rather than £29.5m.