SPANIARDS are used to former public officials getting rich from doing business with the state. When news emerged of investigations into a former official in Castile and León who had secured lucrative wind-farm licences from his ex-colleagues and a former official in Andalusia whose companies netted regional contracts for state-subsidised worker-training courses, few were surprised. Corruption and cronyism (the distribution of political favours to businesses) explain much of the Spanish public’s growing disdain for the two parties that have run the country for the past 32 years: the ruling Popular Party (PP) and the opposition Socialists (PSOE).

Distrust reached a nadir with the temporary arrest two weeks ago of Rodrigo Rato, a former PP finance minister who went on to run the IMF in Washington. Police searched Mr Rato’s office and home in an investigation into unexplained income. He was already under scrutiny over freewheeling use of company credit cards during his chairmanship of Bankia, a bank that needed a €22 billion ($27 billion) rescue under his stewardship. Mr Rato was seen as one of the architects of Spain’s economic miracle in the early 2000s. That miracle now seems a distant memory. Unemployment is running at 23%, and the IMF says it will take nine years, until 2017, to return the economy to its pre-crisis size.

Researchers are beginning to see links between Spain’s excessively cronyistic and corrupt public administration, and the defects that have made it so hard for the economy to recover. The problems may have started well before the crash. From 1995 to 2007, while the Spanish economy was growing at 3.5% per year, productivity declined by 0.7% per year—even as overall EU productivity was growing at an average of 0.4% per year.

Blame has traditionally been pinned on a housing bubble that fostered distorted growth in the construction industry. But a recent paper by a team headed by Manuel García-Santana of the Université Libre de Bruxelles finds that the productivity fall was spread more evenly across all sectors. It had little to do with skills, innovation or debt. “We found that bad [less productive] companies grew faster than the good ones,” says one of the co-authors, Enrique Moral-Benito. Productivity falls were greater when the government was heavily involved, through contracts, licences or regulations. Luis Garicano, the economics adviser of the liberal Ciudadanos party, says this points to an economy dependent on contacts, corruption and cronyism.

Other explanations are possible as well. Banks may have been happier lending to companies with public contracts, and some more productive businesses may have limited their growth to avoid losing fiscal, labour or social-security advantages enjoyed by smaller firms. Either way, those who successfully negotiated their way around the public administration—whether through luck, knowledge, cronies or backhanders—did best.

Popular anger over cronyism helps to explain why the PP government and its prime minister, Mariano Rajoy, seem likely to take a hammering in elections to regional governments and municipalities on May 24th. Over the past year 500,000 jobs have been created and growth is forecast at 2.9% this year, yet the PP has shed half its support. The Socialists are also low in the polls, while Ciudadanos and the left-wing Podemos party have risen. The elections are now a four-way race. A poor result on May 24th could even force Mr Rajoy to bring forward a general election due at the end of the year.

The government is hunting for every bit of positive news. It trumpeted the latest economic-sentiment figures from the European Commission, which put Spain ahead of the other big euro-zone economies. But if voters are less concerned about the latest figures than about the underlying rot of decades of kickbacks and insider dealing, that may not count for much.