A unidentified man was in good condition last night after being shot by an undercover District police officer who authorities said was trying to buy drugs from the man. It was the second time in two days that an undercover drug purchase involving a District officer had turned sour.

The shooting, which happened shortly before 7 p.m., occurred after the plainclothes officer attempted to make a drug purchase in an alley in the 5600 block of Central Avenue SE, police said. During the transaction, police said, the man pulled out a knife and tried to rob the officer, who quickly identified himself.

A scuffle ensued, during which the officer shot the man in the hip, police said. The man, who was arrested on the scene, was taken to D.C. General Hospital. He was charged with armed robbery.

The officer, whom authorities would not identify, was not injured in the incident, police said.

Less than 24 hours earlier, another undercover officer was injured when a man from whom she was trying to buy drugs assaulted her. The officer was treated at Washington Hospital Center. There gave been no arrests in the incident, which occurred in the unit block of T Street NE.

The area in which last night's shooting took place -- a half-block west of Southern Avenue -- is a major drug market, and residents said undercover officers have worked in the area for several years.