The Federal National Mortgage Association reported yesterday it lost $31.2 million (47 cents a share) in the fourth quarter of 1984, compared with a profit of $13.6 million (20 cents) in the same period a year earlier.

For the entire year, Fannie Mae lost $57.4 million (87 cents), compared with a profit of $75.5 million ($1.13) in 1983.

Fannie Mae is a government-chartered private corporation that provides a secondary market in residential mortgages.

Chairman David O. Maxwell attributed the losses to high interest rates, loan losses, and decreased loan commitment fees due to competition from other sources.

The corporation said its negative interest margin, or its higher cost of funds over portfolio yield, amounted to $151.7 million for the year. Recession-related foreclosures resulted in $87.3 million in charge-offs, up from $38.3 million in 1983. Loan commitment fees declined from $151.2 million in 1983 to $114.3 million last year.

Lawrence W. Eckenfelder, an analyst with Dean Witter, said he expects that Fannie Mae will show a slight profit in 1985 if there is only a modest increase in interest rates.

Meanwhile, United Virginia Bankshares Inc. of Richmond reported fourth quarter earnings of $14.6 million ($1.17) , up 17 percent from the fourth quarter of 1983. For the year as a whole, the bank holding company earned $57.3 million ($4.66), up 11 percent over 1983.