I had to move on out of the if and redeclare by loop_rate(double frequency), but with ros::Rate in front:
    ros::Rate loop_rate(rate_eff[type-1]/2+1);