The cost of healthcare for people enrolled in Medicaid under the Obamacare expansion has been rising steadily over time, according to an analysis by consulting firm Avalere Health.

The findings show that average monthly costs for people who enrolled under Obamacare's Medicaid expansion, which comes at little or no expense to them, rose by an average of 20 percent, from $324 in 2014 to $389 after two and a half years of being enrolled.

The analysis found that healthier enrollees tended to leave the program over time, perhaps because they dropped out or took on a new job where they earned more and no longer qualified for the program. Those who stayed were more likely to have chronic medical needs.

“Contrary to some expectations that Medicaid expansion enrollees would be relatively healthy, beneficiaries who have remained on the program have increasing healthcare needs, likely due to previously unidentified or untreated conditions,” Caroline Pearson, senior vice president at Avalere, said in a statement. “Healthier, lower-cost enrollees may be more likely to churn off Medicaid after a shorter period of time.”

Obamacare was originally written to require all states expand Medicaid to people who were making less than roughly $16,000 a year. Prior to that, states varied in who they covered, but the program typically was extended only to children, people with disabilities and pregnant women. A Supreme Court decision made the Medicaid provision in Obamacare optional for states, leaving 18 without expansion, and Maine, which is in the process of doing so.

States that expanded the program have seen the highest reductions in uninsurance rates. The federal government paid for the first couple of years of expansion, but the states took on 5 percent of costs beginning in 2017 and that share will gradually expand to 10 percent of costs by 2020. In some states, this means an increase in spending of billions of dollars.

Avalere's analysis also looked at where the Medicaid dollars went. Researchers found that the share of spending for inpatient hospital care and emergency department visits decreased over time, especially during the first few months of coverage. Over time, however, spending on chronic care services, like medicines, increased.

The researchers hypothesized that people in the program had a lot of pent-up medical needs when they first enrolled in the program, because many of them were probably uninsured beforehand. Another option, the researchers say, is that when people went to emergency rooms or other hospital visits they were enrolled in Medicaid at that time.

As certain Medicaid enrollees spent more time with coverage and met with doctors, they were able to receive the treatment they needed for ongoing medical issues and were more likely to shift to doctor visits and prescriptions. The results show that prescription drug costs almost doubled after two and a half years. The numbers exclude medications to treat hepatitis C, some of which hold a list price of $100,000 for a round of treatment.

“As new Medicaid beneficiaries gain a consistent and sustained source of insurance coverage, their spending patterns reflect improved care for chronic conditions and less need for acute hospitalizations,” Michael Lutz, vice president at Avalere, said in a statement. “This suggests that newly insured populations have underlying health needs but insurance coverage may help rationalize their healthcare spending in favor of longer-term, less costly treatments overall.”

The analysis was funded by Anthem Public Policy Institute and data were collected using information from three Medicaid managed care organizations, representing nine different states.