RICHMOND -- Most of Virginia's colleges and universities were able to protect their endowment gains of recent years by switching from stocks to other investments before the dark stock market days of October.

The state's public and private college endowments picked up $500 million or more in market value between mid-1983 and July this year, financial reports and interviews with college officials indicate.

A sampling of 16 mainly undergraduate private colleges that reported endowment information yearly since 1983 had a combined gain of $269.3 million in endowment value between mid-1983 and this year, largely as a result of gains in the stock market.

Tipped off by sophisticated computer programs or by fund managers' recommendations, most schools shifted their assets from stocks to cash, bonds and other investments well before Oct. 19.

Officials at Hampton University, holders of the third-largest endowment fund among Virginia private four-year institutions, said they listened to Smith Barney, Harris Upham & Co. Inc. in New York and switched about a third of the school's portfolio to cash shortly before the Oct. 19 price plunge.

"Either they knew something, or they were lucky," Hampton President William R. Harvey said of the brokerage.

On a percentage basis, Hampton's loss for the month of October was a little more than half that of the stock market, which declined about 23 percent. The loss would have been much worse without the last-minute change, Harvey said.

A California fund manager set up a computerized system 18 months ago to monitor constantly "the relative attractiveness of stocks, bonds and cash" for the University of Richmond, which has the largest endowment fund among Virginia's private four-year institutions.

In early October this year, the computer pointed to bonds, so University of Richmond fund managers switched $60 million of the $220 million endowment fund from stocks to bonds.

The result was a $9 million profit on that portion of the endowment. The university lost money on $80 million still invested in stocks, but the last-minute shift reduced a potential loss of $30 million to about $10 million, said Louis W. Moelchert Jr., UR's vice president for business and finance.

Overall, the University of Richmond's fund has gained about $90 million in value since mid-1983. Only a small part of that increase is accounted for by money the university has added to the fund annually.

Raymond D. Smoot, vice president and treasurer at Virginia Tech, said, "During the past five years, the growth in market value of our endowment has been about 125 percent.

"I would lots rather have been there and gotten the 125 percent and given back 14 percent in October rather than to have been in fixed-income investments and not had the benefit of the gain in the stock market over the last five years," he said.

The University of Virginia's $396 million endowment fund, the largest in the state, lost about $70 million in the Oct. 19 drop. But the fund had rebounded to $354 million by Oct. 31. The loss for the month was about $42 million, or 11 percent of the fund, about half the loss in the stock market indexes.

Earlier this year, the university transferred funds from stocks to bonds and other investments, thus cutting the traditional share of the fund invested in stocks from about 75 percent to 58 percent by Oct. 19. On Oct. 31, only 53 percent of the fund was in stocks and the school's endowment fund still was $14.5 million ahead of the total on Jan. 1.