Definition of serendipity in a political campaign: when your opponent's ad works so well for you that you pay to bring it back on the air.

Rep. Phil Gramm (R-Tex.) was doing that last week amid signs that he has widened his lead over state Sen. Lloyd Doggett in the race for the U.S. Senate seat being vacated by retiring Sen. John G. Tower (R-Tex.).

Gramm, one of the staunchest conservatives in Congress, has begun airing excerpts of a Doggett commercial that ran on black radio stations in the Democratic primary. It urged voters who wanted to "stick it to Reagan" to vote for Doggett.

"We liked Lloyd's ad so much we're putting it back on for him," chuckled Larry Neal, Gramm's walrus-mustachioed press secretary.

Nothing could please Gramm more, of course, than to cast this race as a referendum on Reagan. The president is running 20 to 30 percentage points ahead in some Texas polls. Gramm never misses the opportunity to recall his role in 1981 as a "Boll Weevil Democrat" co-authoring Reagan's budget cut package, and this week he is saturating the state with television ads of Reagan in the Oval Office asking Texans to send "my friend Phil" to the Senate.

"It isn't so much the president's coattails I worry about," Doggett, 38, a savvy, consumer-oriented legislator quipped the other day. "It's his neck . . . which is getting bent from Phil hanging around it."

Gramm, 42, is feeling no worries. A survey taken for him by Houston pollster Lance Tarrance for Oct. 21-28 showed him leading, 54 to 35. And a three-night tracking sample of 600 voters taken Oct. 26-28 showed the gap widening to 56 to 32.

So confident is Gramm that he has taken to predicting that Doggett will suffer the most "resounding defeat that any candidate for statewide office from that party has ever suffered in the history of Texas."

Doggett calls the Tarrance poll figures "outrageous" and says he hopes they make Republicans complacent. He acknowledges that he is still behind but says the race is tightening.

This has been a nasty contest between ideological opposites, and it may well have turned on a negative ad thrust that Doggett opened, and Gramm parried, in mid-October.

Doggett's strategy was to portray Gramm not just as a conservative, but as a callous, cold-hearted one. He set out to make the case by hanging Gramm with his own words.

One Doggett television spot quoted Gramm as saying of Social Security benefits for elderly people: "Most people don't have the luxury of living to be 80 years old, so it's hard for me to feel sorry for them."

Another quoted Gramm as saying that programs for handicapped "practically encourage people to be handicapped."

Doggett strategists believed that the ads would turn the race around. Their one fear was that viewers would not believe that any politician would say such a thing, so they included a "Department of Verification" address where viewers could send to get copies of the articles in which the quotes appeared.

Gramm responded quickly. The handicapped quote appeared in a Wall Street Journal article about Gramm, but it was a attributed to him by an unnamed aide. So Gramm ran a false-advertising ad saying Doggett had taken the words of an "unnamed government bureaucrat" and put them in his mouth.

On top of that, some bad luck set in for Doggett. Gramm did not dispute the elderly quote, but, as it happened, a picture of an elderly man that ran with the ad turned out to be the deceased parent of a Gramm supporter.

Finally, Gramm ran an ad in which he claimed that Doggett had been cited for unethical advertising by the American Association of Advertising Agencies (4A), when the group merely had sent Doggett a letter during the primaries advising him that they had received a complaint.

"The diversion over the picture didn't do us any good, and neither did the 4A ad," conceded Doggett campaign manager James Carville, who remains incensed that the state media never picked up on the distortion of the 4A letter.

Part of Doggett's problem, analysts for both parties agree, has been that he developed a reputation as a slasher during a bruising three-way primary battle. As a result, his attacks on Gramm this fall have boosted his "negatives" more than they have Gramm's. Moreover, he has been outspent on television by more than 2 to 1.

Doggett's best hope Tuesday lies in a big turnout of Texas's growing black and Hispanic voting blocs. Hispanic registration is over 1 million for the first time, but overall registration is up dramatically as well -- to 7.9 million this year from 6.6 million in 1980. Republicans claim at least as many of the new registrants as the Democrats.