Variationally stable difference equations