When it comes to living a long life, Hawaii is the place to be. Beyond the beaches, idyllic balmy weather and laid-back vibe, the state also has, it turns out, the most efficient health-care system in the U.S., according to data compiled by Bloomberg.

Hawaiians lived two years longer than the national average of 79 years, benefiting from four decades of employer-paid insurance, generous Medicaid benefits and favorable demographics. Residents of West Virginia, which ranked last, lived three years less than the average, even though per capita health-care spending there was $9,462 compared with $7,299 for Hawaii and expenditures were equivalent to almost a quarter of the state’s gross domestic product — the highest in the U.S.

Bloomberg ranked states based on three weighted metrics scored on a scale of 0 to 100: life expectancy, health-care costs per capita and costs as a percentage of state gross domestic product. The data cover 2014, the most recent available.

Longevity and health aren’t easy to improve in the short term, and Hawaiians have an edge: the state’s 43-year-old Prepaid Health Care Act, which sets minimum standards for employer-provided benefits, including coverage for office visits, maternal care and hospital stays for employees working at least 20 hours a week, according to Hilton Raethel, chief executive officer of advocacy group Healthcare Association of Hawaii. A state fund helps defray costs for small businesses.

Hawaii also has lower Medicaid eligibility requirements than most states and high concentrations of union workers and military personnel with medical plans, so about 95 percent of the population has health-care coverage, Raethel said. In addition, Hawaii has a relatively high concentration of people of Asian and Pacific Islander descent, and “Asians tend to be healthier than many other ethnic groups.” According to newly released Census data, as of 2016, health coverage in Hawaii was 96.5 percent, second only to Massachusetts at 97.5 percent.

Hawaii’s death rate — the age-adjusted share of people dying — was 588.7 for every 100,000 people, the lowest in the U.S. and well below the national average of 724.6. West Virginia was one of four states, all in the “diabetes belt,” with a rate higher than 900.

Mortality patterns, from which death rates are drawn, “vary considerably,” according to the U.S. Centers for Disease Control and Prevention, and can be attributed to such things as differences in risk for specific causes of death.

Almost 43 percent of West Virginia’s adult population had high blood pressure, compared with 30.9 percent nationally, according to CDC data. More than one-quarter were smokers versus 17.5 percent, and 35.6 percent were obese compared with less than 30 percent. The state also had the highest death rate from drug-induced causes.

The five lowest states had a higher percentage of rural residents than states at the top of the list. These residents “tend to be older and sicker than their urban counterparts,” according to a CDC study published in January. They’re more likely to die from heart disease, cancer, unintentional injuries and chronic lower-respiratory disease.

They also typically have less access to health care, and they’re are less likely to wear seat belts, the CDC said.