Seventy years ago, Costa Rica got rid of its army.

President Carlos Alvarado Quesada said that has allowed it to invest elsewhere.

Costa Rica also generates more than 99% of its electricity from renewable sources.

As a result, Costa Rica is the happiest and most sustainable country on Earth.

Costa Rica is getting something right. The Central American country of stunning beaches, rainforests, and biodiversity, is also known for its stable democracy and educated population.

Its president, Carlos Alvarado Quesada, said at Davos 2019: "Seventy years ago, Costa Rica did away with the army. This allows for many things. Eight percent of our GDP is invested in education because we don't have to spend on the army. So our strength is human talent, human wellbeing."

By comparison, World Bank data shows the US spent less than 5% of its GDP on education, while the world average is just 4.8%.

Surfers in Costa Rica. Colin D. Young/Shutterstock

President Alvarado said not spending on the armed forces also allowed his country to protect the environment. Costa Rica generates more than 99% of its electricity from renewable sources, with the vast majority from hydroelectric dams.

While this is a major achievement, electricity only represents a small proportion of the country's energy usage, as many homes use gas for heating, and fuel for their cars.

Air quality in Costa Rica, as in many countries around the world, is a concern, and some parts of the capital San Jose breach World Health Organization limits for air pollution.

Read more: For $260 a night, you can stay in this Boeing 727 airplane-turned-hotel suite perched 50 feet high in Costa Rica — take a look inside

The Costa Rican government has used taxes collected on the sale of fossil fuels to pay for the protection of forests.

President Alvarado said: "We saw in the eighties that the forest coverage was reduced to 20% due to animal farming and timber. We've managed to recover all this and we're back to forest coverage of 50%. By this we are combating climate change."

Forests are of crucial importance to the country's biodiversity, which hosts more than five percent of the world's species, despite a landmass that covers just 0.03% of the planet.

President Alvarado said these efforts have helped boost Costa Rica's economy. "Many people say that to protect the environment goes against the economy. Whereas it's the complete contrary. Our tourism has grown precisely because of this."

Costa Rica is known for its biodiversity. EQRoy/Shutterstock

As a result, Costa Rica is the happiest and most sustainable country on Earth, according to the Happy Planet Index (HPI).

This index, which has been published four times since 2006, takes the wellbeing and longevity of a population; measures how equally both are distributed; then sets the result against each country's ecological footprint. And Costa Rica has topped the poll three times out of four.

It is not just the HPI. A recent Gallup poll found Costa Rica to be one of the happiest countries in the world. It also has some of the oldest people, with life expectancy of 78.5 years, longer than in the US.

Read more: Costa Rica went 76 days without fossil fuels, but that's not the only reason it's the future of the planet

Professor Mariano Rojas, a Costa Rican economist at the Latin American Faculty of Social Sciences, attributes Costa Ricans' high wellbeing to a culture of forming solid social networks of friends, families, and neighborhoods.

The reason Costa Rica tops the HPI time and again, however, is that it delivers all this while using a quarter of the resources typically used in the Western world.

There are, of course, flaws in the HPI's calculations, not least that it fails to account for the murder rate in the countries that it ranks.

In Costa Rica, that rate hit 12.1 murders per 100,000 inhabitants in 2017, more than double the world average of 5.3.

A sunset in Costa Rica. Flickr/kansasphoto

President Alvarado said the murder rate was very high across Latin America. "The main thing insecurity is connected to is inequality. Latin America is one of the most unequal regions in the world."

He said murders in Costa Rica take place in "very specific areas where what is required is a policy of opportunities.

"This has been done successfully in a number of countries, by creation of leisure options, prevention of drugs, new opportunities for the youth, for women, the creation of new jobs; and that is very hopeful."

Costa Rica recently pushed through a program of tax reforms, which President Alvarado said has freed up the money to spend on social programs.

"If you bring in these reforms and sort out your problems of liquidity, it means we didn't have to cut any of our social programs. It also meant that there was stable funding of public services. And there is a stability, which is what we need to relaunch our economy."