diff --git a/matlab/cherrypick.m b/matlab/cherrypick.m
index 9df501284981b6d6a6c06c63f900a6759b886459..9a6efb46e82fb49aac39114622ede5d4ef424c1a 100644
--- a/matlab/cherrypick.m
+++ b/matlab/cherrypick.m
@@ -188,8 +188,8 @@ try
                 end
             else
                 % MCE version of the PAC equation.
-                [rhs, growthneutralitycorrection] = write_pac_mce_expectations(eqtags{i}, ispac.name);
                 auxlhs = M_.endo_names{M_.pac.(ispac.name).mce.z1};
+                [rhs, growthneutralitycorrection] = write_pac_mce_expectations(eqtags{i}, ispac.name, auxlhs);
                 if isempty(growthneutralitycorrection)
                     RHS = strrep(RHS, sprintf('pac_expectation(model_name = %s)', ispac.name), auxlhs);
                 else
diff --git a/matlab/write_pac_mce_expectations.m b/matlab/write_pac_mce_expectations.m
index 5eac4ea84f11c43b01cf7b481854d1ab8630ea3a..da8c7b84547fac449d4460319c43c2cc31e851f3 100644
--- a/matlab/write_pac_mce_expectations.m
+++ b/matlab/write_pac_mce_expectations.m
@@ -1,4 +1,4 @@
-function [expression, growthneutralitycorrection] = write_pac_mce_expectations(eqname, expectationmodelname)
+function [expression, growthneutralitycorrection] = write_pac_mce_expectations(eqname, expectationmodelname, auxname)
 
 % Prints the expansion of the PAC_EXPECTATION term in files.
 %
@@ -32,8 +32,6 @@ global M_
 
 expectationmodel = M_.pac.(expectationmodelname);
 
-auxname = sprintf('%s_Z', eqname);
-
 targetid = expectationmodel.ec.vars((expectationmodel.ec.istarget==true));
 alphaid = expectationmodel.mce.alpha;
 betaid = expectationmodel.discount_index;