Last year, most of us felt the bear market blues. That's as the difficult economy and rising inflation weighed on companies -- and their share prices.

This year, the economic situation remains complicated, but investors are more hopeful about the future -- and that's showing in the stock market. All three major indexes have climbed since the start of 2023, and many stocks that spent last year in the doldrums are soaring today. This is especially true of growth stocks. They're the ones that suffered a great deal last year.

Billionaire investor Warren Buffett has a pretty interesting comment about what it's like to be a publicly traded company -- and Tesla chief Elon Musk agrees. Let's take a look at Buffett's analogy and what it means for investing today and into the future.

Swings in share prices

In the past, Musk has commented on swings in share prices, including movement in Tesla shares. Back in May 2020, he even tweeted that Tesla shares had climbed too high. That was after the stock advanced more than 65% in just four months.

As tech stocks Microsoft and Nvidia together added on $192 billion in market value during trading this past Tuesday, Musk tweeted "crazy times," Markets Insider reported. And the news website went on to mention Musk's comment about Warren Buffett:

Warren Buffett's analogy is that being a publicly traded company is like having someone stand at the edge of your home and just randomly yell different prices for your house every day. It's still the same house.

By this, Buffett meant that the actual value of the house -- or company -- hasn't changed. But, due to sentiment alone, people are ready to pay a higher or lower price for it. This happened last year as growth stocks fell.

For example, investors avoided shares of Amazon (AMZN 3.43%). That's as higher inflation increased costs and weighed on earnings. The stock sank nearly 50% last year. But Amazon's long-term outlook remained bright, thanks in part to its leadership in two high-growth markets: e-commerce and cloud computing.

A return to technology stocks

This year, the stock has climbed 60%. That's as investors, feeling more optimistic, return to technology shares and other high-growth players. Yes, Amazon has taken steps to manage today's difficulties -- but it was clear even last year as the stock fell that the company would be able to navigate these rough waters.

So here's what this means for investing: We shouldn't allow ourselves to fall under the influence of short-term market sentiment, whether it's positive or negative. Around the time of the dot-com bubble, Buffett likened what was going on to Cinderella at the ball.

Investors "know that overstaying the festivities -- that is, continuing to speculate in companies that have gigantic valuations relative to the cash they are likely to generate in the future -- will eventually bring on pumpkins and mice. But they nevertheless hate to miss a single minute of what is one helluva party," Buffett wrote in Berkshire Hathaway's 2000 shareholder letter.

Instead of being overly optimistic or pessimistic, it's important to focus on a company's track record and earnings potential. And it's key to only buy a stock when the price is reasonable in relation to possible earnings down the road.

Today, certain stocks may be overvalued. But others that have gained may just be catching up after losses last year -- and still have plenty of room to run. You'll also find stocks that haven't yet rebounded from declines last year. Some are great deals, while others aren't -- even after those declines. All of these situations exist in bear markets and bull markets. It's up to us to identify them and pick and choose stocks with long-term potential.

So, as Buffett and Musk say, don't pay just any price for a stock. Consider what it's truly worth.