The U.S. economy grew at a rate of 2.6% in the third quarter, but there are still concerns that a recession could be coming next year. Experts don't expect this type of growth will be sustainable, especially with inflation continuing to be problematic. 

But even if you invested as the country entered a recession, that could still prove to be a good move in the long run. Below, I'll look at how much you would have made if you had invested $10,000 in the stock market at the start of the Great Recession and held on until today.

Don't focus on economic forecasts

Investing based on economic forecasts can be risky since, as the COVID-19 pandemic has taught everyone, the world can be incredibly unpredictable.

Billionaire investor Warren Buffett doesn't value forecasts in general, saying, "Forecasts may tell you a great deal about the forecaster; they tell you nothing about the future." Peter Lynch also believes that "nobody can predict interest rates, the future direction of the economy, or the stock market. Dismiss all such forecasts and concentrate on what's actually happening to the companies in which you've invested."

The lesson for investors is that the focus should remain on the actual business you're investing in rather than the economy as a whole. After all, strong businesses today that are in good financial shape should be able to get through tough times, including recessions. While a downturn could lead to underwhelming returns, that won't last forever. And by trying to time the market, you may end up missing the rally.

Astonishing gains since the Great Recession

If you had invested $10,000 into the S&P 500 index in December 2007 when the Great Recession was just beginning, your investment would be worth more than $26,000 today -- a rise of 161%. Over a span of 15 years, that averages out to a compound annual growth rate (CAGR) of 6.6%. If you were to include dividends and assume that they get reinvested along the way, then your total returns would be an even more impressive 254%. That means your investment would now be worth over $35,000, with the CAGR rising to 8.8%. And this factors in the current bear market today.

What's notable is that the S&P 500's total returns are underwhelming when compared to how the healthcare and tech sectors have performed over that time. Even if you had invested in individual healthcare stocks such as Johnson & Johnson or Bristol Myers Squibb, two stalwarts in the industry, your returns would be better than the market:

^SPX Chart.

^SPX data by YCharts.

The gray bars in the chart also note the brief recession in 2020, but by and large, the economy has been strong since the Great Recession. And while tech stocks have surged of late, up until 2020 and before meme stocks took off, their returns were broadly in line with healthcare.

The winning formula: buy and hold

The key takeaway is that by investing in top companies with solid fundamentals, you can not only earn a good return in the long run, but you can potentially outperform the market as well.

Bristol Myers and Johnson & Johnson are among the largest healthcare companies on the stock market. They make pharmaceutical products that help people all over the world. Their businesses are profitable, they generate free cash flow, and they pay dividends that today yield more than 2%. 

These are the types of stocks that can set investors up for long-term gains, regardless of the economic outlook. As long as you don't need to pull money out of the stock market for personal reasons, you're better off investing in the markets and hanging on because as bad as things may look right now, the economy will eventually rally and come out stronger afterward.

And with valuations down this year, now may be an opportune time to load up on some solid stocks for the long run.