Sen. Edward M. Kennedy's quest for a comeback victory in Pennsylvania received a strong boost today as Philadelphia's mayor, William J. Green, abandoned his position of cautions neutrality and endorsed the Massachusetts Democrat for president.

But a new statewide poll showed that Kennedy still has a way to go. The poll showed President Carter with a 13-point lead over Kennedy, with 29 percent listed in the category of undecided.

Green, a friend and political ally of Kennedy in Congress before becoming mayor, said it was Carter's "unexpected" budget cuts that pushed him to endorse Kennedy.

". . . I believe that the unexpected federal cutbacks and the worsening condition of the economy -- the burden of which falls most heavily on the people who live in America's cities -- make it imperative for me to speak out," Green said. He said he will not "attempt to deliver the city in the old machine style of politics," adding, "That era is gone."

But his endorsement is considered important by other Pennsylvania politicians, who say it is likely to influence some of the local ward leaders and labor officials who have been non-committal, but who might privately favor Kennedy.

Terry Straub, Carter-Mondale campaign manager for Pennsylvania, said he believes that the endorsement was made on a matter of personal loyalty and not policy preference.

"President Carter has had to take tough but necessary steps to bring the federal budget into balance," Straub said. "He has had to accept certain political costs for these steps."

He added: "There are, at the present time, just two big city mayors who have supported Sen. Kennedy's candidacy [in addition to Green, Chicago Mayor Jane Byrne endorsed Kennedy]. In both cases, it appears to me that the endorsements are based less on real policy differences with the president than on personal loyalty to the senator."

Kennedy is expected to carry Philadelphia. But he will need a substantial margin in the city to offset Carter strength in the small towns and rural areas of the state. Kennedy and Carter both have substantial strength in Pittsburgh and surrounding vicinities.

According to a statewide poll taken for KWY-TV by Teichner Associates of Princeton, Kennedy still trails Carter. The poll, taken last Saturday and Sunday, showed Carter with 42 percent, Kennedy 29, and 29 percent saying they did not know for whom they would vote.

The number of those saying they are undecided has risen sharply since the state conducted its previous poll on March 30. At that time, Carter had the backing of 49 percent, Kennedy 34 percent, with 18 percent saying they did not know.

The television station poll differed significantly from one taken by Carter pollster Patrick Caddell, and leaked by Carter campaign officials, showing Kennedy leading Carter 43 percent to 40 percent. Carter campaign officials explained that the Caddell poll was weighted to include only those likely to vote.

For weeks, Kennedy campaign officials had been privately unhappy that Green had not endorsed Kennedy, even though some of the mayor's aides had been helpful to the campaign. The mayor was said to have been concerned that a break with the president could make it more difficult for Philadelphia to obtain Carter administration cooperation for federal aid. f

Kennedy alluded to this at the airport news conference during which Green announced his endorsement, when the senator said: "All of us are mindful of the complexity of this decision."

The mayor spoke directly to the matter, in answer to a question. "No, I do not think Philadelphia will be penalized" because of the Kennedy endorsement, he said. "I have been assured by the president and the vice president that Philadelphia will not suffer."

In addition to receiving the support of the mayor, Kennedy began his final week of campaigning in the state by receiving the endorsement of the Service Employes International Union.