It only seems as if all stocks have been trending downward this year. Yet, there are stocks that always seem to do well when there's a recession -- or even a threat of one.

Dollar Tree (DLTR -0.28%), Johnson & Johnson (JNJ 0.82%), and Flowers Foods (FLO 0.37%) thrived during the last recession, from December of 2007 to June of 2009, and all three are faring well so far this year. That's because they all have a common thread; they provide something that people need, regardless of the economy.

Dollar Tree helps people stretch their money by selling low-cost variety items. Flowers Foods is benefiting because the same trends that led people to cook at home during the pandemic are carrying over -- meaning people see they can save money by buying Flowers' products and eating at home. Johnson & Johnson is a huge healthcare company, and people always need its products, including during tough times.

Overhead shot of people shopping in a large grocery store.

Image source: Getty Images.

1. Dollar Tree: Money in the bank

Chances are you have shopped at one of Dollar Tree's discount variety stores or know someone who has. It operates 15,500 stores in the U.S. and Canada under the brands Dollar Tree and Family Dollar.

During the last recession, the S&P 500 index dropped 25.1%; Dollar Tree saw its shares rise 46.9%. Though we're not officially in a recession, the market downturn has sent the S&P 500 downward by 12.8% this year while Dollar Tree is up 17.4%.

DLTR Chart

DLTR data by YCharts.

The company reported its first-quarter 2022 numbers last week, and they were eye-opening. Revenue was up a reported 6.5% to $6.9 billion and diluted earnings per share (EPS) were up 48.1% to a first-quarter company record of $2.37.

Dollar Tree has increased its gross profit margin 360 basis points to 33.9% during inflationary times by raising its typical price point from $1 to $1.25. It also tightened its supply chain and opened 112 new stores in the quarter while expanding or relocating 33 others and closing 30 stores.

In March, the company said it expected yearly EPS of between $7.60 and $8; then in the first-quarter report, it boosted that estimate to between $7.80 and $8.20. It also boosted expected revenue to between $27.8 billion and $28.1 billion, up from $27.2 billion to $27.9 billion.

Johnson & Johnson: Too big to fail

Johnson & Johnson is a favorite of value investors because it has increased revenue for six consecutive years and EPS for four consecutive years and raised its dividend for 60 consecutive years, making it a Dividend King. It is a huge company with more than 144,000 employees, and despite talcum powder- and opioid-related lawsuits of recent years, continues to navigate forward.

The company's most recent dividend raise was 6.6% to $1.13 per quarter, giving it a yield of 2.5%. Its cash dividend payout ratio is an easily sustainable 56.6%, especially given its strong cash flows.

The shares are up more than 5% so far this year, and that shouldn't be a surprise. During the 2007-2009 recession, its shares did fall 16.2%, but that was still better than the 37.9% drop for the S&P 500. And the stock bounced back quickly both from that recession and the short down period at the beginning of the pandemic.

The company operates in three segments: consumer health, pharmaceuticals, and medtech. The first segment is the only one of the three that didn't see a revenue gain in the first quarter, and the company plans to spin off that segment by November of 2023.

In the first quarter, Johnson & Johnson reported revenue of $23.4 billion, up 5% year over year. EPS declined 16.8% vs. the same period in 2021, but gross profit was listed at $15.8 billion, up 3.7%. The company said it expects yearly EPS between $10.60 and $10.80, showing a gain between 8.2% and 10.2%, and yearly revenue somewhere between $94.8 billion and $95.8 billion, for a gain between 3.8% and 4.8% over last year.

Flowers Foods manages to rise to the occasion

Flowers Foods is another company that should be familiar, if only because of its brands of baked goods, which include Tastykake and the bread brands Wonder, Nature's Own, and Sunbeam, among others.

As a consumer staples company, Flowers Foods is as stable as they come. So far this year, its stock is down less than 1%. During the 2007-2009 recession, its shares lost only about 6%. There's a reason its stock doesn't take big nosedives; when times are hard, people still have to eat, and its baked goods and breads are a big part of our diet.

Flowers has something that sets it apart from many companies: a dividend that has grown for 20 consecutive years. The company raised its quarterly dividend this year by 4.8% to $0.22, giving it a yield of 3.22%, more than two times the S&P 500 average dividend yield of 1.37%. The payout is a bit high at 82%, based on trailing 12-month earnings, but based on expected cash flow, it's a much more reasonable 41%. The company also helps investors by regularly repurchasing shares, and has a plan this year to buy back $25.4 million worth of its stock.

The company has managed to deal with inflationary pressures by raising prices. In the first quarter, it reported revenue of $1.4 billion, up 10.3% year over year. Net income was listed at $85.6 million, up 19.4% over the same period in 2021, and its EPS of $0.40 was up from $0.34 in the first quarter of 2021.

Flowers also upgraded its 2022 guidance for annual revenue to land between $4.764 billion and $4.850 billion, which represents a gain of between 10% and 12%. It did downgrade its adjusted EPS to a range of $1.20 to $1.30, compared to earlier guidance of between $1.25 and $1.35, citing adjustments for inflation and supply chain issues.

All good choices

All three of these companies have proved to be solid choices in a recession and have advantages that others might not have during downturns. Dollar Tree and Flowers Foods are set up to thrive in recessions because they are the type of businesses people turn to in order to save on necessary daily items. Johnson & Johnson doesn't benefit per se from recessions, but its huge size and healthcare items, whether pharmaceutical goods or medtech devices such as knee replacements or lenses for cataract surgery, are the types of products that aren't really optional.

Flowers Foods and Johnson & Johnson have one advantage over Dollar Tree in that both companies offer above-average dividends with a history of raises. That gives long-term investors a little peace of mind to wait out recessions, knowing the stocks provide strong total returns. All three companies have similar price-to-earnings ratios running from a high of 26 for Flowers Foods to 25 for Dollar Tree and 24 for Johnson & Johnson.