SAN FRANCISCO — Legalizing same-sex marriage would generate millions of dollars for San Francisco, the city's chief economist said Thursday, as a trial on California's gay wedding ban entered a fourth day.

Edmund Egan, who directs San Francisco's Office of Economic Analysis, said legalization of same-sex marriage would increase the intake of real estate, payroll and sales taxes and would slash the number of uninsured.

Testifying at a landmark federal trial which ultimately could seal the fate of same-sex marriage in the United States, Egan said legalizing gay marriage would also boost real estate values and increase school-district revenues.

Further, because married people amass more wealth than unmarried individuals, they are likely to spend more, spurring sectors of the economy.

Same-sex marriage supporters are seeking to overturn a California law known as Proposition 8, which limits marriage to unions between men and women. Socially-conservative opponents are fighting the lawsuit.

If gay-marriages are legalized, the city will be able to trim down the 177 million dollars it spends each year providing healthcare for the uninsured, Egan said. That's because businesses will extend health benefits to the spouses of their married gay employees, he said.

"Legalizing same-sex marriage would ultimately increase the number of people who have health insurance in San Francisco," Egan said, and that "would reduce the local burden for covering the uninsured."

Moreover, he said, citing studies demonstrating that married people are generally healthier than unmarried people, the legalization of same-sex marriage would lead to a healthier, more productive workforce.

"The long-term cost of discrimination," Egan said, is that it "weakens people's productivity in the workforce."

He added: "Higher productivity leads to higher wages and higher wages lead to higher payroll taxes for the city."

Egan outlined a number of ways in which the legalization of gay marriage might spur economic activity in San Francisco.

Egan estimated that there could be 21.4 million dollars in increased spending on weddings here, 13.2 million dollars of "per diem spending" by wedding guests who will fill an additional 2.6 million dollars worth of hotel rooms.

This, Egan said, would lead to 1.7 million dollars in sales tax revenue and 900,000 dollars in hotel tax revenue.

Other jurisdictions in California also would benefit from what Egan called "the San Francisco effect," because the state of California receives a percentage of the sales tax generated in San Francisco, Egan said.

On cross examination, an attorney an attorney for Proposition 8's campaign committee, a coalition called Protect Marriage, took issue with Egan's analysis, suggesting that he overestimated the number of gay couples that would get married should they be offered the option, and ignored potential additional costs of administering gay weddings.