WASHINGTON (Reuters) - U.S. economic growth was a bit stronger than initially thought in the second quarter, notching its best performance in nearly four years and putting the economy on track to hit the Trump administration’s goal of 3 percent annual growth.

People stream into the Apple store on 5th Avenue on Black Friday in New York November 28, 2014. REUTERS/Carlo Allegri/File Photo

Gross domestic product increased at a 4.2 percent annualized rate, the Commerce Department said on Wednesday in its second estimate of GDP growth for the April-June quarter. That was slightly up from the 4.1 percent pace of expansion reported in July and was the fastest rate since the third quarter of 2014.

The economy grew at a 2.2 percent pace in the January-March period. The slight upward revision to growth last quarter reflected more business spending on software than previously estimated and less imported petroleum.

Stronger software investment and a smaller import bill offset a downward revision to consumer spending. President Donald Trump, whose administration has vowed to boost annual economic growth to 3 percent on a sustainable basis, cheered the revised second-quarter data.

“Our country is doing great!” Trump tweeted.

The economy expanded 3.2 percent in the first half of 2018, up from the 3.1 percent estimated last month. Compared to the second quarter of 2017, output increased 2.9 percent instead of the previously reported 2.8 percent. Economists, however, cautioned that the second-quarter growth pace was unsustainable as it was largely driven by one-off factors.

In addition, the economy faces constraints such as low productivity and slow population growth.

The Trump administration’s $1.5 trillion tax cut package provided a jolt to consumer spending after it almost stalled in the first quarter and soybean exports to China were front-loaded to beat retaliatory trade tariffs.

There are signs some of the momentum was lost early in the third quarter. The government reported on Tuesday that the goods trade deficit jumped 6.3 percent to $72.2 billion in July as a 6.7 percent plunge in food shipments weighed on exports.

While consumer spending has remained strong early in the third quarter, the housing market has weakened further with homebuilding rising less than expected in July and sales of new and previously owned homes falling amid a dearth of properties.

The Trump administration’s “America First” policies, which have led to an escalation of a trade war between the United States and China as well as tit-for-tat tariffs with the European Union, Canada and Mexico, pose a risk to the economy.

“We expect the pace of the expansion will cool in the second half of 2018, as the boost from fiscal stimulus starts to fade ... and trade protectionism weighs on activity,” said Oren Klachkin, lead economist at Oxford Economics in New York.

Economists had expected second-quarter GDP growth would be revised down to a 4.0 percent pace. The robust growth pace likely keeps the Federal Reserve on course to raise interest rates in September for the third time this year.

Stocks on Wall Street were trading higher, with the S&P 500 .SPX hitting a record high. The dollar .DXY was little changed against a basket of currencies while prices of U.S. Treasuries mostly fell.

GRAPHIC - U.S. GDP interactive graphic: tmsnrt.rs/1jLPbzV

INCOME GROWTH COOLS

An alternative measure of economic growth, gross domestic income (GDI), increased at a rate of 1.8 percent in the second quarter, slowing from the first quarter’s brisk 3.9 percent pace.

The average of GDP and GDI, also referred to as gross domestic output and considered a better measure of economic activity, increased at a 3.0 percent rate in the April-June period, up from a 3.1 percent growth pace in the first quarter.

The income side of the growth ledger was restrained by after-tax corporate profits, which rose at a rate of 2.4 percent last quarter. After-tax profits grew at an 8.2 percent pace in the first quarter, boosted by the massive reduction in the corporate income tax rate.

Some economists said the slowdown in second-quarter after-tax profits supported the view that the impact of the tax cuts would be temporary, potentially undercutting the White House’s argument that they would boost business spending and job growth.

“The tax cuts’ effect on boosting profits has already hit the corporate bottom line,” said Chris Rupkey, chief economist at MUFG in New York. “The question is what happens next year?”

Growth in consumer spending, which accounts for more than two-thirds of U.S. economic activity, was lowered to a 3.8 percent rate in the second quarter instead of the previously reported 4.0 percent pace. Consumer spending increased at a 0.5 percent pace in the first quarter.

Soybean exports were accelerated in the second quarter to beat Chinese tariffs that took effect in July. Overall exports rose at a 9.1 percent rate in the second quarter.

Imports fell at a 0.4 percent rate, with petroleum accounting for much of the decline. The decrease in imports was the biggest since the fourth quarter of 2015. Imports were previously reported to have grown at a 0.5 percent pace in the second quarter.

The drop in imports sharply narrowed the trade deficit. Trade added 1.17 percentage points to GDP growth in the second quarter rather than the previously reported 1.06 percentage points.

But the front-loading of soybean exports depleted farm inventories. Overall, inventories declined at a rate of $26.9 billion instead of the $27.9 billion pace reported last month. Inventories subtracted 0.97 percentage point from GDP growth in the second quarter.

Growth in business spending was raised to an 8.5 percent rate from a 7.3 percent pace, with investment in software accounting for the bulk of the increase.