Two-years ago, the question, "Walgreen (NASDAQ:WBA) or Rite Aid (NYSE:RAD)" would've sounded foolish. Walgreen was considered the best running pharmacy in America while Rite Aid was about two quarters shy of bankruptcy. But today, a lot has changed, and as we look ahead, this is a serious question that investors must ponder.

Why even ask?
Essentially, pharmacy stocks are a hot ticket. The industry as a whole has produced significantly larger gains than the S&P 500 while Rite Aid has been one of the best performing stocks in the market since the fourth quarter of 2012.

The most noticeable change within the sector has been profits: Rite Aid's operating income has seen a $530 million swing in the last two years, while Walgreen has also seen its margins rise. The reason is because of $130 billion in brand drugs losing patent protection between 2011 and 2016 .

As a result, pharmacies buy cheaper generics in bulk while saving on logistical costs which then allows for higher markups and profits. Therefore, pharmacies, which have historically produced tiny margins, have had more money to spend on wellness programs, store renovations, and marketing, thus driving growth.

With that said, investors realize that there is still two years left in the patent cliff, and with many billions of blockbuster drug dollars set to lose patent protection, pharmacies will likely continue to benefit, which in turn means larger gains.

The best versus the recovery
In terms of operating efficiency, nothing comes close to Walgreen within this space. This is a company that has made all the right investments with an industry-best 13.8% return on equity and a profit margin of 3.7%.

In comparison, Rite Aid is still a recovery story, as its margins trail, and up until the last six months, growth had been non-existent, with the only investment upside being margin improvement. Essentially, Rite Aid soared because investors realized bankruptcy was not going to occur. Hence, Rite Aid's valuation had to be adjusted. Therefore, we are talking about two completely different companies.

2 investment degrees
With all things considered, in viewing Walgreen versus Rite Aid as investments, there are two different degrees of upside.

Walgreen trades at 24 times earnings, which is much higher than the S&P 500's P/E ratio of 18.8 . However, Walgreen is worth the premium, as its expected revenue growth of 5% this year is about double the rate of growth in the overall retail space .

Furthermore, the fact that more new generic drugs will enter the market means that Walgreen's margins will likely rise, therefore translating into higher profits. Essentially, this all means that Walgreen should perform with the broader market, or possibly even outperform it by a marginal degree due to its fundamental performance.

Rite Aid on the other hand, has much more to gain if it keeps improving at its current rate. While its P/E ratio of 32 appears high, it's important to realize that its profit margin of one percent is nearly one-fourth of Walgreen. Hence, as generics are introduced, the company implements more organic and better selling products to its front-end, and technology becomes a bigger part of its day-to-day operations, Rite Aid's margins should continue to rise, and gain ground on its industry peers.

With that said, it's worth noting that Rite Aid's margins have improved at a substantially faster rate than any of its peers, and at 1%, Rite Aid has the most room to improve. Furthermore, growing comparable-store sales also drives margins higher, and for 2014, revenue is expected to increase nearly 3 %, representing Rite Aid's first year of sizable growth in more than six years.

Therefore, Rite Aid becomes an investment that should keep trading higher, and outperforming the broader market, so long as it continues to see improvements. Thus, with all signs pointing up, Rite Aid is a better investment from this point forward than Walgreen.

Final Thoughts
Here's something to consider: If Rite Aid were operating with Walgreen's profit margin it would trade at less than nine times earnings. In addition, if it traded with the same price/sales multiple as Walgreen, Rite Aid would trade at $22.8 a share.

Granted, Walgreen has earned its premium valuation, through years of superb performance. But, as Rite Aid continues to exceed our expectations, and gives every indication that it's becoming a true competitor, the question to ask yourself is whether Walgreen is worthy of this high a premium? For most, the answer is no, and it's for this reason that shares of Rite Aid can still soar considerably higher as margins improve and growth is present, meaning its run is far from over.

Brian Nichols owns shares of Rite Aid. The Motley Fool has no position in any of the stocks mentioned. Try any of our Foolish newsletter services free for 30 days. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy.