Educational attainment in each school district in the U.S. Each circle represents one school district. Larger circles represent districts with more students.

We’ve long known of the persistent and troublesome academic gap between white students and their black and Hispanic peers in public schools.

We’ve long understood the primary reason, too: A higher proportion of black and Hispanic children come from poor families. A new analysis of reading and math test score data from across the country confirms just how much socioeconomic conditions matter.

Children in the school districts with the highest concentrations of poverty score an average of more than four grade levels below children in the richest districts. (Reliable estimates were not available for Asian-Americans.)

Even more sobering, the analysis shows that the largest gaps between white children and their minority classmates emerge in some of the wealthiest communities, such as Berkeley, Calif.; Chapel Hill, N.C.; and Evanston, Ill.

The study, by Sean F. Reardon, Demetra Kalogrides and Kenneth Shores of Stanford, also reveals large academic gaps in places like Atlanta, which has a high level of segregation in the public schools.

There are large gaps between white children and their black and Hispanic classmates. The gaps are largest in places with large economic disparities. White students Hispanic Black Chart shows districts with at least 100 white, 100 black and 100 Hispanic students per grade. Reliable estimates are not available for Asian-Americans.

Why racial achievement gaps were so pronounced in affluent school districts is a puzzling question raised by the data. Part of the answer might be that in such communities, students and parents from wealthier families are constantly competing for ever more academic success. As parents hire tutors, enroll their children in robotics classes and push them to solve obscure math problems, those children keep pulling away from those who can’t afford the enrichment.

“Our high-end students who are coming in are scoring off the charts,” said Jeff Nash, executive director of community relations for the Chapel Hill-Carrboro City Schools.

The school system is near the flagship campus of the University of North Carolina, and 30 percent of students in the schools qualify for free and reduced-price lunch, below the national average.

The wealthier students tend to come from families where, “let’s face it, both the parents are Ph.D.s, and that kid, no matter what happens in the school, is pressured from kindergarten to succeed,” Mr. Nash said. “So even though our minority students are outscoring minority students in other districts near us, there is still a bigger gap here because of that.”

By contrast, the communities with narrow achievement gaps tend to be those in which there are very few black or Hispanic children, or places like Detroit or Buffalo, where all students are so poor that minorities and whites perform equally badly on standardized tests.

The data was not uniformly grim. A few poor districts — like Bremen City, Ga. and Union City, N.J. — posted higher-than-average scores. They suggest the possibility that strong schools could help children from low-income families succeed.

“There are some outliers, and trying to figure out what’s making them more successful is worth looking at,” said Mr. Reardon, a professor of education and lead author of the analysis.

The new analysis surveys data from about 200 million standardized math and reading tests given to third through eighth graders in every state between 2009 and 2012. Although different states administer different exams, Mr. Reardon and his team were able to compare the state results with scores on federal tests known as the National Assessment of Educational Progress in order to develop a consistent scale by which to compare districts.

Mr. Reardon said the analysis should not be used to rank districts or schools. Test scores reflect not just the quality of schools or their teachers, but all kinds of other factors in children’s lives, including their home environment; whether they attended a good preschool; traumas they have experienced; and whether their parents read to them at night or hire tutors.

What emerges clearly in the data is the extent to which race and class are inextricably linked, and how that connection is exacerbated in school settings.

Not only are black and Hispanic children more likely to grow up in poor families, but middle-class black and Hispanic children are also much more likely than poor white children to live in neighborhoods and attend schools with high concentrations of poor students.

“If a school is in a neighborhood that is highly segregated serving students of color and under-resourced, that is going to have a devastating impact on those who are experiencing a crisis,” said Thena Robinson Mock, project director of the Ending the Schoolhouse to Jailhouse Track program sponsored by the Advancement Project, a civil rights group. “But the others who may not be suffering that crisis at home are also going to suffer from not having enough resources or high-quality teachers. So it will impact the entire school community if those factors are at play.”

Even in districts where white students and their minority classmates had similar socioeconomic backgrounds, academic gaps persisted. White students Hispanic Black Here, we're showing only districts where black and white students or Hispanic and white students came from similar backgrounds.

In some communities where both blacks and whites or Hispanics and whites came from similar socioeconomic backgrounds, academic gaps persisted. Mr. Reardon said that educators in these schools may subliminally – or consciously in some cases – track white students into gifted courses while assigning black and Hispanic students to less rigorous courses.

Others who examined the data said it raised as many questions as it answered. “This data is giving us a magnifying glass into places that have the same socioeconomic gaps but different achievement patterns,” said Rucker C. Johnson, associate professor of public policy at the University of California, Berkeley. “So we need to use that magnifying glass to figure out what the constellation of other factors” are that affect academics.

In one school district that appears to have beaten the odds, Union City, N.J., students consistently performed about a third of a grade level above the national average on math and reading tests even though the median family income is just $37,000 and only 18 percent of parents have a bachelor’s degree. About 95 percent of the students are Hispanic, and the vast majority of students qualify for free or reduced-price lunches.

Silvia Abbato, the district’s superintendent, said she could not pinpoint any one action that had led to the better scores. She noted that the district uses federal funds to help pay for teachers to obtain graduate certifications as literacy specialists, and it sponsors biweekly parent nights with advice on homework help for children, nutrition and immigration status.

The district regularly revamps the curriculum and uses quick online tests to gauge where students need more help or whether teachers need to modify their approaches.

“It’s not something you can do overnight,” Ms. Abbato said. “We have been taking incremental steps everywhere.”