In a great year for stocks, Minnesota's two most valuable companies played outsized roles in driving the nation's best-known market barometer higher.

UnitedHealth Group and 3M Co. were among the four biggest contributors to the nearly 5,000-point gain in the Dow Jones industrial average, the index of 30 large U.S. companies that has been used to keep score on Wall Street since 1896.

Sales and profits rose solidly at both UnitedHealth and 3M this year, and their stock prices grew more strongly than the index itself. "These companies are at the right part of the business cycle, right where you would think they would perform, and they certainly did perform this year," said Craig Johnson, managing director at Piper Jaffray & Co. in Minneapolis.

But the effect UnitedHealth and 3M had on the Dow in 2017 illustrates more than strong fundamentals by two companies that happen to be based near each other. Investors these days are pouring money into exchange-traded funds and other vehicles tied to indexes, and the two Minnesota blue chips show how indexes behave differently.

"Index investing, or passive investing, is a bit of a generalism, and it behooves the investor to know what is going on," says Biff Robillard, principal at Bannerstone Capital Management in Deephaven. "Why does an index price change? It turns out that it depends on how important a stock is in the index."

More than simple averages of stock prices, indexes are built on formulas that emphasize certain characteristics of a company's value. The Dow Jones Industrials, rare among indexes, uses a formula that puts weight only on the price of a stock. As a result, higher-priced stocks have a greater effect on it.

With shares priced above $200, UnitedHealth and 3M had a bigger impact on the Dow than some other companies in that index, like Apple and Visa, that have lower-priced shares but experienced bigger percentage increases in price in 2017.

In November, the stock prices at the two Minnesota companies rose so quickly β€” and their prices were already so high β€” that they had the most impact on the Dow during its climb from 23,000 to 24,000. Out of those 1,000 points, 3M was responsible for 136 and UnitedHealth 122.

For the year, Boeing, with both a high-priced stock and a near doubling in price, was the biggest contributor to the rise of the Dow. It was responsible for almost 1,000 points of the overall increase of 4,956.62 points. Caterpillar was next at 465, followed by UnitedHealth at 432 and 3M at 419. The leading 10 companies on the Dow accounted for more than 80 percent of its gains this year, with the other 20 responsible for the rest.

The index closed the year on Friday at 24,719, a 25.1 percent improvement from 19,762.60 at the end of 2016. That's the third-best performance in the past 20 years, after a 26.5 percent gain in 2013 and 25.3 percent jump in 2003. The Dow's best year was 1933, when it gained 64 percent as the nation started to recover from the Great Depression.

Indexes like the S&P 500 rely on a formula that gives more weight to the market capitalization of a company, which is formed by multiplying the stock price and its number of shares. As a result, it is Apple, which has the biggest market cap of any U.S. company, with the outsized effect on the index. Since 2004, the nation's 10 most valuable companies have been responsible for as much as 40 percent of the movement on the S&P 500 each year.

Wide optimism for 2018

A market cap-weighted formulation is a better reflection of a stock's importance to the market. But the rise of ETFs and other investments tied to indexes tends to reinforce, or create momentum around, the most valuable parts of the index. That is fine for investors in a market that's moving higher, but it could lead to a faster unwinding in one that is declining.

Sentiment is high among stock prognosticators for 2018, with the world's largest economies all now rising and the new tax law expected to provide a windfall for U.S. companies. Few, however, are forecasting the Dow and other U.S. stock indexes to experience another 20 percent increase. The last time the Dow experienced two consecutive years of 20 percent-plus gains was in 1996 and 1997.

The analysts and investors who follow the two Minnesota companies in the Dow see few hurdles ahead in the short term.

3M, which reported a 4 percent sales increase through the first nine months of 2017, is forecasting sales to rise 5 to 7 percent in 2018. Its executives expect growth across all five of its business units, which range from health care and technology to consumer goods like Scotch tape and Post-it notes. Outside the U.S., the Maplewood-based firm is benefiting from a weaker U.S. dollar as well as the growing strength of the European and Chinese economies.

UnitedHealth, meanwhile, is forecasting a 12 percent sales increase in 2018 and an adjusted profit increase of around 7 percent. The Minnetonka-based company has expanded over the past decade from being the nation's largest health insurer to become the largest provider of health-related data services as well. Its overall sales are expected to exceed $200 billion for the first time this year while those of its Optum data unit are now greater than every other Minnesota-based company except Target and Cargill.

"3M and UnitedHealth are very different companies, and yet they've both added a lot of value to the American economy and they're both right in our neighborhood," Robillard said. "They are in tangible lines of work whose output itself improves our lives, and then just the number of people they have who take home a paycheck and pay taxes and put kids through our schools. These are gigantic value creators for us."