NEW YORK — Investors sidestepped some of their doubts about the economy Tuesday and bought energy and industrial stocks as commodity prices rose.
Stocks ended back-and-forth trading mostly higher as a spike in the price of gold and corporate dealmaking extended an advance from Monday. The gains in commodity prices helped stocks pare early losses.
The Dow Jones industrial average slipped 17 points after being down as much as 86 points.
Investors were encouraged by billionaire investor Warren Buffett’s decision to pay $34 billion for the Burlington Northern Santa Fe railroad in what he termed an “all-in wager” on the future of the U.S. economy.
Meanwhile, toolmaker Stanley Works struck a deal to acquire Black & Decker Corp. for $3.46 billion in stock.
The broader Standard & Poor’s 500 index rose 2.53, or 0.2 percent, to 1,045.41. The index is up 54.5 percent from a 12-year low in early March. The Nasdaq composite rose 8.12, or 0.4 percent, to 2,057.32.
Investors also took cues from commodities such as gold, which jumped to a new high after India’s central bank bought $6.7 billion of it from the International Monetary Fund.
Concerns about unemployment grew after health-care-products maker Johnson & Johnson said it would cut up to 7 percent of its global workforce and streamline its business structure to save up to $900 million next year. Investors worry that high unemployment will make it hard for the economy to sustain recent growth.
Financial stocks fell after the British government injected more money into Royal Bank of Scotland PLC and Lloyds Group PLC. That fanned worries about the troubles with bad debt still facing many banks.
Traders have been uneasy in recent weeks, wary about whether the economic recovery can maintain its third-quarter growth once government stimulus measures are removed. The Dow has risen or fallen more than 100 points in six of the last eight trading days, the most volatility since March.
“This is a much-needed healthy pause and reassessment,” said David Darst, chief investment strategist for Morgan Stanley Smith Barney in New York.
Shares of Burlington Northern jumped $20.93, or 27.5 percent, to $97 after the move by Buffett’s Berkshire Hathaway Inc., which already owns about 22 percent of Burlington. That pulled other railroads higher. CSX Corp. rose $3.13, or 7.3 percent, to $45.97, while Norfolk Southern Corp. advanced $2.52, or 5.4 percent, to $49.15.



