The U.S. economy was expanding at a robust annual rate of 4.3 percent immediately before the October stock market collapse, the government said yesterday in a report viewed as a sign that the country will be able to avoid a recession next year.

The Commerce Department said growth in the gross national product, the broadest measure of economic health, was greater than previously believed from July through September as consumer spending and federal government outlays offset further trade deficit deterioration.

The report also showed that inflation was in check. A measure of consumer prices tied to the GNP rose at a moderate annual rate of 3.4 percent in the third quarter, down from a 4.1 percent rate of increase in the spring.

"The economy was on a roll in the third quarter. These are the best set of statistics we have had in two years," said Allen Sinai, chief economist of Shearson Lehman Brothers of New York. "If nothing worse than the crash happens, then we should get be able to get through next year with decent growth."

This was the second time the summer GNP growth rate has been revised upward. Last month, the government estimated that the economy was expanding at a 4.1 percent rate in the third quarter, which was an upward revision from an initial estimate of 3.8 percent.

Various business barometers, from housing construction to unemployment, have shown that in November the country was suffering few ill effects from the record drop in stock prices on Oct. 19.

Analysts said these reports suggest that there is enough strength in other sectors to make up for a decline in consumer spending that is expected as a result of slower auto sales and stock market jitters.

"Even if we have a retrenchment in consumer spending, we believe exports and business investment will keep the economy out of a recession in 1988," said John Hagens, chief economist for the WEFA Group, a consulting firm in Bala Cynwyd, Pa.

In the first nine months of the year, the economy grew at an annual rate of 3.7 percent. While economists are looking for this pace to slow, they said growth for the entire year is likely to come in at about 3.5 percent, even better than the 3.2 percent the Reagan administration forecast at the beginning of the year.

There have been reports that the administration will scale down its current 3.5 percent growth forecast for 1988, with some suggesting it could be lowered by as much as a full percentage point.

That would still be higher than the consensus among private economists for growth of about 2 percent next year. Analysts expect the economy to be weak in the first half of 1988 but to rebound in the second half as the Federal Reserve pushes interest rates lower to keep the economy growing during a presidential election year.