Republican John B. Anderson says he would not undertake an independent campaign for president if it meant helping Ronald Reagan win the White House.

The issue of whether the Illinois congressman might run as an independent if he loses the Republican nomination arose in a question-and-answer session with an overflow crowd of 1,700 students Tuesday at Stanford University in California.

When a student asked Anderson about press speculation that a third-party candidacy would help elect Reagan, Anderson replied, "I certainly would not want to be a party to anything remotely similar to what you suggested."

At a later television interview in San Francisco, the liberal Republican was asked again if he wouldn't take more votes from President Carter than Reagan if he ran as an independent.

"My differences with Ronald Reagan are so broad -- on energy, on so many issues -- that I cannot envision myself taking any deliberate action that would benefit him," Anderson said.

But Anderson continued to fuel the third-party speculation with other remarks during his second day of campaigning in Reagan's home state.

He said he has seen at least one poll which indicated if he ran as an independent he would take away as many votes from Reagan as from Carter.

"It has become increasingly clear to me that there exists an unprecedented level of discontent with the prospective choices that now face the voters of this country," he told the enthusiastic Stanford rally. "I am committed to the principle that we should have a choice."

Anderson cited a poll which he said found 58 percent of all Americans "disconsolate, literally despondent, over the prospect that the only choice they have is an election between Mr. Reagan and President Carter."