IN AUGUST 2014 Boko Haram fighters surged through Madagali, an area in north-east Nigeria. They butchered, burned and stole. They closed schools, because Western education is sinful, and carried off young girls, because holy warriors need wives.

Taru Daniel escaped with his father and ten siblings. His sister was not so lucky: the jihadis kidnapped her and took her to their forest hideout. “Maybe they forced her to marry,” Mr Daniel speculates. Or maybe they killed her; he does not know.

He is 23 and wears a roughed-up white T-shirt and woollen hat, despite the blistering heat in Yola, the town to which he fled. He has struggled to find a job, a big handicap in a culture where a man is not considered an adult unless he can support a family. “If you don’t have money you cannot marry,” he explains. Asked why other young men join Boko Haram, he says: “Food no dey. [There is no food.] Clothes no dey. We have nothing. That is why they join. For some small, small money. For a wife.”

Some terrorists are born rich. Some have good jobs. Most are probably sincere in their desire to build a caliphate or a socialist paradise. But material factors clearly play a role in fostering violence. North-east Nigeria, where Boko Haram operates, is largely Islamic, but it is also poor, despite Nigeria’s oil wealth, and corruptly governed. It has lots of young men, many of them living hand to mouth. It is also polygamous: 40% of married women share a husband. Rich old men have multiple spouses; poor young men are left single, sex-starved and without a stable family life. Small wonder some are tempted to join Boko Haram.

Beware the youth bulge

Globally, the people who fight in wars or commit violent crimes are nearly all young men. Henrik Urdal of the Harvard Kennedy School looked at civil wars and insurgencies around the world between 1950 and 2000, controlling for such things as how rich, democratic or recently violent countries were, and found that a “youth bulge” made them more strife-prone. When 15-24-year-olds made up more than 35% of the adult population—as is common in developing countries—the risk of conflict was 150% higher than with a rich-country age profile.

If young men are jobless or broke, they make cheap recruits for rebel armies. And if their rulers are crooked or cruel, they will have cause to rebel. Youth unemployment in Arab states is twice the global norm. The autocrats who were toppled in the Arab Spring were all well past pension age, had been in charge for decades and presided over kleptocracies.

Christopher Cramer of the School of Oriental and African Studies in London cautions that there is no straightforward causal link between unemployment and violence. It is not simply a lack of money that spurs young men to rebel, he explains; it is more that having a job is a source of status and identity.

Throughout history, men have killed men roughly 97 times more often than women have killed women. The reasons are biological. In all cultures, the appetite for mayhem peaks in the late teens or early 20s, “just when males are competing more fiercely for mating opportunities, as in other mammals”, notes Matt Ridley in “The Evolution of Everything”. In “Homicide”, Martin Daly and Margo Wilson put it like this: “Any creature that is recognisably on track towards complete reproductive failure must somehow expend effort, often at risk of death, to try to improve its present life trajectory.” Wars, alas, give young men a chance to kill potential rivals (ie, other men) and seize or rape women. From Islamic State to the Lord’s Resistance Army in Uganda, rebel forces often let their troops treat females as spoils.

In some parts of India and China, where girl babies are routinely aborted, millions of young men are doomed to eternal bachelorhood. Mr Urdal found that Indian states with surplus males were more likely to suffer armed conflict—and by 2050 India could have 30% more single men hoping to marry than single women. In China, too, areas with extra men tend to have higher rates of rape and forced prostitution.

The polygamy powder keg

Any system that produces a surplus of single men is likely to be unstable. Polygamous societies suffer “higher rates of murder, theft, rape, social disruption, kidnapping (especially of females), sexual slavery and prostitution,” note Joseph Henrich, Robert Boyd and Peter Richerson in “The Puzzle of Monogamy”. The Mormon church banned polygamy in 1890 but some breakaway enclaves still practise it. They solve the problem of surplus males by expelling teenage boys from their isolated communities for minor infractions. In southern Utah your correspondent met Kevin (he would not give his surname), who was thrown out of such a sect at 17 for playing video games. He said it was odd how the elders almost never expelled girls.

Nigeria’s new president is determined to crush Boko Haram militarily. Meanwhile, other organisations such as the American University of Nigeria are trying to prevent young people from turning to violence. Previously radical imams preach peace; others teach job skills. Will this work?

A study by Christopher Blattman of Columbia University and Jeannie Annan of the International Rescue Committee offers hope. They looked at more than 1,000 ex-fighters in Liberia, where a civil war had just ended. This was not a promising group. Besides knowing how to kill people, they had few skills. Only 27% of its members were literate, even though they had spent an average of six years at school. All were making a living from crime: mining illegally or stealing rubber from plantations. And war was beckoning them again. A conflict had broken out across the border in Ivory Coast, and both sides were recruiting Liberian veterans with signing bonuses of $500-$1,500—a fortune for men who were making an average of $47 a month.

There was every reason to expect that these men would soon dig up their buried AK-47s. But a non-profit called Action on Armed Violence offered half the men a package of agricultural training, counselling and farming kit (such as seeds, piglets and tools) worth $125, in two instalments. The results were striking. The ex-fighters who were helped to farm got better at it, so they spent more time farming and less on illicit work. They made $12 a month more than the control group and showed less interest in going to fight in Ivory Coast. They were 51% less likely to say they would sign up as mercenaries for $1,000 and 43% less likely to say they had met with recruiters.

As the world ages, it is becoming more peaceful. Since medieval times the murder rate in most Western countries has fallen by a factor of nearly 100, estimates Stephen Pinker in “The Better Angels of Our Nature”. The past decade has seen the fewest war deaths of any in recorded history. Hard though it is to believe in the age of Islamic State, the world is heading for what Mr Urdal calls a “geriatric peace”.