I have a Heatilator NB4842I gas fireplace. When I turn on the switch on the wall, the pilot lights the burner. When I turn off the switch, the burner goes off but pilot is staying on until I tap on gas valve. It's never done this before, and the unit is only 4 years old and not used often. Any ideas for diagnosing the cause of the problem?
I'm not sure about your model, but in my experience (I have gas heating stoves and a gas fireplace) the pilot should stay lit at all times to prevent the build-up of gas in the case of a small leak. It also protects against the case of a power outage.
I know this is the DIY site, but I'd still recommend having it looked at by a licensed professional. You don't want to screw up with gas and blow up your house.
look at page 22 of the manual: http://www.heatilator.com/downloads/installManuals/4031-551.pdf
using a multimeter, check the voltage being sent to the valve while the fireplace is on, which should be the green and orange wires. the re-check it after you turn it off and the pilot is still on. if the on and off voltages are different, then your gas valve is faulty. if the voltages are the same, then your controller is faulty.
if the it's valve, do not replace it yourself. in nearly every jurisdiction, it is illegal for non-licensed people to do work on gas fixtures.
note that it might also be that you just never noticed that the pilot remains on for a brief time as it burns the residual gas in the line.