We won't officially be in a recession until the National Bureau of Economic Research says so. However, you can nearly throw a rock in any direction and find an economist who thinks a recession is probably on the way.

For example, Johns Hopkins economics professor Steve Hanke stated a month ago that he believes there's at least an 80% chance of a recession. Non-profit research group The Conference Board recently pegged the probability at 96%. The latest Bloomberg economic model projects a 100% chance of a recession by October 2023. 

These forecasts don't guarantee that a recession is coming. But it's possible that the current bear market will continue for a while longer. That doesn't mean that every stock will be a big loser, though. Which stocks are most likely to thrive in a recession? Here's what history shows.

Some bad news

The SPDR Select Sector exchange-traded funds (ETFs) are good proxies for gauging how different sectors perform during recessions. One primary downside of using them is that most of these ETFs have only been around since the late 1990s. However, the U.S. has experienced three recessions during that period, so the SPDR Select Sector ETFs should be able to help in determining which stocks historically thrive in a recession.

I've got some bad news, though. None of the SPDR Select Sector ETFs performed well in all three recessions that occurred over the past 25 years. 

The Consumer Staples Select Sector SPDR Fund (XLP -0.24%) held up well during the recession of 2001. However, it still slid a little. The Materials Select Sector SPDR ETF (XLB 0.85%) performed similarly during the first recession of this century. (The shaded area in the charts below indicates the period when the U.S. economy was in recession.)

XLP Chart

XLP data by YCharts

However, both of these ETFs plunged during the Great Recession that began in late 2007 and went through mid-2009. So did every other sector ETF -- including (perhaps surprisingly) the Utilities Select Sector SPDR Fund (XLU 0.08%)

XLP Chart

XLP data by YCharts

All of the sector ETFs also tanked during the brief coronavirus-fueled recession of 2020. However, the Consumer Staples Select Sector SPDR Fund didn't fall nearly as much as the others did.

Looking for exceptions

The cold, hard truth is that no category of stocks thrives in all recessions. But it's clear from examining the past that consumer staples stocks tend to perform better than most. Your best bet, though, is to look for exceptions. I'm referring to stocks that have factors working to their advantage so much that investors want to buy them even when the overall economy stinks.

Johnson & Johnson (JNJ 0.23%) stood out as this kind of stock during the recession of 2001. The healthcare giant continued to deliver revenue and earnings growth throughout the period. It completed the $10.5 billion acquisition of ALZA Corporation. The blue-chip stock was also viewed as a safe haven for investors worried about the dot-com bubble bursting.

JNJ Chart

JNJ data by YCharts

Walmart (WMT 1.00%) performed exceptionally well during the Great Recession, especially considering how most stocks plunged. Investors realized that the serious economic downturn would mean that consumers would have to tighten their purse strings. That worked to the advantage of the big discount retailer.

WMT Chart

WMT data by YCharts

Moderna's (MRNA 0.17%) share price skyrocketed during the quick recession of 2020. That's not surprising. The company was one of the early leaders in developing coronavirus vaccines. Moderna was a natural choice for investors to flock to during the uncertain times at the beginning of the COVID-19 pandemic.

MRNA Chart

MRNA data by YCharts

Likely outliers in the next recession

Which stocks might be outliers in the next recession, assuming it isn't too far off? I think we can learn from history. 

Walmart could again defy gravity if the U.S. economy enters into a recession. My view is that another discount retailer, Dollar General (DG -3.04%), should do so as well.

Dollar General is outperforming Walmart so far this year. The company continues to build new stores. It's also expanding its frozen and refrigerated goods offerings. Dollar General should benefit as consumers increasingly try to stretch their dollars.

Just as Johnson & Johnson and Moderna performed well during two previous recessions, I suspect another drug stock will do so during the next recession -- Vertex Pharmaceuticals (VRTX 1.04%). Vertex's revenue and earnings will almost certainly grow robustly even amid an economic downturn. 

The big biotech also has a pipeline with multiple potential blockbusters likely on the way. Vertex expects to file for regulatory approvals for one of them (gene-editing therapy exa-cel) before year-end. With fears of a recession increasing, I think that Vertex is arguably the best stock to buy right now.