A discharge from the penis is a reaction to irritation of the urethra. Doctors call this urethritis. Its usually caused by a sexually transmitted infection. The most common infections of the urethra are gonorrhea and chlamydia. Typically these are the infections your doctor will test for. He or she will use special cultures or tests that look for DNA from these bacteria.
But no test is perfect. So the results may be negative despite an actual infection. Also a variety of less common infections may cause similar symptoms. Doctors do not routinely test for these. Even if all of your tests were negative, I would bet that your doctor treated you with an antibiotic. If you responded to an antibiotic, then an undiagnosed infection was probably the cause.
There are a few things other than infection that may have caused your symptoms. The meatus (the opening of the urethra at the tip of the penis) may become irritated by soaps, lotions, spermicides or condoms. That may produce a discharge. Also, inserting something into the meatus for sexual stimulation could cause irritation and a discharge.
You might want to see a urologist if you have no evidence of infection, despite thorough testing and a course of antibiotics. Or if you are not sexually active and there is nothing that is likely to be irritating the urethra.