Fannie Mae expects a modest recession to begin in the first quarter of 2023, and 60% of the economists polled by Reuters think the U.S. economy will enter a recession sometime next year. Economists surveyed by Bloomberg think there's a 65% risk of a recession over the next 12 months.

All of the experts aren't predicting a recession, but enough are for investors to take notice. Should you buy stocks if a recession is coming in 2023? Here's what history shows.

Two people with a laptop.

Image source: Getty Images.

Looking at past recessions

You probably won't be surprised that stocks usually decline during recessions. Sometimes, they fall especially hard.

For example, during the Great Recession that began in late 2007 and went through mid-2009, the S&P 500 lost more than half its value at one point. By the end of the recession, the major market index was still down more than 30%. (The shading on the charts below reflects when the U.S. economy was in recession.)

^SPX Chart

^SPX data by YCharts.

However, the Great Recession (as its name implies) was especially bad. The first recession of the 21st century is a better one to examine to get a feel for how stocks are more likely to perform.

^SPX Chart

^SPX data by YCharts.

Believe it or not, though, stocks don't always plunge during a recession. In 1980, the S&P 500 even exited a recession in positive territory and never fell more than 9% below the pre-recession level.

^SPX Chart

^SPX data by YCharts.

What matters most

If a recession occurs in 2023, there's a real possibility that your portfolio value will decline if you're invested in stocks. But what matters most is your investment time horizon.

The charts shown above don't tell the full story. If you bought the S&P 500 index before any of the last 10 U.S. recessions and held, you would eventually have positive returns in every case. Sometimes, you'd be in positive territory within only a few months. In other cases, it would have taken several years.

Your investment time horizon should be the most important factor in helping you decide whether or not to buy stocks. If you need the money that you plan to invest over the next five years or so, it's probably better to stay away from stocks.

However, the stock market usually performs relatively well over five-year and 10-year periods. And there has never been a 20-year period where the S&P 500 has delivered a negative return.

Two winning strategies

One winning strategy that long-term investors could use, even if the U.S. economy enters a recession next year, is to dollar-cost average. With this approach, you invest equal amounts at regular intervals over time. The dollar-cost averaging strategy can be used with any asset, including individual stocks and exchange-traded funds (ETFs).

Another good strategy for investing when a recession is on the way is to buy stocks of companies that are practically recession-proof. For example, discount retailers such as Walmart (WMT 0.38%) and Dollar General (DG 0.38%) tend to perform relatively well during economic downturns as customers look for ways to save money.

The stocks of some drugmakers can also deliver positive returns during recessions. Axsome Therapeutics (AXSM 0.96%) stands out as one high-flying stock to buy and hold if a recession is on the way. The biopharmaceutical company has multiple catalysts that could boost its share price further.

Vertex Pharmaceuticals (VRTX 0.37%) is a lower-risk biotech stock to consider, as well. The company is highly profitable, with strong revenue and earnings growth, thanks to its monopoly in treating the underlying cause of cystic fibrosis. Vertex also has a couple of new drugs potentially on the way to approval.