A new study of nearly 20,000 middle schoolers has found that kids who attend schools that sell junk food such as soda and doughnuts do not gain more weight than students who attend schools where that type of food isn't available.

The study, published in this month's issue of Sociology of Education, contradicts earlier research with smaller sample sizes that showed the availability of junk food correlated with rates of childhood obesity. The new study's author, Pennsylvania State Professor Jennifer Hook, said in a statement that the results surprised her. Hook hypothesizes that kids don't actually have that much time to eat at school, so their out-of-school eating habits are a more important factor in determining their weight. "Children's environments at home and in their communities may provide so many opportunities to eat unhealthy foods that competitive food sales in schools have little influence on children's weight," she writes. Eating habits are set very early, so efforts to encourage healthy food choices should start before middle school, Hook adds.

The study found that most middle schools sell junk food, and schools with a high percentage of poor children were more likely to have junk food for sale than schools without a large disadvantaged population. Five years ago, the American Beverage Association said it would stop selling sugary sodas in public schools in response to growing public concern over childhood obesity. In states like California that have cracked down on junk food in schools, vending machines now offer fresh fruit and water, the Chicago Tribune reported. This study calls into question the effectiveness of such changes, Hook writes.

The study did not evaluate the healthiness of government-subsidized school lunches or breakfasts, which may soon face new, stricter standards mandating more servings of vegetables. Nearly 20 percent of American children age 6 to 11 are obese and the share of overweight and obese children has quadrupled in only 25 years, according to the National Center for Health Statistics.