Dollar General (DG -2.09%) shares have bucked the overall market in 2022, rising by over 9% even as the S&P 500 is down by more than 16%. It's always nice to see share prices go up when you already own the stock. But in the wake of the broad market sell-off, are there better buying opportunities, or is this still a good time to invest in Dollar General? Let's find out.

People celebrating by throwing money in the air.

Image source: Getty Images.

Always in style

Dollar General appeals to customers seeking value by offering most of its merchandise at prices of $10 or less. And it stocks the kind of goods that people use every day. It typically gets most of its sales from the consumables category -- things like paper towels, garbage bags, packaged foods, and soap. For instance, in its fiscal 2021 (which ended Jan. 28), consumables accounted for about 77% of Dollar General's sales.

It also sells items like toys, batteries, light bulbs, and clothing. In other words, essential items that people largely buy no matter what's happening with their personal economic circumstances. That's a big reason why Dollar General had 31 straight years of same-store sales increases.

The growth streak stopped last year, but that was due to the  extraordinary pop in comps growth it experienced in fiscal 2020 due to the onset of the pandemic. In fiscal 2021, its comps fell by 2.8%, but they were still up 13.5% compared to fiscal 2019.

Hardships bring customers

This year, consumers struggling with higher prices have continued to turn to Dollar General for value purchases. In its fiscal second quarter, which ended on July 29, comps increased by 4.6% year over year, mostly due to customers spending more during each visit to the store. There was also an increase in traffic.

And despite the higher costs retailers are experiencing, Dollar General's operating profit rose by 7.5% to $913.4 million. So management is keeping a watchful eye on the bottom line.

Dollar General remains well-positioned to benefit as the economic environment changes. The Federal Reserve continues to combat high inflation by raising interest rates, and many economists now expect the U.S. will tip into a recession.

While no one likes to see economic pain, Dollar General should do well. Former CEO Todd Vasos once said that the company does "fabulous in bad times." Management now expects comps to increase by 4% to 4.5% this year, up from its previous forecast range of 3% to 3.5%.

Returning cash

Dollar General also rewards its shareholders by regularly increasing its dividend payouts. Since it began distributing dividends in 2015, the board of directors has raised its payouts annually. The most recent hike, ahead of its April distribution, boosted the quarterly payout by 31% to $0.55 per share.

Management also regularly repurchases shares. In the second quarter, it spent $349 million to buy back stock, paying an average price of $233.36 per share. The current stock price is about 10% above this level. In fact, over the years, this has been a good use of capital.

After spending $1.1 billion on buybacks in the first half, Dollar General expects to expend a total of $2.8 billion on buybacks in fiscal 2022. With $1 billion remaining on its prior buyback authorization, the board of directors authorized another $2 billion, showing its commitment to buying shares.

While many retailers struggle in difficult economic times, Dollar General's business does particularly well during such periods. That's why the stock has bucked the market's downward trend, and given its steady sales, its profit growth, and its habit of returning cash to shareholders, Dollar General should remain at the top of investors' lists of stocks to buy.