1999 Subaru Impreza Outback Sport - I put it in gear, start driving, then it starts kicking in and out of gear. It does this in all gears and reverse. Is it the transmission or an electrical problem?
Try driving it as gently as you possibly can, like there's a vat of boiling soup on the dashboard.
If that prevents or reduces the transmission from popping out of gear, you can suspect the engine and/or transmission mounts have torn.
This allows the drivetrain to shift, while the gear shift lever is held by a joint in the body. This causes the car to "shift" out of gear.
This is a relatively easy and inexpensive repair. I usually replace ALL of the mounts, unless some others have been replaced recently.