Savvy investors know how to use bear markets to their advantage -- loading up on high-quality stocks while others are selling off.

Real estate stocks are some of my favorite stocks to buy in a bear market because they can offer diversification for my portfolio, growth opportunities when the market recovers, and if it's a real estate investment trust (REIT), higher yielding dividends.

The stock market is erasing some of the losses from this year, but there's always a chance a market sell-off will happen again. If it does, here's why I'll be buying Iron Mountain (IRM 4.06%) and W. P. Carey (WPC -1.08%) and why you may want to, too.

Covering the bases for data storage needs

Iron Mountain is in the data storage industry. The REIT, which has been in operation for 71 years, stores physical assets like medical records, important documents, and files, art, or other collectibles. This business has done well over the years as it serves an essential but often overlooked niche of the economy.

Countless industries, like healthcare or lenders, are legally required to store documents for a period of time. Rather than allocating precious space and staff to manage these resources, they often outsource it. While society is moving toward digital storage solutions, there will always be a need for physical storage, particularly among its biggest customers.

But to cover all its bases, Iron Mountain is rapidly expanding in the data center industry, now having interest and ownership in 20 facilities as of the second quarter of 2022. This move will allow it to expand its current data services while getting a foot in a fast-growing industry with a high barrier of entry. It's also giving its revenue a nice boost, with data center earnings growing by 30% this past quarter.

Shares of the company are up nearly 3% this year and up over 16% over the last year -- which is no surprise considering the company has consistently reported strong earnings. Its revenue is up 18% year over year, while Q2 2022 marked record earnings before interest, taxes, depreciation, and amortization (EBITDA) and adjusted funds from operations (AFFO), key metrics for illustrating REIT profitability. Plus, its dividend yield is still a very attractive 4.6% even at the higher pricing today. I purchased shares in Iron Mountain during the last market dip and will happily buy more if the market tumbles.

A dividend record to be proud of

W.P. Carey's impressive history of 24 years of consistent dividend raises makes it one of the most tenured dividend payers. The diversified net lease REIT has interest and ownership in over 1,350 properties across the globe.The REIT is already up 9% this year, and 12% over the last year thanks to its reliable performance as of late. Revenue and net income were up 7.7% and 6.2% respectively in Q2 2022.

Aside from it's stellar dividend yield, I also like that the company is a diversified REIT. Bear markets aren't always associated with a recession, but they can be. And in times of economic distress, diversification is king. The company benefits from having a wide variety of assets in its portfolio like self-storage, retail, office, industrial, and warehouses, among others. That means if one industry is suffering from lack of demand, oversupply, or other economic impacts, the others can help carry the REIT's portfolio without compromising earnings.

It's also got an incredible track record. Its historical occupancy has remained upward of 97% for over 10 years, with occupancy sitting at 99% today, plus its dividend return is nearing 5%, over three times higher than the S&P 500. Its price today is around 16 times its AFFO, which means it's favorably priced even with its stock price being up. If the market were to reenter bear territory its share price could be impacted, offering investors an even better price with it.