When the results came in tonight showing that New Hampshire -- a historic Kennedy family stronghold -- had gone solidly for President Carter, Sen. Edward M. Kennedy and his supporters came up with some virtuoso analysis that suggested their hefty deficit was actually good news.

"We got almost 40 percent of the vote," Kennedy said to the crowd jammed into his New Hampshire headquarters, a defunct clothing store on Manchester's main street.

"Four years ago Jimmy Carter got 28 percent of the vote and he claimed victory. And tonight," Kennedy went on in an exaggerated mocking tone, "we're claiming victory."

When he turned serious, however, and reiterated his determination to stay on the race, "on to Massachusetts, on to New York and Pennsylvania, and on to the Democratic convention."

Whether the money and the support he needs to keep going will be forthcoming is a mystery, but for the time being it seems evident that Kennedy wants to stay in the race.

After all, explained the candidate's nephews, Joe Kennedy III, polls last week, had showed Kennedy trailing by about 25 points. "We've got at least one victory here tonight," the younger Kennedy told campaign staffers. "We beat the polls by 2 to 1."

While Sen. Kennedy managed a smile and his wife, Joan, kept a stiff upper lip, the three children showed that the family is not reconciled to the idea of losing elections.

Twelve-year-old Patrick Jospeh Kennedy tried hard not to cry but finally broke down as he briefly spoke to the crowd. His older brother, Teddy Jr., announced "We're all very happy here tonight," but his long, sad face made it evident that this was a fib.

When the candidate himself arrived in Manchester tonight, he responded to the results with what might best be described as forced jollity.

For as long as he could today, Kennedy -- in neighboring Vermont -- ignored what was happening in New Hampshire and kept on chasing votes and contributions as if his race with Carter were a dead heat.

The little prop plane bounced and justled through the air pockets over Vermont like a Tinkertoy droped into a Waring blender, and with each jolt Kennedy grimaced; for a man with a bad back, the flight was torture.

He coughed and sneezed and wiped his nose on a crumpled paper napkin he had picked up somewhere, the New England weather had brought on a cold he could not shake.

He stood in a Vermont barnyard, the rich fragrance of manure lacing the icy air and quietly deplored inflation for the benefit of a shivering local TV crew.

He battled a tenacious corps of hecklers at the University of Vermont, and clearly enjoyed every minute of it. "I tell you, we haven't had this much fun -- isn't this great?" he shouted happily. "This is what the Democratic party is all about, I'll tell you."

Despite recurring back pains that forced him to stop campaigning some afternoons to soak in a hot bath, and despite unceasing schedule foulups in this often confused campaign, the 48-year-old senator has been campaigning the past few days with considerable elan.

He has been saying -- and said again in Manchester tonight -- that the inflation and high-interest statistics that came out last weekend can be the turning point that makes people realize "a vote for Kennedy will send a message that the Democratic Party is not going to put up with Republican economics any more."

He has steeled comfortably into a role he seemed uneasy about at the start of his campaign -- the liberal alternative to Carter.

At the University of Vermont today Kennedy's "big government" ideas were challenged, and he responded with an impassioned defense of liberalism.

"I'm deeply proud . . . that I have tried to be a voice to support people who have been excluded from our economic, social and political systems," he said. "If you want to deny help and assistance for the handicapped, for the mentally retarded . . . if you want to strike back against the elderly people in our society, food programs which are effective here in trying to provide nutrition for the elderly, then you've got the wrong man here for your candidates as president of the United States."

Another reason that Kennedy seems personally determined to keep running is his obvious dislike for the belief that his departure would leave California Gov. Edmund G. (Jerry) Brown Jr. as Carter's sole Democratic challenger.

Bumping across the narrow roads of northern New Hampshire the other day in his crowded, putrid campaign bus, Kennedy was talking calmly about the reversal his campaign has suffered since he entered the race as a clear front-runner four months ago.

But when the subject of Brown came up, the calm demeanor disappeared. Kennedy fairly bristled at the suggestion that he might leave liberal Democrats to Jerry Brown. "That won't happen," he said curtly.

And so Wednesday he starts off again, with two stops in Boston and a long flight for a day's campaigning in Alabama. Some may say that New Hampshire ended Kennedy's chances, but the candidate is not ready yet to join that chorus.