Four out of five states, including New Jersey, collected more revenue in their general funds than they anticipated in fiscal year 2018 — the highest number of states reporting surpluses in a dozen years, according to the National Association of State Budget Officers.

The states can largely thank low unemployment, higher collections of income taxes, and a good year for sales taxes.

“There’s a lot of cautious optimism about the state of state finances right now," said Erica MacKellar, a senior policy specialist at the National Conference of State Legislatures.

Officials differ on what their states should do with surpluses. Pay off debts? Restore funding to local governments that have gotten less and less in state funds over the years? Save it for lean times?

But since fiscal year 2010, after the country emerged from the Great Recession, states as a whole have been devoting higher shares of their general funds each year to their savings accounts.

“Governments and legislatures have been touting the need to continuously build up their reserves, recognizing that some day in the future, another recession is going to hit,” said John Hicks, executive director of the National Association of State Budget Officers. "More so now than 20 to 25 yeas ago, rainy day funds and reserves are a more prominent, talked about, and supported government policy.”

States' median rainy day fund balance was 1.6 percent of general fund spending nine years ago. This year, states' median savings will be 7.3 percent of general fund spending, based on enacted state budgets, according to the budget officers' group.

In the last fiscal year, 32 states increased their savings accounts. Pennsylvania made a $22 million deposit into its rainy day fund — its first such deposit in nearly a decade. The current budget calls for a $4 million deposit in the fund this year, which would bring the total amount to about $26 million.

That’s nowhere near the amount the commonwealth would need to withstand a recession, and peanuts compared to its $32 billion general fund budget. A third of the states, including Pennsylvania and New Jersey, have “significantly fewer” funds than they would need to weather the next moderate recession without raising taxes or cutting spending, according to a 2018 “stress test” report by Moody’s Analytics.

Pennsylvania was among the eight states that met their general fund targets last fiscal year. Gov. Tom Wolf said building up the state’s Budget Stabilization Reserve Fund is a priority in his second term.

“On the whole, Pennsylvania is in a pretty good financial position,” Wolf said this week.

One reason why the recovery from the Great Recession was so slow was that states were not prepared for any downturn, let alone a deep one, said Dan White, director of fiscal policy research at Moody’s. Now, two-thirds of states have most or all of the funds they need for the next moderate recession, according to the Moody’s report.

New Jersey’s Surplus Revenue Fund sits empty. The state’s expected surplus won’t be enough to trigger a deposit into the reserve fund, according to the state treasury department.

New Jersey will know the size of its surplus in a couple of months when officials certify the budget numbers.

Elizabeth Maher Muoio, New Jersey’s treasurer, said in a statement that one of the administration’s top fiscal priorities “is building a healthier surplus, which is critical to weathering any economic downturns, providing cushion for emergencies, and boosting our credit rating.”

The goal for states, White of Moody’s said, is to balance savings with investments in the economy.

For Michael Darcy, executive director of the New Jersey State League of Municipalities, that means the state should invest in its 565 local governments. If New Jersey is ever to shed its designation as the state with the highest property taxes, surplus money has “got to make its way down to the local level,” he said.

“Municipalities have been underfunded for years,” he said, citing hundreds of millions of dollars in energy-tax revenue meant for local governments that the state has kept for itself during the last decade.

At least nine states, including Connecticut and North Carolina, have formally studied their revenue fluctuations since the Great Recession to figure out what they should do with reserves, said Steve Bailey, associate manager at the Pew Charitable Trusts.

Especially in the decade since the recession, state officials have reexamined what saving should look like. Many state officials realized they did not do enough to make sure their governments had enough savings, he said.

“It’s really hard for any state to figure out how to best prioritize” spending, Bailey said.

“For these states," Bailey said, “sometimes it was born of crisis or a look back at what they could do better.”

This story was updated to reflect that New Jersey will not know the size of its surplus until fiscal year 2018 budget numbers are finalized.