In June, the S&P 500 slumped 21.8% from its Jan. 3 peak, officially marking a bear market for the index. Though the index has recovered a bit since then, it is not out of the woods yet. Whether the index will reenter a bull market or get worse from here is anyone's guess. Trying to predict short-term fluctuations in stocks is impossible.

Though the timing is elusive, one thing is more certain. There will be an ensuing bull market. Following bear markets, bull markets can run rampant for a long time. Here are a few examples. After a bear market in the early '70s, the S&P 500 ran for 12.9 years and advanced an average of 19% per year. That was followed by a three-month bear market, followed by a nearly identical 12.8-year period returning a 19% average annual return.

A chart showing bull markets following bear markets.

Image source: Raymond James.

We won't know where the S&P 500 will be in the next month, quarter, or even next year, but there are tangible benefits to buying stocks during a bear market and holding them. Buying into a bear market can be scary, though. You may see your stocks get crushed before the bear market closes and feel the urge to sell. Avoid it!

The good news is that you don't have to be a genius. You just have to steer clear of the panic button. In the immortal words of Warren Buffett, "Success in investing doesn't correlate with IQ ... what you need is the temperament to control the urges that get other people into trouble in investing."

A toy bull and bear standing on a bar graph chart.

Image source: Getty Images.

For those ready to take on the challenge, here are two stocks that have been ravished in this year's bear market that you should consider buying before the bear market is over.

1. Johnson Controls

Johnson Controls (JCI 1.43%) helps its property owner customers maintain their heating and cooling equipment and keep tenants happy. For example, data center companies need to keep a massive amount of computer hardware cool, healthcare facilities need to keep patients warm and keep medicines at their optimal temperature, and apartment buildings need to keep residential customers comfortable. At the same time, the company's energy-efficient units reduce greenhouse gas emissions.

In addition to selling into growing industries like data centers and living spaces, Johnson Controls has introduced OpenBlue, its newest platform, which allows users to avoid breakdowns and costly disruptions. OpenBlue remotely monitors equipment for preventative maintenance and warns customers before failures occur. Johnson Controls can send someone out to install new parts sold by the company. Moreover, OpenBlue is system-agnostic, meaning it can be attached to any heating and air conditioning unit on the market. Therefore, Johnson Controls can sell its parts to replace and update competitors' units.

Johnson Controls stock has retreated 20% this year based on fears of a slowing economy, which could hinder new construction. It's true that a slowing construction market may slow the company's growth, but profits from aftermarket repair and maintenance equipment can help keep it afloat during a macroeconomic slowdown. In addition, Johnson Controls is sitting on a backlog of orders they have yet to fill totaling $11.1 billion. Despite the current macro environment, the company still expects to generate adjusted earnings per share of about $3 this year. Given the critical nature of Johnson Control's services, the stock can survive a bear market. But the company also has long-term growth prospects that could vault the stock when a bull market eventually materializes.

2. Trane Technologies

Trane Technologies (TT 1.42%) has a similar business to Johnson Controls, with a focus on its cold supply chain segment. The cold supply chain includes trucks, airplanes, shipping containers, and warehouses. Each step in the chain must remain at cold temperatures to transport the food, medicine, and other products moving through the system.

Trane's Thermo King brand is one of the most recognizable names in the cold supply chain industry. Failures at any place in the cold supply chain can mean an entire shipment could be spoiled. So buying from a reliable supplier like Thermo King is vital to the profits of its customers. The company has some of the most energy-efficient refrigeration products on the market. In addition to keeping spoiled food out of landfills and on tables, Trane's products reduce greenhouse gas emissions.

Also, like Johnson Controls, its stock is down, but it can sustain worsening economic conditions. Last quarter, as inflation remained at elevated levels, the company surprisingly raised its full-year earnings-per-share forecast from between $6.95 and $7.15 to between $7.05 and $7.15. Though the increase was modest, it demonstrates the resiliency of the company.

Should you buy before the bear market is over?

Though it would be nice to have a crystal ball that tells us the near-time prices of stocks, no one has one. If the bear macro climate takes a turn for the worse, Johnson Controls and Trane Technologies businesses can maintain earnings. Down the road, the two stocks can also benefit from the climate-change mega-trend and each company's own growth strategies. If you buy these stocks now, you'll be happy you did when the bear market is over.