Dollar General (DG -0.41%) is a top realtor that focuses on providing consumers with day-to-day essential at reasonable prices. It has grown considerably over the years, opening its 19,000th store in January. And although 2023 hasn't been off to a good start, Dollar General has historically been an excellent stock to buy and hold.

Dollar General has outperformed the S&P in 8 of the past 10 years

Discount store operator Dollar General could be a relatively safe stock to buy, especially amid inflation and a potential downturn in the economy. It's a defensive, resilient stock, as its business can appeal to customers and generate growth even at a time when other companies are struggling.

But this is more than just a relatively safe investment to hold; Dollar General has routinely been a marketing-beating investment as well. Here's a look at how it has performed compared with the S&P 500 each year over the past decade:

Dollar General's stock returns vs the S&P 500.

Source: YCharts. Chart by author.

There were only two years during that stretch where it didn't beat the market -- 2016 and 2021. And in years of market declines such as in 2018 and 2022, Dollar General managed to post positive returns and handily outperform the S&P. Another remarkable fact is that over the past decade, in each one of those years, Dollar General's stock has achieved positive gains for investors. Those returns also don't factor in its dividend yet, which at 1.5% is in line with what the average S&P 500 stock pays.

What has helped make Dollar General a solid investment over the years is that nature of its business; by focusing on low prices the discount retailer appeals to a wide customer base. And by selling essential items, it's not as vulnerable to macroeconomic conditions as its products will always be in demand.

The company is facing headwinds in 2023

This year, however, isn't proving to be as strong for the stock. Dollar General shares are down 35% since January, and for it to come out positive this year would require a big turnaround in consumer sentiment. 

Shares of the company plummeted 20% when it reported its first-quarter earnings in June, which came in below expectations. Sales of $9.34 billion for the period ending May 5 missed Wall Street forecasts of $9.46 billion. Earnings per share of $2.34 also missed expectations by four cents. The company also scaled back its guidance for the fiscal year, and is now projecting same-store sales of no more than 2% versus an earlier forecast that called for as much as 3.5% growth.

Dollar General blames the current economic conditions for its challenges as its customers battle with rising inflation. And although the customer base proved to be resilient last year, continual inflation and interest rate hikes have clearly taken their toll. But while the business has slowed down of late, Dollar General has continued to generate positive year-over-year revenue growth:

DG Revenue (Quarterly YoY Growth) Chart
DG Revenue (Quarterly YoY Growth) data by YCharts.

Is Dollar General stock still a good buy today?

Dollar General's stock may end up underperforming the S&P 500 this year as the index has been soaring due to the popularity in tech and artificial intelligence. But there's a lot that can still change this year. And with the inflation rate slowing down and a recession potentially not taking place, Dollar General's business could recover, and so could its stock. Just as quickly as its shares nosedived due to a bad earnings report, they could bounce back on stronger results later this year.

What's important, however, is how the business does in the long run. Dollar General has established itself as a top retailer in the country, and with the business consistently generating good growth and looking for ways to expand, it makes for a viable long-term investment to buy and hold for years. As the economy starts to recover, this could quickly become a hot buy again. At 15 times earnings, there's a lot of value here. It's down right now compared to the S&P, but with the stock trading near its 52-week low, it could be an excellent excuse to buy the stock.