"In fact, when we own portions of outstanding businesses with outstanding managements, our favorite holding period is forever." -- Warren Buffett 

The advantage of holding a stock forever is the uninterrupted growth of the stock's value over many decades. And if you buy a stock with the intention of holding it forever, you're naturally going to invest in a company you like. If you like it, you're more likely to avoid the temptation of selling at the wrong time and missing the tremendous gains that come from compound interest.

That's the wisdom behind Warren Buffett's favorite holding period. The trick is you want to invest in companies that are financially solid and have a competitive advantage. Here are two stocks that fit the bill.

Costco Wholesale

Costco Wholesale (COST 1.01%) built its competitive advantage the old-fashioned way. It keeps costs down so it can sell quality goods at rock-bottom prices in volume. Whether offering tickets to the NFL's biggest game or selling giant jars of mayonnaise, Costco wants its 71 million household members to know they are getting the best deal. 

Over the past decade, Costco's membership warehouse model has delivered steady sales and earnings growth of about 9% and 12%, respectively. Sales took off during the pandemic as more members turned to its stores to stock up on essentials. The value it delivers during times of need only widens the company's competitive moat so that it can deliver more growth for investors.

One trend that could benefit Costco for a long time to come is the current demand from younger customers. This environment of higher inflation is clearly strengthening Costco's value proposition and going a long way toward building a new generation of shoppers.

Comparable-sales growth has slowed to low-single digits in recent quarters, partly because management has kept prices low relative to higher inflationary costs. But memberships were up 7.9% year over year in fiscal Q4.  

People are going to repeatedly shop at Costco because they trust the prices they see on the shelves are the best deal around. Its most recent member renewal rate was an impressive 92.7%. For all these reasons, investors won't find a more solid stock to hold forever than Costco.

Starbucks

Despite sluggish consumer spending, Starbucks (SBUX 0.47%) has delivered consistent sales growth over the last few years. But as it invests more in the stores, new menu items, and upgrading equipment, management believes there is more growth to come.

Morning commuters place a high value on their regular visit to Starbucks. Over the last 10 years, a combination of store openings and comparable-sales growth pushed revenue up 9% annually. It's impressive to see Starbucks expanding even faster over the last year. In the most recent quarter, global comp sales climbed 10% year over year, an acceleration over last year's 3% increase. 

No two baristas will make a Starbucks beverage exactly the same. Inconsistency would destroy almost every other restaurant, but not Starbucks. The repeat visits by 100 million customers every week speaks volumes about the brand's resiliency.

It's not surprising that Brand Finance ranked Starbucks the top restaurant brand for the seventh consecutive year. It has grown into a global icon, but Starbucks has plenty of room to expand, given there are still lots of areas in smaller U.S. cities without a store. Management also sees opportunities for new store formats in larger cities.

The shares have pulled back a bit this year, which sets up a good opportunity to start a small position. The stock's forward price-to-earnings ratio of 23 is the lowest valuation it has had in a while.