There have been widely reported stock market crashes throughout history. While nobody knows when the next one will occur, it will happen at some point.

You needn't fear the next big decline, though. When people get nervous, they tend to sell their stocks indiscriminately. Hence, if you are a long-term stockholder, this also creates a buying opportunity, particularly for strong, enduring companies.

These are good stocks that you can pick up when people are panic-selling.

People shopping in a grocery store

Image source: Getty Images.

1. Dollar General

More than three-quarters of Dollar General's (DG -1.16%) sales come from everyday items like paper towels, trash bags, cereal, milk, and eggs. Charging up to $10 for most of its merchandise, the combination of low prices and basic necessities does particularly well during difficult economic times.

During last year's tumultuous days brought on by the pandemic, Dollar General's same-store sales (comps) rose by 16.3% for the period ended on Jan. 29. Incredibly, this marked 31 consecutive years with a comps increase. The higher sales led to diluted earnings per share growing by 60% to $10.62.

Management expects the comps increase streak to stop this year, forecasting a 3% to 5% decline. But that's only because last year's sales were so strong. And while nobody wishes ill, if the pandemic rears its head again or another unpleasant economic surprise comes our way, people will increasingly shop at Dollar General's stores. Meanwhile, its growth plans, including opening over 1,000 new stores this year, remain intact.

You can also count on dividends to see you through the tough times. Although you can find higher dividend yields than Dollar General's 0.8%, it has increased the payment annually since declaring its first dividend in 2015. This includes this year's decision to raise the quarterly dividend by 17% to $0.42.

2. Kroger

Kroger (KR -0.28%), with over 2,700 locations serving 60 million households, is one of the largest supermarket chains. Many stores have a pharmacy and over half include gas stations. People need food, gas, and medicine no matter what is going on in the world, providing a safe haven for investors.

Its 2020 results bear this out. Excluding gasoline sales, comps rose by 14.1%, and earnings per share grew by 61% to $3.31. Management's looking for a 3% to 5% decline this year, but this comes after a strong year.

A pen pointing to a stock going up among several decliners.

Image source; Getty Images.

Kroger isn't getting lulled into maintaining the status quo, either. Its initiatives include testing drone deliveries. That will allow it to keep up with large competitors like Walmart (WMT 0.66%) and Amazon.

Meanwhile, with its stable business and free cash flow, Kroger consistently raises dividends. Free cash flow was about $4 billion last year, easily covering the $534 million of dividends. It's not just a one-year phenomenon, either. When the board of directors increased the quarterly payment from $0.16 to $0.18 in 2020, it brought its annual streak to 14 years.

3. Walmart

Walmart is the world's largest retailer, serving over 240 million people weekly. It has become dominant by seeking to offer the lowest prices to its customers. Always attractive, that draws a greater crowd during dicier times.

Last year's adjusted revenue grew by 7.7% to $564.2 billion, and adjusted operating income was $23.4 billion, 9.3% higher.

This year, management expects a low-single-digit percentage increase in sales. While investors might not feel excited about the flat to slight increase in operating income, management is investing in the future.

You shouldn't fret, because this will allow Walmart to remain strong. The company is investing in digital initiatives, including supply chain, automation, and customer-facing technology. Previous steps include launching Walmart+, its subscription service, which allows it to remain competitive with online retailers, notably Amazon.

You can also count on Walmart's dividends, which the Dividend Aristocrat has raised for nearly half a century.

Investing in stocks during a free-fall is nerve-racking. But these three companies, with rock-solid businesses that people flock to during stressful economic times due to their low prices and offerings, will provide solace. More than that, it will likely fatten your wallet during potentially lean times.