Riverside and San Bernardino counties are the fifth-worst places to raise a family, according to a study measuring the odds of achieving economic success and good health.

The Inland Empire ranked fifth-lowest among the top 100 metropolitan areas tracked by the Child Opportunity Index, prepared by Brandeis University in Massachusetts. The region was ahead of Bakersfield, the worst, then Fresno; McAllen, Texas, and Stockton. Los Angeles/Orange County was 16th worst, tied with Las Vegas and Youngstown, Ohio.

Tops for kids was Madison, Wis., then the San Jose-Sunnyvale-Santa Clara metro area. The San Francisco-Hayward-Oakland area ranked ninth highest.

To define childhood opportunity, the study evaluated a host of factors, including neighborhood poverty, employment, housing vacancy rates, air quality and access to high-skill jobs, healthy food, schools and parks.

Bakersfield scored the worst place in the nation for child opportunity, with more than 20% of families living in poverty; 12% of workers commuting at least two hours each day and nearly a quarter of public school teachers with less than three years of professional experience, according to the study.

Life expectancy in very low-opportunity neighborhoods in Bakersfield, the study found, is 6.2 years less than in very high-opportunity neighborhoods.

“California is fascinating because there is such inequity within the state,” says Dolores Acevedo-Garcia, director of Brandeis’ Institute for Child, Youth and Family Policy and co-author of the report. “It is remarkable that you have literally one of the best — San Jose — and the worst within the same state.”

Are you a real estate fan? Then sign up for The Home Stretch newsletter and its Bubble Watch edition A twice-a-week review of what’s important for housing around the region! Subscribe here!

In San Jose, for example, 15% of children live in what the study saw as very low-opportunity areas compared with 52% in very high-opportunity areas. Inland Empire? 39% in very low-opportunity areas vs. 2% in very high-opportunity neighborhoods. L.A.-O.C.? 25% in low opportunity communities vs. 17% in high ones.

“On average, you would prefer to be a poor child in the Bay Area than a poor child in Los Angeles or the Central Valley,” says Acevedo-Garcia. “Being low-income in San Jose might carry better child outcomes than in Los Angeles.”

Nationally, the study also highlighted stark divisions along racial lines in access to opportunities. About 60% of African-American and Hispanic children in the U.S. are concentrated in low-opportunity or very low-opportunity neighborhoods, the study found, compared to about 20% of white and Asian children.

Erica Hellerstein of the (San Jose) Mercury News contributed to this report.