An estimated 11.2% of Americans changed residences last year. Some of these left their homes for a new city, or suburb, looking for a better job and quality of life. If they moved to one of several counties, they likely have found themselves surrounded by people living rich, healthy lives, relatively free from financial struggle.

To determine the best counties to live in, 24/7 Wall St. developed an index based on three social measures — educational attainment, poverty rate, and life expectancy — and ranked counties based on their well-being.

21. Middlesex County, Massachusetts

> 5-yr. population change: +5.2%
> Nov. unemployment rate: 2.1%
> Poverty rate: 8.3%
> Life expectancy at birth: 82.1 years

Middlesex County, situated in eastern Massachusetts largely to the north and east of Boston, is the only New England county to rank among the best places to live. The Boston metro area has a high concentration of colleges and universities, and partially as a result, Middlesex County is one of the best educated areas in the country. Over half of all county adults have at least a bachelor’s degree, well above the 29.8% national college attainment rate.

Many high paying jobs require a college education, and in Middlesex County, higher educations appear to be paying off. The typical Middlesex household earns $85,118 a year, well above the $53,889 national median income.

All but a few of the healthiest, best educated, and most financially-secure U.S. counties are located within a major metropolitan area. Of the counties on this list, three are located within commuting distance of downtown San Francisco, another three are within commuting distance of New York City, and eight are within commuting distance of Washington D.C.

Major cities such as these offer a wide range of jobs, including many that are especially high paying. In every county on this list, the median annual household income is at least $17,000 higher than the $53,889 national median income. In many cases, the typical county household earns more than $100,000.

In the counties in and around the D.C. metro area, many of the high-paying companies are government contractors. Defense contractors such as Lockheed Martin, General Dynamics, and Northrop Grumman are headquartered around the nation’s capital and receive billions of dollars in government contracts annually.

In the New York metro area, high-paying jobs in the city’s finance sector likely contributed to high incomes in some of the area’s counties. On the other side of the country, many counties on this list are located in and around San Francisco and Silicon Valley. Major, high paying, employers in the area include tech giants Apple, Facebook, and Google.

People living in these counties are not just more likely than those in other parts of the country to find high-paying work, but are also more likely to have a job in general. The unemployment rate in all but three of the 25 counties on this list is more than a percentage point below the U.S. rate of 4.6%.

The high employment rate may help explain another positive aspect in these counties, high health insurance coverage. Nationwide, 87% of Americans have health insurance coverage. All but three counties on this list have a higher health insurance coverage rate. In five of the counties on this list, the coverage rate is 95% or more.

Such high health insurance coverage can help explain the long life expectancy in these counties. People with health insurance coverage are more likely to get life-saving treatment when they need it and are also more likely to receive regular preventive care that can prolong life.

Not surprisingly, many of these healthy, educated, and economically vibrant counties are growing rapidly. The populations of only two counties on this list have decreased in size in the last half decade, and 20 have grown faster than the 4.1% national population growth rate. Loudoun County, Virginia’s population ballooned by 20%, about five times faster than the national population growth rate.

To identify the best counties in which to live, 24/7 Wall St. created an index composed of three socioeconomic measures — the poverty rate, the percentage of adults who have at least a bachelor’s degree, and life expectancy at birth — and ranked counties based on the index. The selection of these three measures was inspired by the United Nations’ Human Development Index. Poverty, insurance, and bachelor attainment rates came from the U.S. Census Bureau’s 2015 American Community Survey. Population data also came from the ACS. Life expectancies at birth are from the Institute for Health Metrics and Evaluation, a health research center affiliated with the University of Washington, and are for 2013. Unemployment rates are from the Bureau of Labor Statistics and are for November 2016. Independent cities in Virginia are treated as counties by the U.S. Census Bureau and were included on this list for that reason.

Click here to see the best counties to live in.

Click here to see the worst counties to live in.