Mounting uncertainty over the potential for a global recession led the S&P 500 index to fall into a bear market on May 20. But not all stocks have fared poorly. 

Pharma stocks Merck (MRK 0.44%) and Johnson & Johnson (JNJ 1.49%) have gained 23% and 5%, respectively, year to date. And based on their valuations, the two stocks look like solid long-term buys right now.

1. Merck

Merck's $233 billion market capitalization positions it as the fifth-largest pharma stock in the world. The company has an excellent drug portfolio and pipeline that should bode well for the future.

Merck had five blockbuster products in 2021, including the top-selling cancer drug in the world, Keytruda. And its animal health segment posted double-digit net sales growth for the year. The company also has a blockbuster COVID-19 antiviral treatment called Lagevrio, which generated $3.2 billion in net sales in the first quarter of 2022.

It also has 77 phase two programs and 29 phase three programs in its clinical trial pipeline. These projects are diversified across therapy areas, including cardiovascular, diabetes and endocrinology, oncology, and vaccines. This is exactly why analysts are forecasting 11.6% annual non-GAAP (adjusted) diluted earnings-per-share (EPS) growth through the next five years. 

Better yet, Merck can provide investors with a 2.9% dividend yield. For context, that's nearly double the S&P 500's 1.6% yield. 

Since Merck's dividend-payout ratio is expected to be 38% in 2022, the dividend appears safe and should be able to grow almost as quickly as earnings. This is why I'm expecting high-single-digit annual dividend growth, which makes the stock a nice combo of income and growth potential.

Even with Merck's significant rally so far this year, the stock doesn't look unreasonably priced. Merck is trading at a forward price-to-earnings (P/E) ratio of 12.9, which is slightly below the pharmaceutical-industry average of 13. Simply put, Merck is an above-average business, trading at an average valuation.

A patient and doctor speak to each other during an appointment.

Image source: Getty Images.

2. Johnson & Johnson

Johnson & Johnson's $458 billion market cap makes it the biggest pharma stock on the planet.  Its portfolio consisted of 14 blockbusters in 2021, including its immunology drug Stelara, cancer drug Darzalex, and a COVID-19 vaccine. Aside from the robust product portfolio, J&J has a just-as-impressive drug pipeline.

This is supported by the fact that the company, as of April, had 84 projects in different stages of clinical trials in treatment areas like oncology, immunology, and neuroscience. J&J's strong product portfolio should drive growth in the near term, while the pipeline should lead to growth in the distant future. This is why analysts are conservatively predicting that J&J will deliver 5% annual earnings growth over the next five years.

With the dividend-payout ratio projected to be 44% in 2022, J&J should be able to grow the dividend a bit ahead of earnings. That's why I'm anticipating dividend growth similar to the 6.6% raise that was declared last month. Coupled with a market-topping 2.5% dividend yield, this is a good mix of starting yield and growth prospects.

Best of all, J&J is sensibly priced for its quality and track record. The stock is priced at a forward P/E ratio of 17.5, which is only moderately higher than the S&P healthcare sector average of 15.4.