As many others said: it's about the ideal cadence, you shift to maintain that cadence to make your pedaling output optimal and comfortable. Under some conditions you may not need to shift for a long time, under other conditions you may find yourself shifting very frequently. The idea is to make it natural so you don't have to think about shifting. And you don't need to worry about how often you shift: you shift as often as you need to. If you think you need to shift gears then you need to shift gears. Having your drivetrain in good shape and adjusted properly helps a lot