From e6a27ddb4615fee75a6450196cfbcc3d8fa3dcfd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Puck=29?= <stepan@adjemian.eu>
Date: Tue, 2 Apr 2024 11:43:32 +0200
Subject: [PATCH] Fix aux. equation for PAC expecation in cherrypick (MCE).

The RHS of the equation was not acknowledging the user provided name
for the auxiliary variable.
---
 matlab/cherrypick.m                 | 2 +-
 matlab/write_pac_mce_expectations.m | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/matlab/cherrypick.m b/matlab/cherrypick.m
index 9df5012849..9a6efb46e8 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 5eac4ea84f..da8c7b8454 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;
-- 
GitLab