diff --git a/matlab/cherrypick.m b/matlab/cherrypick.m
index 752533934695ac62f21d02c62a1503bc84c52fb4..9df501284981b6d6a6c06c63f900a6759b886459 100644
--- a/matlab/cherrypick.m
+++ b/matlab/cherrypick.m
@@ -189,7 +189,7 @@ try
             else
                 % MCE version of the PAC equation.
                 [rhs, growthneutralitycorrection] = write_pac_mce_expectations(eqtags{i}, ispac.name);
-                auxlhs = sprintf('%s_Z', eqtags{i});
+                auxlhs = M_.endo_names{M_.pac.(ispac.name).mce.z1};
                 if isempty(growthneutralitycorrection)
                     RHS = strrep(RHS, sprintf('pac_expectation(model_name = %s)', ispac.name), auxlhs);
                 else