President Reagan yesterday handed 4.3 million federal civilian and military workers a 2 percent pay raise for the new year.

The president signed an executive order implementing raises recently authorized by Congress as he vacationed in Palm Springs, Calif., at the estate of publisher Walter Annenberg.

The new raise will increase the pay of a midlevel government worker, a GS9, step 5, from $25,454 to $25,963 annually. A less senior worker, a GS5, step 5, would go from $16,798 to $17,134 a year. The pay of those in the higher grades, such as a GS14, step 5, would rise from $51,863 to $52,903 a year.

The highest paid executives -- those making more than $72,500 -- got no raise under legislation passed Dec. 21 and signed by the president the next day.

Congress, judges and other top officials last winter received a controversial raise, in some cases as much as 16 percent. As a result, members of Congress voted to freeze their own pay, that of district court judges, and assistant Cabinet secretaries at $89,500 a year; the pay of the vice president, the chief justice and the speaker of the House at $115,000 annually, and the most senior members of the Senior Executive Service at $77,500 a year.

Carol Bonasaro, executive director of the Senior Executive Association, said that the freezing of civil servant executive pay "aggravates the already severe problems of recruiting and retaining people."

The pay increase goes to 2.1 million federal civilian workers and 2.2 million military personnel. The military pay increase goes into effect today, the civilian increase on the first day of the first pay period after today.

The military increase will raise the level of pay and allowances for enlisted personnel with less than four months of active duty to $620.70 per month. After four months, recruits would be eligible for $671.40 monthly.

Reagan last year proposed raising civilian pay by 2 percent and military pay and allowances by 4 percent. Congress pressed for a 3 percent increase for all workers, which the president threatened to veto. The 2 percent figure was agreed on as part of the deficit-reduction compromise between the administration and Congress during the recent "budget summit."

The Office of Management and Budget said that the cost of the civilian pay raise, roughly $550 million, must be absorbed by the employing agencies without additional funding. The cost of the pay raise for civilian employes at the Pentagon, about $505 million, and for military officers and enlisted personnel, $1.004 billion, does not have to be swallowed by the Defense Department, a spokesman said.

Because of the decision by Congress to freeze lawmakers' pay, about 7,000 high officials of the executive branch and 1,639 judges will not receive a raise at this time.

Those workers barred from the pay increase are the group singled out by a presidential commission last year as "critically underpaid." The commission found that federal executives and legislators have experienced a decline of over 40 percent in real income since 1969.

Reagan yesterday also ordered a 4.2 percent benefit increase for 1.5 million military and 2.1 million civilian retirees.

And, in a related action, the president signed legislation that grants an identical 4.2 percent cost-of-living benefit increase for more than 2.2 million veterans with service-connected disabilities and their dependents and 310,000 surviving spouses and children of veterans whose deaths were service related.