Retail is a cornerstone of the American economy, and retailers like Dollar General (DG 1.94%) and Walmart (WMT 0.09%) have built empires doing hundreds of billions of dollars in annual sales to the consumer.

Interestingly, these companies' stocks trended in different directions over the past year. Share prices of Dollar General plunged 35% compared to a year ago, while Walmart's have soared by more than 21%.

What separates these two powerhouse retailers, and what's the better stock to buy today? Crunching the data reveals what appears to be a lopsided battle. Here is what you need to know.

Dollar General's struggles

Investors have generally enjoyed strong performance from Dollar General since the company went public in 2009. It succeeded, in part, by opening its stores in rural neighborhoods lacking the population to support large retailers like Walmart. Today, Dollar General has over 19,000 stores, primarily in the United States (with a small portion in Mexico).

But the company has struggled over the past two years; revenue growth slipped to the low to mid-single digits, and operating margins are drifting lower.

DG Revenue (Quarterly YoY Growth) Chart

DG revenue (quarterly YoY growth); data by YCharts; YoY = year over year; TTM = trailing 12 months.

Management pointed to the economy putting pressure on customers, which is interesting. With Dollar General, one might think customers would flock to its stores to save money, but that hasn't shown up in the company's operating results. As with many businesses, inflation has hurt margins; inventory costs rose more than 14% year over year in the first quarter.

The combination of timid customers and higher costs stunted Dollar General's operating results and punished the stock, which investors have seen this year.

Walmart has enjoyed success

Meanwhile, Walmart has seemingly benefited from consumers cutting back. You can see below that revenue growth held up better through a quarter of 2023. While operating margins declined, sales grew enough to increase operating income.

Walmart might not get into some rural neighborhoods that Dollar General can, but the company still has a massive footprint. An estimated 90% of Americans live within 10 miles of one of its stores. Walmart is also a tremendous player in the grocery segment, which likely helps attract traffic.

WMT Revenue (Quarterly YoY Growth) Chart

WMT revenue (quarterly YoY growth) data by YCharts.

Has it been perfect? Of course not. Still, Walmart's tremendous size has seemingly helped it navigate a challenging operating environment, and Wall Street has rewarded investors accordingly. Investors will get an updated look at each company when second-quarter earnings come by month's end.

But what about moving forward?

American consumers will likely rebound over the long term. The economy has ups and downs, but shoppers are easily the economy's driving force. Roughly two-thirds of U.S. gross domestic product comes from consumer spending. That means Dollar General and Walmart have a good shot at growing over time.

But the company and the stock aren't the same thing. Dollar General's stock trades at a forward P/E of 16.6 versus Walmart's 25.7. Investors love themselves some Walmart. Analysts believe its earnings will grow by an average of 5.5% annually over the next three to five years versus 7.9% for Dollar General. If you weren't just keeping score, Walmart's stock has a higher valuation but a lower expected growth rate.

It translates directly to each stock's price/earnings-to-growth (PEG) ratio; Walmart trades at a PEG of 4.7, implying that the stock is blisteringly expensive considering its expected growth. Dollar General? It trades at a more reasonable PEG of 2.1. It's not a concrete predictor of the future; nobody can know for sure. However, it gives Dollar General stock a solid shot at outperforming Walmart. That makes it the clear winner to buy today.