If it's a hobbyist project, just follow what you see on existing commercial hardware. You want it to sit far enough above the board so that the leads are not stressed, either because they're too short and everything is jammed together in assembly, or because they're too long and the part is moving from shock and vibration.
Ideally TO-92 transistors should be around 1/10 to 1/4 of an inch (2.5mm - 5mm) above the board. TO-220 style transistors should have the leads sitting on their shoulders (unless they're bent 90 degrees and the transistor mounted flat).
If you really want to do it up right, search out the correct IPC standard for PCB manufacture -- that'll go into exhaustive detail (and then you'll know more than me!)