The nation’s 9-year-olds and 13-year-olds are posting better scores in math and reading tests than their counterparts did 40 years ago, and the achievement gap between white students and those of color still persists but is narrowing, according to new federal government data released Thursday.

The scores, collected regularly since the 1970s from federal tests administered to public and private school students age 9, 13, and 17, paint a picture of steady student achievement that contradicts the popular notion that U.S. educational progress has stalled.

“When you break out the data over the long term and ask who is improving, the answer is . . . everyone,” said Kati Haycock, president of the Education Trust, a nonprofit organization that works to close the achievement gap between poor and privileged children. “And the good news, given where they started, is that black and Latino children have racked up some of the biggest gains of all.”

The data, part of the National Assessment of Educational Progress long-term trend study, come from tests given every four years in math and reading. The most recent results, from tests 50,000 students took in 2012, show that 9-year-olds and 13-year-olds did better in both math and reading than students who took the first reading test in 1971 and the first math test in 1973.

Although the younger test-takers made significant progress, test scores of 17-year-olds remained relatively flat. But the 17-year-olds who struggle the most — those in the bottom percentiles — did show gains in 2012 compared with 40 years ago.

The trend lines of progress over the decades show ups and downs. But for 9-year-olds and 13-year-olds in math and reading, and 17-year-olds in reading, there has been an uptick in test scores since 2004, when No Child Left Behind, the main federal K-12 education law, began taking effect.

No Child Left Behind required school systems to publicly report test scores for the first time, including information about how minorities, English-language learners and special-education students were performing. Observers say that transparency laid bare racial disparities and put pressure on school districts to help their weakest performers.

The law also set aggressive goals for academic growth and spelled out consequences for schools that failed to meet them. In recent years, school districts and states have complained that those goals were unrealistic, and the Obama administration has issued waivers to most states and the District of Columbia to free them from the most onerous requirements of the law. Efforts in Congress to update the law have stalled, with Democrats arguing the federal government must continue its oversight of public education and Republicans saying the federal role should shrink.

Data released Thursday show that blacks and Hispanics made more significant progress than white students in their scores since the 1970s, narrowing the achievement gap.

On the reading tests that are scored on a scale of zero to 500, the gap between 9-year-old whites and blacks was nearly halved, from 44 points in 1971 to 24 points in 2012. The gap on the same test between Hispanics and whites shrank from 34 points to 21 points.

Blacks and Hispanics at all age levels made similar gains in math and reading. Only the white-Hispanic gap among 9-year-olds in math has not changed since the 1970s.

In addition to narrowing the gap with white students, blacks and Hispanics performed better in 2012 in reading and math when compared with the same racial groups in the 1970s.

On a scale of zero to 500, 9-year-old black students in 2012 scored an average 36 points higher than their counterparts in the 1970s in reading and math, while 13-year-olds scored an average 24 points higher in reading and 36 points higher in math.

Meanwhile, 9-year-old Hispanic students scored an average of 25 points higher in reading and 32 points higher in math than Hispanics in the 1970s. And 17-year-old Hispanics scored 21 points higher in reading and 17 points higher in math in 2012, compared with scores from 40 years ago.

“Black and Hispanic students made larger gains than white students across all these age groups,” Peggy Carr, associate commissioner at the National Center for Education Statistics, told reporters in a telephone call Wednesday.

Still, stubborn differences between racial groups remain, Haycock said.

“If we have a crisis in American education, it is this: that we aren’t yet moving fast enough to educate the ‘minorities’ who will soon comprise a ‘new majority’ of our children nearly as well as we educate the old majority,” she said. “At best, students of color are just now performing at the level of white students a generation ago.”

The data released Thursday also show the gender gap getting slimmer in math and reading. In the 1970s, boys scored higher than girls in math, while girls outperformed boys in reading. By 2012, the gap in math had been erased for girls and boys at ages 9 and 13, and it was narrowed to just four points among 17 year-olds. In reading, 9-year-old boys shrank the gap with girls from 13 points to five points. But the gender gap in reading did not budge for 13-year-olds and 17-year-olds.

At all ages, students who said they regularly read for fun outside of school scored higher than those who reported reading for fun a few times a year or less.

The data also document significant changes in the makeup of the student population over the past four decades.

In 1978, the 13-year-old test takers were 80 percent white, 13 percent black, 6 percent Hispanic, and 1 percent Asian/Pacific Islander. By 2012, the proportion of white students shrank to 56 percent, blacks modestly grew to 15 percent, Hispanics jumped to 21 percent and Asians/Pacific Islanders grew to 6 percent.

The report noted that the percentage of 13-year-olds taking algebra has doubled, to 34 percent, since 1986, when the government first began asking that question. And the percentage of 17-year-olds taking either pre-calculus or calculus more than tripled from 1978 to 2012. In both cases, students who were taking more rigorous math such as algebra or calculus scored higher on the math tests.

Another significant change is that an increasing number of students of a given age are enrolled in a lower grade than they were in the 1970s. For example, in 1978, 72 percent of 13-year-olds were in eighth grade and the rest were in seventh grade or lower. By 2012, just 60 percent of 13-year-olds were in eighth grade, with the rest enrolled in lower grades.

Jack Buckley, commissioner of the National Center for Education Statistics, said it was unclear why so many students are enrolled in lower grades than their counterparts were 40 years ago.

But he suggested that changes in state policies regarding the age for kindergarten enrollment and mandatory grade retention could be factors. And an increasing number of parents are intentionally delaying the start of school for children — a practice known as “redshirting” — because they believe it will give their children an advantage over others.