Nearly a third of Americans who die are in the hospital at the time and their last treatments cost the U.S. economy $20 billion, according to a report released on Wednesday.

The single biggest cause of hospital death was septicemia, an overwhelming infection of the blood, which killed 15 percent of patients, the team at the U.S. Agency for Healthcare Research and Quality found.

Eight percent died of respiratory failure, 6 percent died of stroke and 5 percent had fatal heart attacks in the hospital, according to the report, available at http://www.hcup-us.ahrq.gov/reports/statbriefs/sb82.pdf.

"In 2007, it is estimated by the Centers for Disease Control that 2,423,995 people died in the United States. Of these, we estimate that 765,651 died in the hospital," the agency's Yafu Zhao and William Encinosa wrote.

"That is, 32 percent of all deaths in the U.S. in 2007 occurred in the hospital."

Their analysis, using federal survey data, found that the average cost of a hospital stay that ended with the patient's death was $26,035, compared to $9,447 for patients discharged alive.

Patients covered by Medicare, the federal health insurance plan for the elderly and disabled, accounted for 67 percent of in-hospital deaths and $12 billion in hospital costs.

Private insurance covered 20 percent of patients who died at a cost of $4 billion. Medicaid patients made up 2 percent and uninsured patients accounted for 3 percent and $630 million in costs.

"Overall, the costs of hospitalizations ending in death were $20 billion, which accounted for 5.2 percent of total in-patient hospital costs in the U.S. in 2007," they wrote.

Zhao and Encinosa used their survey data, which covered 90 percent of U.S. hospitals, along with CDC data to calculate that 74 percent of infants who die are being treated in the hospital at the time.

"Among the elderly, 31 percent of deaths occurred in the hospital, while 34 percent of nonelderly deaths took place in the hospital," they said.