Doctors gave no good reason for prescribing opioids to patients close to a third of the time during the buildup to the opioid overdose epidemic, researchers reported Monday.

A close check of medical records from 2006 to 2015 showed that a physician gave no explanation at all for writing an opioid prescription in 29 percent of the cases, the team at Harvard Medical School and the Rand Corp. found.

The findings help support criticism by the Centers for Disease Control and Prevention, the Food and Drug Administration and others that say inappropriate prescribing practices have helped drive the opioid crisis, in which 42,000 people died in 2016 alone.

The CDC has been trying to get doctors to prescribe opioids only when absolutely necessary, and to prescribe as low a dose as possible for the shortest time possible.

Nicole Maestas, a professor of health care policy at Harvard, and her colleagues went through tens of thousands of medical records, focusing on more than 31,000 physician surveys that included a prescription for an opioid.

Two-thirds did include a pain diagnosis: usually back pain, arthritis, diabetes or other chronic condition. Five percent were for pain related to cancer.

“No pain diagnosis was recorded at the remaining 28.5 percent,” the team wrote in their report, published in the Annals of Internal Medicine.

Many patients had multiple ailments, so the researchers threw out any surveys that may have simply lacked space to record all the diagnoses. Still, many patients got renewals of opioids for no apparent good reason.

“At visits with no pain diagnosis recorded, the most common diagnoses were hypertension, hyperlipidemia (high cholesterol), opioid dependence and ‘other follow-up examination,' ” the researchers wrote.

The number of opioid prescriptions rose dramatically over the past 20 years, and the CDC says people would do better with other painkillers, or even just ice.

Since there’s been a big national focus on the crisis, prescribing has dropped, but not enough, the CDC says.

At the very least, doctors need to write down why they are giving someone an opioid, the researchers said.

“Whatever the reasons, lack of robust documentation undermines our efforts to understand physician prescribing patterns and curtails our ability to stem overprescribing,” Dr. Tisamarie Sherry, who worked on the study, said in a statement.

Meanwhile, a second study showed that most teens and young adults who have opioid use disorders are not getting the medication they do need.

Drugs such as buprenorphine, naltrexone and methadone can help people fight their addiction to opioids.

But the team at Boston Medical Center found that only 24 percent of youths with an opioid use disorder had a prescription for one of the drugs.

“In this multistate study of addiction treatment and retention in care, we found that three-quarters of youths diagnosed with opioid use disorder received treatment within three months," the team wrote in the Journal of the American Medical Association’s JAMA Pediatrics. "However, most treatment included behavioral health services only, and fewer than one of four youths received timely buprenorphine, naltrexone or methadone treatment."

Many doctors don’t know about the drugs; there’s stigma around their use and it can be hard to get methadone especially, the researchers noted.

People with opioid use disorder are far more likely to drop out of treatment and relapse if they don’t get Food and Drug Administration-approved drug treatment, the researchers noted.