Ideally, as an investor you should consider holding stocks over years, even decades. The magic of compounding will provide you with a substantial nest egg to enjoy your golden years, while a growing income stream from dividends provides a hedge against inflation. However, it's important not to buy and own the wrong companies. Doing so will result in poor or even negative returns and may destroy your capital over time.

So, what attributes do great companies have? They should have a strong competitive advantage, market share, and a high level of resilience. These attributes will allow them to weather crises over the years and yet emerge unscathed or even stronger. Companies with such attributes are usually large, with a long track record of growth and stellar financial performance. Size confers an advantage as it allows them to dominate the industry they are in and continue to lead the pack.

Here are three examples of stocks that you can hold for the next two decades.

Man holding credit card and smiling while looking at laptop

Image source: Getty Images.

Mastercard

Mastercard (MA -1.19%) is a market leader in the financial services and payments industry. The company acts as an intermediary between banks and end customers by providing a secure platform for transaction and payments processing. For the first quarter of the fiscal year 2020, the company processed a gross dollar volume of $1.56 trillion worth of transactions, up 8% year over year. The number of cards in circulation grew 5% year over year to 2.6 billion. 

Mastercard is a market leader in cashless transactions. With more countries modernizing and shifting to paperless transactions, the future looks bright for the company despite the short-term effect of the COVID-19 pandemic. Because of the pandemic, the company has temporarily suspended its share repurchase program. Dividend per share has been maintained at $0.40 per quarter as the business continued to generate strong operating cash flow of $1.9 billion. With strong tailwinds for its business and a robust balance sheet, Mastercard is a company you can own for the long term without losing sleep.

Nike

Nike (NKE 0.95%) is a market leader in the design and manufacture of sports footwear and apparel. The company has retail stores located around the globe and reported growth in revenue and net income of 7% and 10% respectively for the first nine months of the fiscal year 2020. 

Though Nike has had to temporarily close stores in China, North America, and other parts of the world due to COVID-19-related lockdowns, the company has managed to tap on its digital sales platform to sell its products. Digital sales were up 36% year over year during the quarter , and CEO John Donahoe has reiterated the company's commitment to invest in the Nike Direct online platform and the Nike app. Digital is the company's fastest-growing channel, and owned and partnered digital sales represent more than 20% of overall revenues.

Nike is also famous for its innovation in running shoes. A few months ago, the new Nike ZoomX Vaporfly NEXT% was touted as one of the best running shoes ever made, with people going so far as to claim it gives athletes an unfair mechanical advantage. The company has just devised a new self-lacing shoe called HyperAdapt 1.0 that electronically adjusts to the contours of your foot and offers style in addition to comfort.

Investors can rest assured that the company's innovative culture and loyal fan base make the company an attractive one to own for the long term.

American Tower

American Tower (AMT -0.59%) is an owner and operator of a portfolio of roughly 180,000 communication sites that are leased to wireless service providers and communication companies. The company is incorporated as a real estate investment trust and is mandated to pay out 90% of its annual taxable income as dividends.

Over the years, American Tower's dividend has grown impressively by around 22.8% per annum over the last seven years, from $0.90 per share in 2012 to $3.78 in 2019. The company has achieved this through acquisitions of cell towers in emerging markets and by increasing the number of tenants using the same tower (thereby improving the return on investment for each tower).

With the expected investment by telecommunication companies in the development of 5G network technology, American Tower can expect an extended period of solid growth. This catalyst can allow the company to grow for many more years, and investors can look forward to continually growing dividends.