The stock market is a forward-looking investment vehicle. But economists are struggling to predict what's coming next.

On the one hand, historically high inflation is causing consumers to spend more, resulting in excess savings in the U.S. dropping more than 75% since August 2021, according to the San Francisco Federal Reserve. Moreover, inflation motivated the Federal Reserve to raise interest rates at an unprecedented pace, causing major bank failures and looming refinancing complexities in the commercial real estate market, among other things.

On the other hand, retail sales in the U.S. grew 0.7% in July, according to the U.S. Census Bureau, which continues a streak of better-than-expected sales numbers. Additionally, the unemployment rate sits at 3.5%, which is historically very low and signals that the job market is strong.

Some of the data says the U.S. economy is headed for a recession; therefore, the stock market should head lower. But other data points to the strength of the economy, which could send stocks higher. This is why Wall Street is turning to brick-and-mortar retail giant Walmart (WMT -0.08%) for help in predicting the future.

What can Walmart tell us?

On Aug. 17, during the conference call to discuss financial results for the fiscal second quarter of 2024, Walmart CEO Doug McMillon acknowledged the complexities of the state of the economy, saying, "There are a lot of conflicting data points, but you guys see the same data that we do."

Things for Walmart are good right now, even if the broader economic picture is complex. Q2 revenue was up 5.7% year over year to nearly $162 billion, aided by strong same-store sales growth of 6.4% in the U.S.

However, Walmart isn't seeing sales growth across the board, and that may be significant. Both grocery and pharmacy gained in Q2, whereas general merchandise sales fell. And this suggests that consumers continue to spend on the essentials while cutting back on discretionary purchases.

Financial results from other retailers support this theory. For example, same-store sales for Target (TGT 0.18%) fell overall during its most recent quarter. But the company saw spending growth in its essentials category, while categories like home and apparel declined.

Similarly, Dollar General (DG -0.41%) reported same-store-sales growth of 4.3% in its consumables category during the fiscal first quarter of 2024. But same-store sales for non-consumables dropped by 8.5%. It's as CEO Jeff Owen said: "Customers continue to shift more of their spending away from discretionary goods."

As consumers prioritize non-discretionary purchases, Target and Dollar General have lowered their respective financial outlooks for the remainder of the year. These management teams were more optimistic at the start of 2023 than now. By contrast, Walmart just raised its full-year guidance.

The disparity between Walmart and some of its retail rivals may have to do with product assortment in stores. While Walmart, Target, and Dollar General all sell food items, Walmart has a larger grocery selection. Therefore, it's not seeing the same weakness in consumer spending.

What does this mean for the market?

If I had to use this information to guess what happens next, I would say that consumer discretionary stocks could post disappointing numbers over the next year or so. This could lead to strong sell-offs for these stocks as the bad numbers come in. Not all of them will be stocks to buy. But it's possible that some high-quality businesses could go on sale, and share prices will rise as the economy gets through the worst of the cycle. Therefore, now is a good time to start filling up a watch list.

However, I believe there's a more important takeaway for investors. Looking at Walmart's financial results, I believe it's fair to say that the economy is OK -- not overly good or overly bad. And that's actually quite surprising when you think about it.

In December, 70% of economists polled by Bloomberg said the U.S. economy would enter a recession in 2023. In July, a mere seven months later, less than half of economists believe a recession is coming within the next year.

If that many professional economists can change their opinions this quickly, how much harder is it for people like you and me to predict what the economy is going to do?

This is why it's crucial to take a longer, bigger-picture view than most other investors. It can be hard to nail down the details for the next months or years. But it can be easier to identify long-term trends and look for companies winning in those industries. The economy will ebb and flow, and the market will usually overreact. But holding shares of these companies through market cycles can lead to big stock market gains for those with patience.