Shares of Costco Wholesale (COST 1.01%) are trading close to new highs but sold off recently along with several other retail stocks. In its most recent earnings report, Walmart (WMT -0.08%) said it is more cautious about the holiday quarter than it was three months ago. It noted sluggish sales in the second half of October.

Walmart is seen as a barometer for the health of consumer spending since it is such a large business. Slowing retail sales could be a problem for Costco shares, which trade at a price-to-earnings ratio of 41.6 (compared to the 23.5 P/E ratio for the S&P 500 index). The company's October sales report also showed a slight deceleration in comparable sales over September.

Let's find out more about how Walmart's news might impact Costco, and the stock, in the near term.

Customer traffic is healthier than sales indicate

Costco stock is expensive, but investors have historically paid a big premium to own shares for the company's wide competitive moat built on low prices and recurring revenue from membership fees, which generate most of its operating profit.

Still, Costco has felt the macroeconomic headwinds like everyone else. After reporting a solid 10.6% in adjusted comparable sales (excluding fuel and foreign exchange) in fiscal 2022, comp sales slowed to an increase of 5.2% so far in fiscal 2023, with growth decelerating throughout the year. This echoes Walmart's latest quarterly update, where U.S. comp sales grew just 4.9% in the quarter ended Oct. 27 -- the lowest rate of growth at Walmart this year.

However, there's more to the story. Walmart said that general merchandise prices are coming down, which could attract more shoppers in the near term. This could benefit Costco, too, in driving more customer traffic. So, there's a scenario playing out where sales are under pressure as inflation cools off, but that doesn't necessarily indicate weak consumer spending.

Costco also noted some silver linings in its last earnings report. Within its e-commerce business, management said that sales of big-ticket items had been falling by double-digit rates in previous quarters, but in the fiscal fourth quarter, sales of appliances, specifically, were up over 30% in the quarter, while big-ticket items overall were only down 5%.

Walmart's cautious comments on its earnings call might weigh on retail stocks in the near term, but there are clearly signs that Costco is seeing stabilizing sales trends and could see sales growth improve as demand for big-ticket merchandise picks up again.

Here's why investors should hold Costco stock

Costco's focus on selling a narrow selection of merchandise at low prices has translated to high inventory turnover, which is a key measure of a retailer's inventory efficiency. A higher rate of turnover is one reason Costco can generate profitable sales at a lower gross profit margin than other retail companies.

WMT Inventory Turnover (Quarterly) Chart

Data by YCharts

Costco is a well-managed business, but there are other reasons I would also consider holding the stock. Costco has a long record of paying growing dividends to shareholders, especially an occasionally large special dividend. The last special dividend was for $10 per share in December 2020, so another large payout could be around the corner.

Another reason to hold the stock is e-commerce, which made up just 7% of Costco's business last year. Management noted on the last earnings call that unique visitors to the site were up 40% year over year. Costco Next is proving to be a major advantage, where customers can buy select merchandise at discounted prices directly from Costco's suppliers. The company is steadily expanding the product selection with more brands joining the program.

Costco's high valuation makes it difficult to call it a screaming buy, but it's also difficult to call the stock overvalued. It's incredibly efficient at acquiring and selling merchandise on the cheap, and it's just getting started in using that advantage to win in e-commerce.