A reduction in oil imports helped shrink the nation's trade deficit last month, the Commerce Department reported yesterday.

As oil purchases slumped to an average of 5.1 million barrels a day -- their lowest level since the 1973-74 Arab oil embargo -- the U.S. trade gap narrowed from $3.1 billion in June to $1.5 billion in July, the department said.

Monthly trade numbers are quite erratic, and oil imports have jumped around from month to month this year. But there has been a clear reduction in overseas purchases of oil this year from last year. Between January and July 1981, the United States imported only 1,318 billion barrels of oil, a drop of 17 percent from the same period last year.

Overall imports dropped by 9.9 percent between June and July to $20.7 billion, the Commerce report showed. Nonoil imports were generally flat during the month, probably reflecting a slowdown in the economic, analysts said.

Meanwhile, merchandise exports slipped 3 percent during July to $19.3 billion, the department said. European economies also are slowing so their imports from the United States are expected to drop.

The surge in the value of the dollar over recent months also is expected to affect the trade balance. The dollar has appreciated by 21 percent against the currencies of the United States' major trading partners since last October.

The first impact of this appreciation has been to improve the deficit because imports then cost less in U.S. dollars. However, this is likely to encourage Americans to buy more from abroad, thus ultimately raising imports.

In addition, because U.S. goods are now more expensive to foreigners, manufactuerers will find it harder to sell overseas, and U.S. exports probably will decline. The Commerce Department expects the deficit to worsen by "several billion dollars" from last year's $36.4 billion trade gap despite the cut in oil imports.

Commerce Department analyst David Lund said the July decline in oil imports was due partly to large inventories and reduced demand for oil. The Commerce Department's International Trade Association has predicted that oil imports could be as low as six million barrels a day this year, down about one million a day from 1980.

During the first seven months of 1981, exports were at an annual rate of $236 billion, about 7 percent higher than the 1980 total. Imports on the same basis were $271 billion, up about 6 percent over last year, the report showed.

In the last four months, the trade gap has changed little from that of the previous four.