Updated

Four centuries after William Shakespeare wrote "something's rotten in the state of Denmark" in his play "Hamlet," the small Scandinavian country clearly has gotten its act together.

Danes were excited this week to see their calm and prosperous country thrust into the spotlight of the U.S. presidential race when Democratic hopefuls Bernie Sanders and Hillary Clinton sparred over whether there's something Americans can learn from Denmark's social model.

"It's always nice when Denmark is being shown as an example," said Christine Schwartz, a 42-year-old shopkeeper in Copenhagen. "Often we have been dreaming of living the American way. Now Americans should maybe dream of the Danish way."

Denmark is a nation of 5.6 million people living in an area half the size of South Carolina. It's perhaps best known for Hans Christian Andersen's 19th century fairytales, including "The Ugly Duckling" and "The Little Mermaid." But it's also gained a reputation of being an enchanted country to live in due to high rankings in quality of life surveys.

Denmark ranked No. 3 of 158 countries in the United Nations' 2015 World Happiness Report; the United States was No. 15. Three years ago The Economist ranked it the fifth best place in the world to be born, just after neighboring Norway and Sweden. The U.S. placed 16th.

Danes get free or heavily subsidized health care, education and job training and compensation when they're unemployed, out sick from work or on parental leave.

That, however, comes at a cost that not all Americans might be willing to accept: high taxes.

In Tuesday's debate, Sanders said the U.S. should look to the Scandinavian countries "and learn from what they have accomplished for their working people."

Clinton responded: "We are not Denmark. I love Denmark. We are the United States of America and it's our job to rein in the excesses of capitalism so it doesn't run amok."

For decades economists have studied how Denmark and its Scandinavian neighbors have blended socialism with capitalism, a robust welfare system with a market economy.

Unlike purely socialist societies, they also embrace the free market.

"When you look at the openness of the economy — when you look at capitalism — there is very little difference between the United States and Denmark," says Marian Tupy, policy analyst at the libertarian Cato Institute in Washington.

Denmark is even more open to world trade than the United States, ranking 10th out of 157 countries studied by Canada's Fraser Institute.

Where the two countries differ is in the government's role in the economy.

Danish government spending was equal to 43 percent of the country's economic activity, eighth-highest share in the world, according to World Bank figures from 2012. In the United States, the government's share was 24 percent of economic activity that year, No. 65 of 114 countries.

Heavy spending requires heavy taxation: Denmark's taxes came to 48.6 percent of the country's economic output in 2013, nearly double the United States' 25.4 percent that year and highest in the Organization for Economic Co-operation and Development (OECD) group of wealthy countries.

The average income tax rate for a single person without children is 38.4 percent in Denmark compared with 24.8 percent in the U.S.

"If the U.S. wanted a Danish model, you just need to know that it's a very costly model," said Mads Fuglede, an academic and center-right politician who comments on American politics in Danish media. "And the only way you can pay for it is by taxing the middle class more than the U.S. does at the moment."

Denmark uses taxes and social spending aggressively to narrow the income gap between the rich and the rest. After adjusting incomes for taxes and welfare payments, only three of 31 wealthy countries had smaller income gaps than Denmark in a 2013 study by the Pew Research Center. The U.S. came in 30th, ahead of only Chile.

More than two-thirds of Danish workers belong to labor unions, compared to just 11 percent in the United States, according to the OECD and the U.S. Labor Department.

Powerful unions and a redistributive government don't seem to trouble Danish businesses. Denmark came in No. 4 for ease of doing business in World Bank rankings of 189 countries; the United States was No. 7.

The United States does beat Denmark on several indicators, though.

The U.S. ranks No. 5 and Denmark No. 10 on the U.N.'s human development index, which looks at life expectancy, education and income in 187 countries. Average annual wages were about $49,000 last year in Denmark compared with $57,000 in the U.S., according to the OECD.

Similarly, the U.S. is third and Denmark 13th in the World Economic Forum's global competitiveness rankings.

The Danish unemployment rate is 6.3 percent — low by European standards but higher than the United States' 5.1 percent. And Denmark's economy grew just 1.1 percent last year, less than half U.S. growth of 2.4 percent.

In contrast to the Democratic debate in the U.S., it's highly unusual for Danish politicians to extol the virtues of American society in their election campaigns.

Fuglede said that when he ran for a seat in Parliament this year, he was advised that his role as an expert on American politics could be used against him, and that he should come out as a strong defender of the Scandinavian welfare state.

"From our former communists to the ultra-conservatives, they all support the Danish model," Fuglede said. "The Danish debate is about tinkering with paradise, not 'is this really paradise?'"

___

Ritter reported from Stockholm. AP Business Writer Paul Wiseman in New York contributed to this report.