Macy's (M -0.30%) has been one of the worst-performing stocks of 2017, having declined about 40% year to date. Yet while Macy's clearly faces significant challenges due to changing consumer habits, its stock price has been driven far below its intrinsic value.

Macy's stock took its latest plunge on Monday, falling 7% after The Wall Street Journal ran a story highlighting how department stores (including Macy's) had recently begun discounting cosmetics, breaking with long-standing practice.

However, Macy's stock has been irrationally beaten down this year, perhaps thanks to the company's prominence as the No. 1 department store operator. Shares of Dillard's (DDS 1.58%) -- a company that faces the same trends but gets a lot less media scrutiny -- have fallen just 9% this year. As a result, Macy's shares are dramatically undervalued.

M Chart

Macy's vs. Dillard's 2017 Stock Performance, data by YCharts.

Macy's vs. Dillard's: It's the same story

The outperformance of Dillard's shares relative to Macy's stock during 2017 might seem to imply that Dillard's is insulated from the trends battering Macy's and other department stores. Yet both companies are in the same boat, for better or worse.

During fiscal 2016, comp sales declined 3.5% at Macy's. Dillard's posted an even steeper comp sales decline of approximately 5%. Macy's also had a somewhat higher adjusted pre-tax margin (excluding both asset sale gains and restructuring costs) of 5.1%, compared to 4.2% for Dillard's.

Last quarter, Dillard's posted a slightly better sales performance, with a 4% comp sales decline, compared to Macy's 4.6% decline. However, it benefited last quarter from being less weather-sensitive than Macy's. The vast majority of Dillard's stores are in the southern part of the U.S., whereas Macy's has heavy exposure to the Northeast and Midwest. Adjusting for this factor, the relative sales trends at Macy's and Dillard's haven't changed much in 2017.

On balance, Macy's is performing a little better than Dillard's right now. It has also made much bigger technology investments than Dillard's, which bodes well for Macy's long-term prospects. The most plausible explanation for why Macy's stock is underperforming Dillard's stock this year is that investors are singling it out and selling it as a proxy for all department-store stocks.

The Macy's flagship store in Manhattan

The outlook for Macy's isn't nearly as bad as its stock performance suggests. Image source: Macy's.

Rehashing old news

Another reason Macy's stock slide looks suspicious is that the stock often seems to plunge based on news stories that aren't actually "news."

For example, Macy's shares fell 8% after CFO Karen Hoguet stated in June that gross margin would probably decline more than the company had initially expected in fiscal 2017. However, Hoguet had previously discussed Macy's margin challenges at length on the first-quarter earnings call in May. Furthermore, the company's EPS guidance hasn't changed.

Similarly, Macy's executives have previously discussed the pricing pressure in cosmetics that The Wall Street Journal examined in its recent story. The story didn't provide any new information that would justify the sharp sell-off in Macy's stock.

Real estate remains a key source of value

Lastly, even if Macy's retail operations are more troubled than previously believed, the company can still fall back on its enormous real estate value. While some Macy's properties in lower-quality malls may be losing value because of the retail slump, the bulk of its real estate value is concentrated in urban flagship locations and top-tier malls. Macy's is steadily squeezing out value from this real estate portfolio.

During Macy's investor meeting last month, real estate chief Doug Sesler described a variety of projects the company is working on. It will take many years for Macy's to monetize its excess real estate, but pundits who think the company is ignoring its real estate are way off base.

Based on the recent Macy's stock price, the company's enterprise value has fallen to around $12 billion: less than most estimates of its real estate value alone. As Macy's continues to work through its turnaround plan and real estate monetization initiatives during the next few years, the share price is likely to fully recover from its irrational 2017 sell-off.