With 40 Americans in the hands of fanatical Moslems in the mindless city of Beirut, President Reagan did most everything that could have been asked of him.

Boldly, he held a news conference, an exercise he hates in the best of times. He knew he would take his lumps for his old rhetorical swagger about "swift and effective retribution." He had schooled and steeled himself to that outrageous fortune, and throughout the news conference he was masterly, somber, measured, chastened and without a hint that he had ever heard of John Wayne and "standing tall."

He conceded that he can do nothing save what was done by his disdained predecessor, Jimmy Carter, who in a similar instance waited and prayed, with one lapse into violence, for the hostages' safe return.

Reagan drew the line at one thing: He will not be compared to Carter. He would not admit that he had been hard on Carter, that he at last knew something about what Carter had experienced while Reagan was savaging him for visiting "shame and humiliation" on the country.

He drew an uncharacteristically lawyerly distinction. Carter's plight, he said, was a piece of cake compared with his. Carter was dealing with "state-sponsored terrorism," while Reagan is faced with infinitely more difficult free-lancers.

"It just seems to me that you have a great many more opportunities . . . to find vulnerabilities in another government and things that you can say in return, that you can offer as a trade."

He did not specify the "vulnerabilities." Carter could have bombed Tehran, but that would have been, as Reagan had said minutes before in ruling out the use of force in Lebanon, "a terrorist act in itself."

Carter had been swift enough with economic reprisal. Eight days after the U.S. Embassy in Iran was occupied, he suspended imports of Iranian oil.

But Reagan artfully left his reproach up in the air.

Like Carter, he has made the safe return of the hostages the paramount consideration. But where he is different is that, while Carter made no secret of his eagerness to negotiate, Reagan has taken a firm public stance against "giving in" to the terrorists.

To drive home the point that "state-sponsored terrorism" is more manageable, Reagan retroactively conferred on the Iranian government a "cohesiveness" that he says is lacking in Lebanon. But Tehran then looked as crazed a capital as Beirut today.

"But," says a Reagan man, "it had a head, the Ayatollah Khomeini. Nobody is in charge in Beirut."

Yet, Reagan attributed power equal to the ayatollah's on Nabih Berri, the Shiite leader we are dealing with. Berri is the Lebanese minister of justice. Although Reagan has the ultimate responsibility for American citizens wherever they are, he put the fate of the 40 hostages on Berri, who, he said, with a snap of his fingers, "could be the solution that quickly."

From the perspective of Plains, Carter may see Reagan as a hostage of his own policies. The key is the reciprocal release of some 700 Shiite Moslems held as hostages in Israeli jails. They are not criminals; they were scooped up as insurance against attack when the Israelis were finally quitting Lebanon.

The United States officially disapproved their seizure. Israeli intended, until the hijacking occurred, to send them home. Yet both sides are immobilized on a matter of face. The Israelis won't give up the prisoners unless we ask them. Reagan won't ask because he won't give in to terrorists.

It's a standoff between friends. To Carter, the solution might look as easy as blinking.

Reagan knows that he is competing with Carter on the most important question of all. Carter, at the end of the day, saw all the hostages brought safely home. In Beirut, a U.S. Navy man was brutally murdered by the hijackers. Reagan must bring about the safe return of the others.

The danger is not that he will do something rash in Lebanon but that in frustration he will lash out at some other country that he can punish for far less cause.

He has unloaded on Greece for its lack of airport security. For sterner measures, Nicaragua suggests itself. It has not kidnaped any of our citizens. He hates it for what it might do. He could give Daniel Ortega a taste of the force he cannot use in Lebanon.

The morning after the last tragedy in Lebanon, the massacre of 241 Marines, he ordered the invasion of Grenada. It proved to be a dramatic diversion. If he moves against Nicaragua, he would take the public's mind off Lebanon and decisively end what he regards as the unendurable indignity of being compared to Jimmy Carter.