The amazing thing about David Stockman's career as director of the Office of Management and Budget is that it lasted as long as it did. After he savaged Reaganomics the way he did in the Atlantic Monthly article, "The Education of David Stockman," in December 1981, few thought he could last long in the job.

His endurance is a tribute less to President Reagan's broadmindedness than to the difficulty in getting anyone as competent to take an impossible assignment. "No one knows as much about the budget as Dave Stockman," White House aides said in explaining why Stockman was kept on after his famous trip to the Reagan "woodshed."

Now that Stockman has made the break after nearly five tortuous years for a highly compensated partnership in Salomon Brothers of New York, the replacement problem will have to be faced. Clearly, the headhunters working for White House Chief of Staff Donald T. Regan are seeking someone less controversial than Stockman, and especially someone who will stick to the Reagan party line: No tax increases permitted here.

The secret of Stockman's survival for most of 1982, 1983 and 1984 was that he went "underground," turning down speech and talk-show requests while adhering to his main goal of trying to whittle the federal government and the budget down to size.

After all, it was Stockman who had offered to Reagan at the start of his first term the substance of what until then had been only a campaign theme of cutting back federal spending. Stockman provided the "meat and potatoes" for what that line on the Reagan menu, inducing Congress (with a bipartisan vote) to pass drastic cuts in social-spending programs.

That was Stockman's, and probably Reagan's, biggest legislative success on budget cutting. But Stockman, as he revealed to author William Greider in that Atlantic Monthly piece, never bought the supply-side jargon. He knew, and told Greider, that "supply-side is 'trickle-down' theory."

But worse than that, as he knew, the huge $750 billion tax cut put through in 1981 (a monstrous blow to the tax base) would in the end defeat all of his deficit-cutting efforts. To the horror of unreconstructed Reaganauts, Stockman began working, along with then White House Chief of Staff James A. Baker, to support the efforts of traditional Republicans in the Senate to "take back" part of the tax cut.

Slowly, Stockman emerged from his self- imposed underground. In testimony on Feb. 7, before the House Appropriations Committee, Stockman said boldly that "the original 1981 tax cut clearly went too far." He noted that despite the president's anti-tax rhetoric, he signed five bills during 1982-84 that raised nearly $300 billion in additional revenue.

And that wasn't all. As he saw his vision of a budget under control fading away, Stockman emotionally denounced farmers as greedy and called military pensions "a scandal (and) . . . an outrage." Military men "are more concerned about protecting their retirement benefits than they are about protecting the security of the American people," he said.

In the past year, as Stockman suffered one frustration after another in trying to convince Congress to address the budget-deficit problem, he let his privately expressed feelings -- that some sort of tax increase may be inevitable -- creep into the public domain.

In an extraordinary speech June 5 to the New York Stock Exchange Institute, Stockman not only said that "we must either massively cut spending or raise taxes by large, unprecedented magnitudes," but also confessed once more (as he had in the Greider article) that the economic forecasts on which budget estimates are based rest on questionable assumptions.

This speech was originally made on an "off- the-record" basis, but, as Stockman could have predicted, it eventually leaked into print.

In one revealing passage, Stockman said the extent of the military buildup planned for 1986 to 1990, from $325 billion to $500 billion "won't be possible" and would have to be scaled back by $150 billion because "of the fiscal stand we have chosen."

Privately, Stockman had long been fighting Defense Secretary Caspar Weinberger's exaggerated ideas of what was needed for a military buildup. For the most part, he lost when Reagan had to choose between him and Weinberger.

So Stockman leaves Washington as the overseer of the biggest budget deficits in history, his goal of a smaller federal government a victim of Reagan's economic policy. The "brute fact," he admitted, is that the $900 billion national debt that Reagan inherited in 1981 -- which has now doubled -- will be tripled by 1990 unless there is "a change of course."

But he left an epitaph in the Stock Exchange speech:

"The basic fact is that we are violating badly, even wantonly, the cardinal rule of sound public finance: Governments must extract from the people in taxes what they dispense in benefits, services and protections -- perhaps not every year, but certainly over any intermediate period of time."