* U.S. shares end higher after seesawing between gains and losses
* China factory activity contracts, stoking economic fears
* 10-year Treasury notes and safe-haven yen rally (Updates to close of U.S. markets)
By April Joyner
NEW YORK, Jan 2 (Reuters) - Weak Chinese and European economic data weighed on stocks around the world and boosted safe-haven Treasuries and the Japanese yen on Wednesday, though Wall Street shares edged higher as investors took advantage of cheaper shares to ring in the new year.
Chinese factory activity contracted for the first time in more than two years, according to a private survey.
The Purchasing Managers' Index (PMI) for the euro zone also reached its lowest level since February 2016, and France's PMI fell in December for the first time in two years. Concerns about the flagging global economy contributed to U.S. stocks posting a loss in 2018 for the first time in a decade.
The U.S. benchmark S&P 500 stock index dropped as much as 1.6 percent on the data, but later moved higher in choppy trading and ended up 0.13 percent.
Bank and energy shares, which have been especially hard-hit in recent sell-offs, were among the biggest gainers. But while cyclical stocks rose, defensive shares fell.
Keith Lerner, chief market strategist at SunTrust Advisory Services in Atlanta, said that divergence was likely driven by investors' seeking to rebalance their portfolios by looking for undervalued stocks
"It's a normal shifting in position, regardless of the data today," Lerner said. "We're seeing a 'January effect' on areas of the market that have sold hard."
Energy shares also benefited from a jump in oil prices, which climbed as U.S. stocks recovered.
MSCI's gauge of stocks around the globe ended 0.26 percent lower, as did Asian markets and the pan-European STOXX 600.
Reflecting lingering investor nervousness, yields on U.S. 10-year Treasury notes fell, hitting an 11-month low. However, the boost in oil prices pushed up yields on short-dated maturities, flattening the yield curve . An inverted yield curve is widely seen as an indicator of a future recession.
"The yield curve is signaling that something is wrong," said Matt Miskin, market strategist at John Hancock Investments in Boston. "The underlying economic data continues to suggest a slowdown."
The safe-haven Japanese yen reached a seven-month high against the dollar.
Yet the dollar index, which measures the greenback against a basket of six other currencies, advanced 0.7 percent as the euro and sterling fell more than 1 percent. The euro sank as a result of weak European manufacturing data, while concerns about Brexit negotiations weighed on sterling.
The Dow Jones Industrial Average rose 18.78 points, or 0.08 percent, to 23,346.24, the S&P 500 gained 3.18 points, or 0.13 percent, to 2,510.03 and the Nasdaq Composite added 30.66 points, or 0.46 percent, to 6,665.94.
Benchmark 10-year U.S. Treasury notes last rose 17/32 in price to yield 2.6328 percent, from 2.691 percent late on Monday.
Brent crude futures gained $1.11, or 2.06 percent, to settle at $54.91 a barrel. U.S. crude futures rose $1.13, or 2.49 percent, to settle at $46.54 a barrel.
Reporting by April Joyner; Additional reporting by Wayne Cole in Sydney and Sujata Rao and Abhinav Ramnarayan in London; Editing by Lisa Shumaker and Leslie Adler