The stock market has been a confusing roller coaster over the last few years. Rising interest rates and inflation are hitting the economy, and these headwinds remain an anchor on the financial markets. The good news is that lower stock prices provide more bang for your buck, and nowhere is this more evident than the rising yields on dividend stocks.

Two terrific stocks to buy for their dividends are Realty Income (O -0.17%) and Hershey (HSY -0.53%). These stocks have fallen over concerns about the economy, but they are currently paying unusually high yields because of it. Here's why they should continue paying growing dividends over the long term.

1. Realty Income

Realty Income is a top real estate investment trust (REIT) with more than 13,100 properties across 85 countries. It has a long record of delivering market-beating returns to investors. Much of the return is supported by a monthly dividend that has increased for 31 consecutive years.

The strength of Realty Income's property portfolio makes the stock a great buy when Wall Street gets nervous. Its top clients include some of the top retailers, like Dollar General, Walgreens Boots Alliance, FedEx, Walmart, and Lowe's. Realty Income has a resilient collection of properties. The value here is that leading retailers will keep paying their rents even in a slow economy. This adds certainty to Reality's ability to pay dividends to shareholders.

The stock's fall has sent the dividend yield up to a high 6%. The current monthly payment of $0.256 per share is supported by $1.98 in adjusted funds from operations (AFFO) produced in the first half of 2023. Realty has grown its AFFO about 5% per year since 1996, and that includes at least a few economic recessions along the way.

Management is taking advantage of the current environment to scoop up quality properties at great values. It is looking to expand beyond its focus on retail properties to casinos and farming, which will make it more diversified and increase its long-term growth prospects.

2. Hershey

Hershey stock has increased its quarterly dividend for 14 years. In addition to the Hershey brand, it also owns several others like Reese's and Kit Kat, which have been driving profitable growth for shareholders for ages.

Hershey stock is historically known for its relatively low volatility, but the share price plummeted 19% this year over concerns about record-high prices for cocoa, which is making it more expensive to produce chocolate -- and therefore more expensive for the consumer to buy.

Hershey successfully passed the extra costs on to consumers through higher retail prices. Sales and adjusted earnings per share grew 11% and 19%, respectively, year over year last quarter, which are well above the company's historical averages.

But the concern is that virtually all its sales growth is coming from price increases and not higher volumes. Consumers cannot afford to pay higher prices for chocolate every year, which could make it challenging to maintain profitable growth at this rate of cost inflation.

However, sharp spikes in cocoa prices have always reversed in short order. Moreover, cocoa prices have been in a long-term upward trend since 2000, but Hershey has still grown sales and profits that fueled returns to shareholders.

Hershey has dealt with rising costs before and will navigate through the current episode just fine. Meanwhile, it continues to pay around half of its annual profits in dividends. The stock's haircut sent the dividend yield to an above-average 2.54%, compared to 1.89% for the average consumer staples stock.