Things have been difficult for companies across sectors this year. But economic woes have hit retailers particularly hard. That's because higher inflation weighs on their costs such as transport and logistics -- and it weighs on their customers' wallets.

As a result, these companies' stock prices have suffered too. The SPDR S&P Retail ETF has dropped 36% this year. That's compared to a 23% decline for the S&P 500 Index. With this in mind, should you really invest in retail stocks right now? Is it too soon to get back into this hard-hit industry? Let's find out.

A big problem for retailers

As mentioned above, rising inflation is a big problem for retailers. E-commerce giant Amazon (AMZN 1.49%), for instance, said international container shipping costs more than doubled from pre-coronavirus days to early this year. Companies are paying more to ship and store their goods. And that's hurting gross margin.

The inflation problem also means consumers might hold off on buying non-essential goods or even switch to cheaper brands. Here, not only retailers suffer -- but related players such as consumer goods companies. An example is Procter & Gamble (PG 1.52%). The company's well-known brands like Bounty paper towels and Pampers diapers may lose out to cheaper brands during these tough times.

But it's important to remember that today's challenges won't last forever. Times of economic slowdowns and even recessions are followed by growth. Just as bear markets eventually lead to bull markets.

So, even though things might look gloomy for retailers -- and some consumer goods players -- right now, the conditions are temporary. At the same time, some of these otherwise solid companies have seen their valuations plummet. This opens up the door of opportunity for long-term investors.

But, wait a minute, you might say. What if these stocks -- and their valuations -- drop further? After all, today's economic troubles won't disappear overnight. It's possible rising inflation and economic weakness may continue for a while.

Timing the market?

That's true. Some retailers may continue to report pressure on margins. And stock declines may not be over. But here's the thing: It's impossible to time the market and buy a stock at its very lowest level. So, instead of wasting time trying, it's best to buy a stock when valuation looks reasonable considering the company's track record and future prospects.

This means that today is a great moment to buy retail stocks. But, at the same time, it's important to avoid tossing all retailers into the same basket.

Company A may be struggling today -- and recovery may be difficult or even impossible. Company B may have it difficult right now, but future prospects still look promising. And, finally, Company C continues to grow in spite of today's tough times. In each case, share prices may have tumbled. But while you'll want to avoid Company A, you may want to pick up shares of Company B and Company C.

For example, Amazon and Home Depot (HD 0.22%) have each lost more than 30% so far this year. Amazon's struggles with inflation and supply chain issues have hurt earnings. Home Depot, however, recently reported record quarterly earnings.

Both stocks are great buys today, though. Amazon is trading around its lowest in relation to sales in about five years. Home Depot is trading for about 16 times forward earnings estimates. That's compared to 25 earlier this year. Most importantly, both companies have a strong track record, solid customer base, and great future prospects.

Two key words

And finally, it's key to keep these two words in mind every time you buy a retail stock and every time you look at your portfolio: long term.

Even if you buy a stock today and it declines tomorrow, that's OK. What is important is the stock's performance over a period of at least five years. If you keep this in mind, it's easier to remain calm during times of stock market turmoil. And instead of fleeing the market, you'll see it as a place of opportunity.

So yes, today, you really should pick up certain retail stocks. And this move could set you off on the path toward long-term investing success.