AS HE prepared to begin a second term as Colombia’s president on August 7th, the first name that Juan Manuel Santos inked in for his cabinet was Mauricio Cardenas, who keeps his job as finance minister. That was no surprise: helped by an investment boom, the country’s economy grew by 6.4% in the first quarter compared with the same period last year. Mr Cardenas says the second quarter was strong, too. The government will be raising its growth forecast for this year from 4.7%.

This is a welcome exception to a regional trend: Latin America as a whole looks likely to grow by less than 2% this year, the worst figure since 2009 (see chart). The end of the commodity boom that lifted the region for more than a decade, the fading of the era of cheap money as central banks in the rich world prepare to raise interest rates and a series of home-grown factors have all taken their toll.

Colombia’s lottery winnings at work

The fall has been especially abrupt in Peru, where the economy is suffering what Luis Miguel Castilla, the economy minister, calls a “hiccup”. Even if it rebounds in the fourth quarter as he expects, predictions of growth of more than 4% this year seem too rosy. For a country that has enjoyed Asian-style growth averaging 6.4% a year in 2003-13, the slowdown is a nasty surprise. Colombia has overtaken Peru to become the fastest-growing of the bigger Latin American economies.

Both countries are medium-sized commodity exporters with open-market economies. They are both members of the free-trading Pacific Alliance. So why is Colombia now faring better than Peru?

The answer starts with what Victor Bulmer-Thomas, a British economic historian of Latin America, has called “the commodity lottery”. Colombia’s main exports are oil and coal, whose prices have held up over the past couple of years. Peru depends on copper and gold for half its exports; their prices have fallen (steeply in the case of gold). So the value of Peru’s exports fell by 9% last year while that of Colombia’s slipped only slightly.

In explaining Colombia’s growth, Mr Cardenas also points to several reforms. Last year the government arranged lower mortgage rates via an agreement among banks and a public subsidy. This helped to boost construction, which is growing at over 10% a year. The subsidy is now being withdrawn; $200m of public money leveraged housing investment totalling $2 billion, according to Mr Cardenas.

A law in 2012 cut onerous payroll taxes (while raising income tax on the better-off). The result is that formal-sector jobs are growing at 8% a year, while the large informal sector has started to shrink, which ought to boost productivity. Ambitious, albeit delayed, private-public partnerships in roads and railways should see investment of up to $25 billion by 2018.

Mr Santos has also implemented a fiscal rule under which the public-sector deficit, long a drag on growth, has fallen steadily, to less than 1% of GDP. That has boosted the confidence of investors. In March J.P. Morgan, a bank, more than doubled the share of Colombian bonds in its emerging-market indices.

By contrast, Peru is suffering what Mr Castilla calls a “complicated” year. First, the sol depreciated by about 9% in 2013, a textbook consequence of deteriorating terms of trade, which raised the financing costs of some careless Peruvian companies. Further setbacks have included weather-related contractions in fishing and farming, a standstill in investment by regional governments because of corruption scandals and unexpected technical problems at two big copper mines.

In response the government is shovelling money at the economy. Extra bonuses and wage increases for state employees and extra loans for small business are worth more than 1% of GDP. Mr Castilla insists that the economy will rebound in the fourth quarter and will again grow by 6% in both 2015 and 2016. With new low-cost mines starting up, copper output should rise by 20% next year while building work will start on public-private partnerships worth $18 billion, including a gas pipeline and a second metro line for Lima.

Most analysts predict that Peru will soon regain its lead over Colombia. But that is not assured. Peru’s long growth spurt was based on a mixture of catch-up after a disastrous 1980s, sound economic policies (it enacted a fiscal rule in 1999), cheap natural gas and, above all, a huge mining boom. But Peru has now caught up a lot. Francisco Rodríguez, an economist at Bank of America, argues that the fall in mineral prices, together with delays in mine development, have already driven Peru’s potential (ie, non-inflationary) rate of growth down to less than 5% and that it will fall further.

Only “if we do nothing,” replies Mr Castilla. The government has launched plans to cut red tape and to promote diversification away from mining. It has enacted promising reforms of the civil service and of education, though their success turns on determined implementation. Its critics decry an absence of labour-market reform.

In Colombia, Mr Cardenas is confident that all the new highways will raise the country’s potential rate of GDP growth by 0.7 percentage points over four years. Mr Santos says a peace deal with the FARC guerrillas would add another extra point of growth, by boosting agricultural and energy output and encouraging investors.

But there are risks. The biggest involves the oil industry. Guerrilla sabotage and declining reserves are threatening output and thus government revenue. Peace carries a price as well as offering a dividend. Mr Cardenas’s next task may be to push through further tax increases.

Lotteries give countries opportunities. Development comes from using them to create more productive economies. On that score, Colombia now has an edge over Peru; both are better placed than many of their South American neighbours.