"It gives them an opportunity to expand geographically," said Vishnu Lekraj, an analyst with Morningstar who follows Walgreens. "They get to move into areas like upstate New York where they don't have or have a minimal presence."

Walgreens Boots Alliance, the chain's parent firm, said Tuesday it had reached an agreement to buy Rite Aid for a total of about $17.2 billion, including acquired net debt.

Walgreens currently has some 8,200 pharmacies across the country, while Rite Aid has about half that number.

While Walgreens has the most stores of any pharmacy chain, Lekraj said, CVS is a bigger company thanks to its mail order business in addition to its stores.

Walgreens has $76 billion in sales, compared to $26 billion for Rite Aid.

CVS, with $139 billion in sales, will remain the nation's largest pharmacy chain.

In a written opinion on the merger, Lekraj said, Walgreens is struggling and reported a tough fiscal fourth quarter with steep declines in profit offsetting revenue growth from prior acquisitions. He described Rite Aid's underperformance as "massive" in recent years but said the combined firm could benefit from centralized corporate operations, store closures, and supply chain enhancements.

The merger could give the combined firm some additional ability to negotiate prices with insurance companies and pharmacy benefit managers, he said.

Pharmacies feel pressure to consolidate as the rest of the health industry does, and bigger drug suppliers and insurance companies flex their muscle at the negotiating table, according to David Kile, who teaches pharmacy administration at the Albany College of Pharmacy and Health Sciences.

Albany-based CDPHP, for instance, last year reduced its pharmacy network for Medicaid members in an effort to negotiate lower prices. That lets the health insurer promise higher volume to the drug stores that remain in network, in exchange for a lower price-per-prescription, Kile said.

Neither Walgreens nor Rite Aid are part of that smaller network, he noted.

"A lot of times with the large payers, it's a take-it-or-leave-it approach," Kile said.

What the merger could mean to local Rite Aid stores is an open question, especially given that the merger must be approved by federal regulators. It is not expected to take place until the second half of 2016. There are about 38 Rite Aid stores in the Capital Region, while there are about a third as many Walgreens.

"There should be some store closings," Lekraj said, but those will occur in Florida, California, Arizona and other places where the two compete head to head.