The average lifespan of an S&P 500 company is less than 20 years. That makes successfully picking stocks to hold for decades hard. Even the most dominant companies of today could be relegated to the dustbin of history within a generation.

The best an investor can do is pick stocks that have some sort of competitive advantage and hold on tight. If you're looking for ideas, three of our Foolish investors think Shopify (SHOP 1.35%), Vail Resorts (MTN -0.67%), and Baidu (BIDU 0.17%) are great stocks to hold for decades. Here's why.

A sunrise over mountains.

Image source: Vail Resorts.

The one-stop shop for digitizing a business

Leo Sun (Shopify): Shopify helps companies design, set up, and run online stores. It also lets them process orders, payments, and shipments, run marketing campaigns, and build customer relationships with its expanding ecosystem of tools.

Shopify, founded in 2004, has a first mover's advantage in this space. Smaller rivals such as Bigcommerce and Magento lack Shopify's scale and brand recognition, and even Amazon.com's (AMZN 0.34%) rival platform, Webstore, flopped. Amazon now integrates Shopify's platform into its own marketplace.

Shopify now serves over half a million merchants worldwide -- up from just 84,000 in 2013. Shopify co-founder and CEO Tobi Lutke claims the company is a "100-year" business, since companies will always need to digitize their businesses.

Demand for Shopify's services is booming. Its revenue rose 95% in 2015 and 90% in 2016, and Wall Street expects another 70% growth this year. Shopify wasn't profitable in previous years, since it was investing heavily in the expansion of its ecosystem, but analysts expect it to squeeze out a slim non-GAAP profit this year.

Shopify rallied nearly 160% over the past 12 months, and the stock isn't cheap at 19 times sales and a whopping 425 times forward earnings. However, Shopify's first-mover advantage and best-in-breed reputation in its market makes it a great e-commerce play to hold for the next few decades.

Betting on winter sports

Tim Green (Vail Resorts): It's hard to predict anything about what the world will look like 50 years from now. But I'm pretty sure people will still be skiing in Colorado. Vail Resorts owns mountain resorts in Vail, Beaver Creek, Breckenridge, and Keystone in Colorado. The company also owns a handful of other mountain resorts, a portfolio of hotels, and golf courses.

Vail Resorts has been acquisitive in recent years, spending nearly $900 million on acquisitions since 2015. This activity has boosted revenue, which grew by 19% in fiscal 2017 and is up 70% over the past five years. It's also boosted the company's debt, which now sits at $1.26 billion. However, Vail Resorts' properties generate plenty of cash flow. Free cash flow was $312 million in fiscal 2017, good for a free cash flow margin of 16.4%.

Vail Resorts stock isn't cheap, trading for about 29 times free cash flow and 43 times earnings. But if your holding period is essentially forever, paying such a high price may not be a bad idea. No new mountain resorts are being built, according to the company, and Vail Resorts' guests tend to be what it calls "high-end vacation travelers." That means there's limited competition, and even a recession may not dent its business too much. The company remained profitable throughout the downturn brought on by the financial crisis, for example.

Barring a major drop in the popularity of skiing over the coming decades, Vail Resorts looks like a solid growth stock to hold for the long run.

Still just getting started

Matt DiLallo (Baidu): Chinese internet search giant Baidu has delivered impressive growth over the past decade, with sales up more than 4,000% in the past 10 years while earnings have risen nearly 1,700%. This growth has rewarded investors with more than a 770% return over that time frame.

While Baidu's growth rate slowed in recent years, the company's best days appear to be ahead. That's because the company has been pouring billions of dollars into expanding beyond its core search business, such as increasing its online-to-offline offerings, accelerating its artificial-intelligence efforts, and being one of the early leaders in driverless cars. These markets all represent long-term growth drivers for the company, with each having the potential to move the needle in the decades to come as search has in the past.

For example, the self-driving-car market alone could be a $7 trillion annual revenue stream for companies by 2050, according to a study from chip giant Intel (INTC -0.16%). The bulk of that revenue would come from providing mobility-as-a-service, which includes combining self-driving cars and ride-hailing services such as Baidu's partner Shouqi. Driving that estimate is the view that we won't own cars in the future but instead will summon them as needed to take us where we need to go. 

That's just one of several moonshot bets Baidu made in recent years, which have the potential to keep it growing at an accelerated pace for decades to come, making it a great growth stock to hold for the long term.