Investing in pharmacy retailers is a relatively safe play these days. Even if states shut most businesses down in an effort to stop the spread of COVID-19, companies like Rite Aid (RAD -51.21%) and Walgreens (WBA -1.18%) will keep operating (at least in some fashion) as they provide consumers with essential day-to-day products and critical prescriptions.

However, that doesn't mean their stocks are equally good buys or one's as safe as the other. Let's take a closer look at both Rite Aid and Walgreens to see which pharmacy chain operator is a better investment today.

Walgreens is coming off of a (rare) loss

Walgreens can usually be counted on to post a profit. Unfortunately, that didn't happen when the Illinois-based pharmacy retailer released its third-quarter results on July 9. The bad news was that a lockdown in the U.K. led to Walgreens' international retail pharmacy sales declining by 31% from the prior-year period. The company also wrote down its Boots UK assets by $2 billion, which caused Walgreens to incur a net loss of $1.7 billion for Q3.

Medical products in a pharmacy.

Image source: Getty Images.

On the bright side, this was a rare blemish for Walgreens, which finished in the black in each of the previous four quarters. The non-cash impairment charge also didn't prevent the company from recording positive free cash flow for the sixth straight period in a row. 

Walgreens' domestic pharmacy retail sales rose by more than 3% this past quarter and total sales of $34.6 billion still came in 0.1% higher than Q3 2019.

COVID-19 is weighing heavily on many companies this year, including Walgreens. However, the headwinds from the pandemic don't make the company a bad investment.

Another good sign is that Walgreens is continuing to find ways to add value and to try and reach more customers who are staying home during the pandemic. On July 16, Walgreens announced it would partner with DoorDash to deliver health and wellness and convenience products to customers in select markets, which could inject a bit more sales growth into its top line.

For Rite Aid, losses are the norm

Rite Aid has been in the red in three of its last four quarters. That's also how the company began the new year: When it released its first-quarter results of fiscal year 2021 on June 25, it posted a net loss of $63.5 million. The good news is that the loss wasn't as deep as it was in the prior-year period when Rite Aid incurred a loss of $99.7 million. Sales of $6 billion during the quarter were up 12% year over year but with a light gross margin of just 20%, there wasn't nearly enough incremental revenue there to help cover the remaining expenses or for Rite Aid to reach breakeven.

Unlike Walgreens, Rite Aid reported negative free cash flow of $240 million for the quarter. What's more troubling is even from its day-to-day operations, Rite Aid wasn't cash flow positive for the second time in the last four quarters. It burned through $200 million in cash to fund its day-to-day activities -- that's up from a cash burn of $65 million during the same period a year ago.

In the earnings release, Rite Aid said it was working to cut more expenses and reduce capital expenditure as it aims to generate positive free cash flow this year.

Which stock is the better buy?

In terms of financial performance, Walgreens is the steadier stock of the two. Not only is it consistently profitable (outside of this past quarter) but it's also generating positive free cash flow, which is crucial to growing the business and not needing to dip into lines of credit or taking on debt. 

But before deciding which stock is the better buy, let's take a look at them in terms of their price-to-sales and price-to-book multiples:

WBA PS Ratio Chart

WBA PS Ratio data by YCharts

Rite Aid's a cheaper stock, but Walgreens is still trading at fairly low multiples to book value and sales. And even if Walgreens is a bit more expensive, that's not enough to offset its stronger bottom line. 

Let's also take a look at how the stocks are performing this year against the S&P 500:

WBA Chart

WBA data by YCharts

Judging by this picture you'd likely believe investors are more bullish on Rite Aid. But the truth of the matter is Rite Aid's been beaten up over the years. Here's what the five-year returns of the two stocks look like:

WBA Chart

WBA data by YCharts

Admittedly, neither healthcare stock looks terribly appealing, but it helps put Rite Aid's recent ascension into context.

With troubled financials, a lower multiple just isn't enough of a reason to pick Rite Aid over Walgreens. And another great reason that clinches Walgreens as the better buy: The Dividend Aristocrat pays a dividend that yields 4.6% (the S&P 500 average is a modest 2%) and it's increased its payouts for 45 years in a row. Rite Aid currently doesn't offer a dividend to its shareholders.

With a better dividend and more sound financials, Walgreens is hands-down the better pick here. Regardless of whether Rite Aid performs better in the short term, Walgreens is the stock long-term investors should go with.