At its most fundamental level, the stock market is merely a measure of supply and demand. So as the biggest and wealthiest part of the U.S. population approaches a situation in which its members will start needing to liquidate their vast investment portfolios in order to cover living expenses, it only makes sense to wonder whether all that extra supply of shares will hurt stock prices for years to come.

A recent study tries to quantify exactly what impact baby boomers will have on the stock market. Although the results are indeed alarming, there's a silver lining for long-term investors -- one that should help keep you from making emotional decisions that could threaten the success of your investing plan over the long run.

Selling out
A report from the Federal Reserve Bank of San Francisco tried to answer the question of what would happen with stocks as baby boomers begin to retire. To do so, it looked at the ratio of middle-aged workers in their 40s to older workers and young retirees in their 60s and compared it with the valuation of the stock market. Interestingly, the research found a strong connection between stock prices and this age ratio.

In particular, during the bull market of the 1980s and 1990s, boomers were in their peak earning and investing years, while a relatively small part of the population was approaching or entering retirement. The report argues that those trends pushed earnings multiples for stocks up toward their peak around 30 in the late 1990s. Conversely, as boomers aged over the past decade, they gave way to a smaller cohort of middle-aged workers from the so-called baby bust, and as a result, earnings multiples have fallen.

The bad news is that this trend is likely to continue. In fact, the report suggests that P/E multiples could contract further, from their current levels in the mid-teens to as low as 8.4 by 2025. Even assuming that inflation-adjusted earnings continue to grow at past rates -- an assumption that could prove heroic -- the research suggests a 13% real drop in stock prices, with stocks not returning to their 2010 levels on an inflation-adjusted basis until 2027.

Demographic-proof investing
The San Francisco Fed's research makes some interesting points, but it's naive to think that baby boomers will sell out of all of their stocks. For one thing, with longer life expectancies, boomers need the growth that stocks can provide. In addition, large capital gains on some stocks will dissuade boomers from selling out and incurring a huge tax bill.

What's most likely is that rather than seeing retirees abandon stocks entirely, they'll move their stock allocations from risky, high-beta stocks to safer, less volatile choices. For instance, those who've invested in small oil and gas exploration and production companies such as Kodiak Oil & Gas (NYSE: KOG), Rosetta Resources (Nasdaq: ROSE), and Hyperdynamics (NYSE: HDY) have earned impressive returns because of high energy costs and big finds in alternative production methods like shale plays. But as you approach retirement, you can't afford the volatility that those stocks have.

Rather, you'll move toward more stable stocks that can help provide income, as well as modest growth. Investing in consumer-oriented stocks like Campbell Soup (NYSE: CPB) and General Mills (NYSE: GIS) or utilities Duke Energy (NYSE: DUK) and PG&E (NYSE: PCG) aren't going to blow the socks off your brokerage statement every month, but they will deliver healthy dividend income and tone down the fluctuations even during tough times. So even if you're younger, those conservative stocks might be exactly the place to be to take advantage of boomer demographic trends.

What could change
The report does admit that other factors, including foreign investment and prices of competing investments like bonds, could affect these projections. But if you want to invest with demographic trends in mind, the key is to figure out which stocks boomers are most likely to want to hang onto -- and to make sure to get out of the ones that boomers will want to sell first.

If you're looking for more of the dividend stocks that retirees are most likely to hang onto, look no further. The Fool's special free report with 13 high-yielding dividend stocks gives you a cheat sheet on the stocks that look best to dividend investors.