A LARGE, FEATURELESS shed by the motorway between the Castilian towns of Burgos and Lerma is home to ASTI Mobile Robotics. Inside, on the main shop floor, a score of workers armed with iPads test driverless contraptions mounted on red and orange steel frames. The automatic guided vehicles (AGVs) they are designing, building and controlling with customised software already operate in factories and warehouses in 16 countries around the world, including some belonging to Fiat, Airbus and Nestlé. The robots deliver parts to production lines, bringing more flexibility and efficiency to the jobs that conveyor belts, forklifts and tractors used to do.

They are the brainchild of Veronica Pascual, a 39-year-old aeronautical engineer who took over her parents’ small conveyor-belt firm when it ran into trouble 15 years ago. At the time the customers were mainly confined to northern Spain, but now 70% of sales are abroad. She is confident that turnover this year will rise to €35m ($41m), from €25m in 2017, and will reach €100m by 2020. Her staff has expanded more than tenfold, to 210, of whom 25 are working at an innovation centre in Madrid. One hundred new staff joined last year alone. The business is highly profitable, says Ms Pascual, and continuously reinvests those profits in growth. “We’re thinking always of where we want to be in five years,” she explains.

As a research-intensive high-tech company with global ambitions, growing fast and run by a woman, ASTI is everything that Spanish business is traditionally not. Before the financial crisis Spain had a clutch of multinationals, most of them in Madrid in regulated sectors such as banking, telecoms and infrastructure (the big exception was and is Inditex, a fast-fashion giant based in Galicia). Catalonia and the Basque country had medium-sized industrial firms, most of them family-owned. Below that came hundreds of thousands of small family businesses.

The crisis brought wrenching change. Between 2008 and 2013 Spain lost 9% of its GDP in real terms, private consumption fell by 14% and unemployment surged. The subsequent recovery owed much to Mr Rajoy’s reforms. The previously rigid labour market became more flexible. Wage bargaining was devolved to firm level, which helped make companies more competitive. Redundancy pay was cut from 45 days per year worked to a still-generous 33 days, making lay-offs more bearable for companies.

Helped by the promise of a €100bn loan from the EU (of which only €40bn was used), the government also cleaned up the financial system, merging or shutting down scores of broken cajas (savings banks) which had made reckless property loans. The non-performing loan ratio is still slightly above the EU average but has declined steadily, and credit is flowing again. The collapse of Banco Popular in 2017 (and its absorption by Santander, a bigger rival) was a delayed effect of the crisis, not a sign of new problems ahead. The government also paid off the arrears that regional governments had run up with their suppliers, which added up to 5% of GDP. That saved many small businesses.

Mr Rajoy also consolidated the public finances, cutting the budget deficit from a peak of 11% of GDP in 2009 to 3.1% in 2017. His approach was politically crafty. The first and boldest decision he took was to reject advice from many quarters to seek a general Greek-style bail-out of the economy. That gave him the freedom to hold pensions steady (the PP relies heavily on the over-60s vote) and extend the period for which unemployment benefit is paid. He brought down the deficit gradually by slashing public investment and squeezing other spending.

Recovery was helped by favourable external conditions, including low interest rates and oil prices (almost all the country’s oil is imported). Both are now rising, but Spain’s economy has changed since the crisis. It has proved more flexible than Italy’s or France’s, says José Luis Escrivá, director of a new independent fiscal authority appointed by Congress. Compared with 1999, a cyclically neutral year, he sees many differences. Back then, Spain had a current-account deficit of 3.3% of GDP; now it enjoys a current-account surplus of close to 2% of GDP. Before the crisis, inflation and labour costs in Spain were uncomfortably high. Since then unit labour costs have been well below the euro-zone average in every year except 2015, and inflation is currently slightly lower than in Germany.

Yet in 1999 public debt was 61% of GDP and falling; that year the government posted a primary fiscal surplus (before interest payments) of 2% of GDP. Now the public debt stands at 98% of GDP, and the government will not achieve a primary fiscal surplus until next year at the earliest. Still, companies and households are far less indebted than before the crisis.

Mr Sánchez’s government faces a delicate balancing act. It would like to reverse Mr Rajoy’s public-spending cuts, but has promised to stick with his budget for this year. In theory, this aimed at a fiscal deficit of 2.2% of GDP, but in fact 2.7%, according to European officials. Nadia Calviño, Mr Sánchez’s economy minister has adopted the latter figure. But she insists: “We are a country committed to fiscal balance.” Since interest rates are likely to rise, it would be prudent to cut public debt faster, so some taxes may have to go up.

Can it last?

To overcome the social problems left by the crisis, several more years of steady growth are needed. The recovery is already in its fourth year, so how long can it continue? Rafael Doménech, head of macroeconomic analysis at BBVA, a bank, thinks that the economy can go on growing faster than the euro-zone average for some time because unemployment is still high. The question, he says, is just how long it can carry on doing so without starting to generate the sort of cost pressures experienced in the past. Raymond Torres of Funcas, a think-tank, does not see growth continuing at its current pace much beyond 2020 without further reforms, especially in education, skills and regulation.

Spain enjoys a world-class infrastructure, as seen in its high-speed trains, motorway network and modern ports and airports. Its fibre-optic network for high-speed data transmission covers 76% of the population, the biggest proportion in Europe, and will reach 95% by 2021, according to José Maria Lasalle, who was responsible for digital policy under Mr Rajoy. But the software often falls short, and Spain still wraps everything in red tape. In the World Economic Forum’s competitiveness index, Spain ranks 12th out of 137 countries on infrastructure but a shameful 113th for the burden of government regulation, well below countries such as Guatemala and Paraguay. Decentralisation has added an extra layer of regulation; for example, business permits for one region are not automatically valid in others.

The country’s tax system manages to be both punitive and lax. A headline corporate-tax rate of 25% is mitigated by myriad deductions and exemptions (though efforts are being made to prune these). Buy a bottle of beer or a soft drink in a supermarket, and you will pay value-added tax at 21%; buy the same thing in a bar, and you pay 10%. That is why Spain has more bars per person than any other European country (which fans would say is part of what makes it such a civilised place). And by some reckonings, the “black” economy amounts to 17% of GDP.

The chief cause for optimism is the change that has taken place in business. Construction is no longer the driver of the economy, as it was before the crisis. Tourism remains important, but it is no longer just about sun- and sangria-seekers; cities such as Bilbao, Valencia and Seville are now attracting better-heeled visitors. Total exports of goods and services in 2016 were up by 46% on 2009, accounting for 33% of GDP. Spain produces more cars than any other European country except Germany; it is also starting to sell business services abroad. The number of exporting firms has increased by almost one-third since 2011, according to the Círculo de Empresarios, a business think-tank.

Companies like ASTI have sprung up across the country, led by a new generation of entrepreneurs, many of them educated abroad and more internationally minded than their parents. The Basque country is a hive of innovation. In the Automotive Intelligence Centre outside Bilbao, 31 companies, mainly component-makers, engage in “collaborative innovation” on things such as driverless vehicles, lighter parts and shorter time to market for new products. They are selling to the whole of Europe and beyond, according to Ines Anitua, the centre’s manager.

A business incubator at Vizcaya Technology Park, near Bilbao airport, houses 23 start-ups, mainly in advanced manufacturing and biosciences. One is the Art of Discovery, whose founder, Iñigo Angulo-Barturen, used to head the unit for therapeuticeffectiveness studies of GSK, a big drug company. With a staff of ten, it is now working on new medicines for prolonging life, as well as doing not-for-profit work on malaria.

Barcelona has several good universities and a clutch of tech start-ups. More surprisingly, perhaps, such companies can be found across Spain, according to Adrián García-Aranyos of Endeavour, an entrepreneurship foundation. He points to Cabify, a Madrid-based rival to Uber, that has become Spain’s first “unicorn”, with a valuation of over $1bn. Or take Glamping Hub, a global booking site for luxury camping holidays, a Silicon Valley-style startup based in offices in the heart of Seville. With 75 staff (and 25 in a second office in Denver) and triple-digit annual sales growth since it was founded in 2013, it is the creation of David Troya. He grew up in Triana, a Seville district famous for flamenco, and did an MBA in San Francisco on a grant from the regional government of Andalusia. Raising finance has taken longer than it does in California, he says. But venture-capital funds and the supply of risk capital are now expanding fast in Spain.

The transformation of the economy is still a work in progress. The mass of small firms with low productivity is still there. Under 1% of firms have more than 50 workers, compared with 3% in Germany and 1.8% in Britain, according to the Círculo. Cristina Garmendia, a former science minister who now heads a foundation to promote innovation, sees a “systematic deficit” in investment in research and development and in software. Public spending on R&D was cut hard in the crisis; it now totals only around 1.2% of GDP, half the average in the OECD group of mainly rich countries. Yet people like Mr Troya say their biggest problem is finding the right people to work for them, even in a country with 3.3m registered unemployed.