The S&P 500 is down 24% this year, and the stock market hasn't been a great place to be holding your money of late. Investors have been dumping stocks left and right, with many quality companies seeing their valuations plummet as interest rate increases and rising inflation have made people second-guess their investments.

But before you follow suit and decide to dump all of your stocks and hold cash or pivot to bonds, you should consider Warren Buffett's advice, and why getting out of the stock market right now could be a costly mistake.

Buffett believes it's always favorable to remain invested

Warren Buffett isn't a fan of economic projections, or what he refers to as "dancing" in and out of stocks based solely on economic outlooks. And in a Berkshire Hathaway shareholder meeting in 2015, he said that "we think any company that has an economist has one employee too many."

Buffett is an investor who has remained invested for decades, all the while experiencing the effects of inflation, recessions, wars, and no shortage of crashes along the way. He believes that "the risks of being out of the game are huge compared to the risks of being in it." And the game he's referring to -- investing -- is favorable in the long run. Another popular investor, Peter Lynch, agrees with that notion, saying that "people who exit the stock market to avoid a decline are odds-on favorites to miss the next rally."

Given that the stock market has always recovered from every decline, history should serve as an important reminder to investors that there's always light at the end of the tunnel. 

Investors should focus on fundamentals rather than forecasts

The key takeaway for investors is to invest in businesses that will do well in the long run, and to not worry about economic projections or what the experts think will happen. There are too many variables to factor in regarding where the economy may go, and the simpler option is to focus on a business itself.

One example of a company that could make for a great long-term investment is drugmaker AbbVie (ABBV 1.26%), which has solid financials and a path to more growth. Revenue of $56.2 billion last year was 72% higher than the $32.8 billion the company generated in 2018. Profits during that time doubled to $11.5 billion. And over the trailing 12 months, the company has generated free cash flow of more than $22 billion.

AbbVie's acquisition of Botox-maker Allergan a few years ago has diversified its business; Botox cosmetic sales rose 19% in its most recent quarter (ended June 30). Its high-growth products Skyrizi and Rinvoq both generated sales growth in excess of 50% during the quarter and should make up for declines in revenue from top-selling drug Humira, which begins losing exclusivity as early as next year.

Combined with its high-yielding dividend that pays 4.2%, AbbVie is the type of stock that you might expect to perform well in the long run, regardless of the economic situation. Its financials are strong, and the business is well-diversified.

Another stock with strong fundamentals to consider is Adobe (ADBE 0.11%). The tech company sells popular software products, including photo-editing program Adobe Photoshop, on a recurring subscription basis. Its products are top of the line and essential to many professionals involved in web design and photography.

However, the stock recently nosedived after announcing lackluster earnings numbers where sales rose by 13% to $4.4 billion. That's modest growth for a company that earlier this year commanded a hefty price-to-earnings multiple of more than 50 (now it's down to less than 30). Last month, it also announced a seemingly expensive $20 billion acquisition of Figma, a company that focuses on creating web applications for collaborating on web design projects.

With Adobe's stock now near 52-week lows, it could present an attractive buying opportunity for investors. The company may have carved out a new growth avenue for its business, focusing more on collaboration -- while also becoming a cheaper investment. Adobe has generated more than $7 billion in free cash flow over the trailing 12 months, and it is in a solid position to pursue more opportunities as they come up. In the long run, this can be another great stock to buy and hold.

Buying and holding could pay off, now more than ever

AbbVie and Adobe are just two examples of promising growth stocks to own for the long haul, but there are many other options out there that investors can load up on today. While there could still be declines in the months ahead for stocks, there's also the possibility of an eventual rally that could make holding on to your investments a great decision.

As long as you don't need to take the money out, keeping it invested in stocks with strong fundamentals could be a move you thank yourself for later on.