U.S. stocks advanced on Tuesday as economic data and the reappointment of Federal Reserve chief Ben Bernanke strengthened expectations for a recovery and offset forecasts of federal budget red ink.

Major indexes briefly hit 2009 highs after stronger-than-expected readings on consumers and housing, two crucial components for an economic rebound.

But a drop in oil prices weighed on energy shares, and Exxon Mobil helped limit gains on the Dow industrials.

The Conference Board's index of consumer confidence in August topped economists' forecast, while the S&P/Case-Shiller home price index rose for a second consecutive month in June.

Home builders' shares rose, with Lennar Corp up 4.6 percent at $15.24 and KB Home , also up 4.6 percent at $18.30.

It suggests that there still more consumers and investors yet to turn, or who are maybe increasingly turning, positive, and that is helping to boost the markets, said Jeff Kleintop, chief market strategist at LPL Financial in Boston.

The Dow Jones industrial average <.DJI> was up 52.91 points, or 0.56 percent, at 9,562.19. The Standard & Poor's 500 Index <.SPX> gained 4.11 points, or 0.40 percent, at 1,029.68. The Nasdaq Composite Index <.IXIC> rose 8.13 points, or 0.40 percent, at 2,026.11.

Pulte Homes Inc

, the biggest U.S. builder, rose 4.83 percent to $13.23 and the Dow Jones U.S. Home Construction index <.DJUSHB> gained 3.99 percent.

The consumer confidence data and earnings news helped drive retail stocks higher. Solid results from women's clothing retailer Chico's FAS Inc , rose 8.33 percent to $12.88, and close-out retailer Big-Lots Inc , gained 5.9 percent to $25.44.

Macy's Inc also rose 4.8 percent to $16.05 and the broader S&P Retail Index <.RLX> gained 2.13 percent.

Investors welcomed President Barack Obama's decision to keep Bernanke as Fed chairman.

Bernanke has put his policies in place and now (with the reappointment), the market is reassured that he will unwind the policies in a timely manner. It's good to know that someone else won't come in and change everything, said Kim Caughey, senior equity research analyst at Fort Pitt Capital Group in Pittsburgh.

The positive news overshadowed government forecasts that the U.S. national debt will nearly double over the next 10 years due to a slow recovery from the worst recession since the 1930s and higher spending on retirement and medical benefits.

The market is ignoring any kind of bad news. We are concentrated on the positive side, and anything that is not rosy is being shrugged off, said Alan B. Lancz, president of Alan Lancz & Associates in Toledo.

We have a lot of cash on the sideline and the market is looking for excuses to buy instead of being objective about the numbers.

The broad S&P 500 index briefly hit a 10-month intraday high and remains on track for its sixth straight monthly gain.

On the downside, energy shares were dragging the market with U.S. crude oil retreating nearly 3 percent to $72.20 after a recent rally.

Exxon was off 0.4 percent at $70.99 while Murphy Oil Corp shed 2.1 percent at $59.40.

(Reporting by Angela Moon, Editing by Kenneth Barry)