After a week of political unrest over the new canal treaties, the death of two university students in clashes yesterday left Panama tense and gloomy on the eve of President Carter's arrival.

Three hours of sporadic shooting on the university campus here continuing until early yesterday, left at least two students dead and 18 reportedly wounded. The fighting was between factions opposing and supporting Carter's visit today.

Determined to prevent any further protests against Carter's 23-hour stay in Panama, the government ordered the university closed indefinitely and suspended classes at the most militant high school, the National Institute, whose students had also demonstrated against Carter recently.

Carter is coming to exchange the instruments of ratification of the Panama Canal treaties with Panamanian head of government Gen. Omar Torrijos, who has also invited his long-time regional supporters, the president of Columbia, Costa Rica, Jamaica, Mexico and Venezuela.

[In Washington, an administration official said, "We believe matters will be calm in Panama" during Carter's visit. White House press secretary Jody Powell said no changes were contemplated in the schedule.]

Although in the last two months there has been more apathy than militancy here, the impending Carter visit has revived the controversy over the treaties and Carter has become a new target of opposition criticism. This week, leftist student groups painted and pasted slogans like "Carter Keep Out" and "Panama Si, Carter No" around the capital. They have been hastily removed by government workers.

More moderate citizens addressed their criticisms less against Carter himself than against the impact they feel the visit they have. These opponents of Torrijos fear the Carter trip will serve mainly to boost the 10-year-old military government which many people have grown tired of.

The Torrijos government, which has spent a lot of money and energy in a publicity campaign to gather supporters for a rally today, was forced to subdue its enthusiastic tone because of the overnight violence.

The Canal pacts were ratified by the U.S. Senate earlier this year after a lengthy debate that barely produced the necessary two-thirds majority. They will give Panama control over the U.S.-built waterway by the year 2000 while a large portion of the installations and land in the U.S. Canal Zone will go to Panama after Congress approves the implementing legislation.

Although most officials here have been extremely bitter against the treaty opponents in the U.S. Senate and their often insulting descriptions of this country and its leadership, Torrijos has always praised Carter for his tenacious fight to get the treaties approved in the United States.

But public support for the Carter visit so far has come largely from official channels, such as pro-government labor and student unions and the pro-government communist party, known here as the People's Party. Most opposition groups of left and right have been critical of the visit, which they see as the celebration of treaties that many Panamanians have condemned.

Although Panama has anxiously negotiated for 14 years to get control over the canal, these groups feel the country had to swallow too much by having to accept the effective legalization of the U.S. military base in the zone as well as the U.S. insistence on the right to intervene here militarily after the year 2000.

All opposition groups have claimed that the absence of a second Panamanian plebiscite, to approve changes made by the U.S. Senate, has invalidated the pact.

The overnight clash began as anti-government students of the Federation of Revolutionary Students and of the Trotskyist League were holding noisy anti-Carter meetings on campus. At first they got into a stone throwing fight with the pro-government Federation of Panamanian Students, whose members then reportedly returned with armed civilians.

The two dead, one of whom was killed by a M1 rifle shot and the other by a rifle butt, belonged to the anti-government factions, which angrily charged that government agents were responsible.

"This is terrible. All our manifestations have been peaceful. It was a deliberate government provocation to keep the protesters off the streets for Carter," said a leader of the Trotskyist League.

In an agry radio speech, Labor Minister Adolfo Ahumada warned that no further disturbances would be tolerated. Ahumada also launched a strong attack against unnamed political exile who recently returned to Panama after a general amnesty. He virtually blamed the exiles for the violence, although there appears to be no evidence that any of them participated.

Anti-Carter demonstrations were planned here as soon as the president's visit was announced, long before the exiles returned.