Some economists have grown more cautious in their outlook, given the Federal Reserve's hawkish stance in fighting inflation. While everyone hopes the U.S. economy can avoid a recession, certain stocks will do well even in an economic slowdown.

That's because, while people may curtail spending on discretionary items like vacations, and big-ticket items such as cars, they still need to buy basic items. These two companies offer everyday merchandise that consumers still buy, no matter what's going on with their personal financial circumstances.

People standing in a store aisle.

Image source: Getty Images.

1. Dollar General

Dollar General (DG 0.30%) offers most of its merchandise at prices below $10. More than three-quarters of its sales come from the consumables categories. This includes toilet paper, paper towels, trash bags, packaged foods (e.g., cereal), over-the-counter medicine, and soap. In other words, the type of products that people need to buy. After all, they won't use fewer paper towels if they're unemployed.

You can see that by looking at Dollar General's sales during difficult economic days. In the periods that ended January 2009 and January 2010, years that encompassed the Great Recession, same-store sales (comps) increased by 9% and 10%, respectively.

In fact, through fiscal 2020 (ended Jan. 29, 2021), the company had a remarkable streak of 31 years of positive comps. Last year, the streak was broken when comps fell by 2.8%, but that was because the early days of the pandemic saw large buying for some products that boosted that year's sales. On a two-year basis, comps rose by 13.5%.

This year, management expects comps to increase by 3% to 3.5%. The company increased guidance from its previous 2.5% expectation.

With low prices on everyday goods, holiday items, and apparel, it offers a good value proposition. That becomes even more compelling when people are going through trying times.

2. Kraft Heinz

Kraft Heinz (KHC 1.31%) sells condiments like ketchup, cheese and dairy products, and frozen foods. Its popular brands include Heinz, Kraft, Oscar Mayer, Velveeta, and Maxwell House. These consumer staples typically don't see a drop-off in demand when the economy turns sour.

In the first quarter, Kraft Heinz's adjusted sales rose by 6.8%. On the positive front, the company was able to pass along cost increases, with higher prices accounting for nine percentage points. Volume/mix dragged the period's sales down by 2.2 percentage points, but management blamed this on supply chain constraints.

In other words, demand for its products didn't drop, just the ability of the company to get enough on the shelves. This problem has also plagued many consumer goods companies. Management felt confident enough to raise its 2022 sales outlook, now expecting a mid-single-digit percentage increase.

With mainstay products found in many people's homes, Kraft Heinz offers stable prospects even if the economy falls into a recession.

When looking for companies to invest in that will do well even if the economy hits turbulence, it's important to find ones whose demand won't dip. In the case of Dollar General, its low prices will likely attract customers, an even better scenario. Kraft Heinz probably isn't as fortunate, but people will continue buying items like ketchup throughout a slowdown. That makes them ideal stocks to buy ahead of a recession.