A boundary stress tensor for higher-derivative gravity in AdS and Lifshitz backgrounds