From edede274f27e1fcd4d43037e0cebae105c37adbd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stepan@adjemian.eu>
Date: Fri, 24 Jul 2020 17:36:31 +0200
Subject: [PATCH] Make the detection of the target in PAC equation more robust.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In a PAC equation, the error correction term must be written as:

β×(yₜ₋₁-xₜ₋₁)

where x is the endogenous variable determined by the equation and y
the target for x. The ordering matters, if not respected the
preprocessor wll not identify the error correction term (hence the
target) and will throw an error. The target must be an endogenous
variable or the log of an endogenous variable. For a more general
target, ie an expression, one can create an auxiliary variable.

We impose the ordering, target comes first in the error correction
term, so that the stability condition is always β>0 (this constraint
can be enforced when estimating the PAC equation).
---
 preprocessor                                  | 2 +-
 tests/pac/trend-component-13a/example.mod     | 2 +-
 tests/pac/trend-component-13b/example.mod     | 4 ++--
 tests/trend-component-and-var-models/tcm6.mod | 6 +++---
 tests/trend-component-and-var-models/tcm7.mod | 6 +++---
 tests/trend-component-and-var-models/tcm8.mod | 4 ++--
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/preprocessor b/preprocessor
index ca375041bb..150e9f05d5 160000
--- a/preprocessor
+++ b/preprocessor
@@ -1 +1 @@
-Subproject commit ca375041bb0860341aef5df1487413576973c092
+Subproject commit 150e9f05d5b164b728800ed9592d75071c765fb4
diff --git a/tests/pac/trend-component-13a/example.mod b/tests/pac/trend-component-13a/example.mod
index da102a915e..0ae12e9103 100644
--- a/tests/pac/trend-component-13a/example.mod
+++ b/tests/pac/trend-component-13a/example.mod
@@ -69,6 +69,6 @@ end;
 // Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
 pac.initialize('pacman');
 
-if ~isequal(M_.pac.pacman.equations.(M_.pac.pacman.tag_map{strcmp(M_.pac.pacman.tag_map(:,1), 'zpac'),2}).ec.istarget, [true, false])
+if ~isequal(M_.pac.pacman.equations.(M_.pac.pacman.tag_map{strcmp(M_.pac.pacman.tag_map(:,1), 'zpac'),2}).ec.istarget, [false, true])
    error('ec.istarget vector is wrong.')
 end
diff --git a/tests/pac/trend-component-13b/example.mod b/tests/pac/trend-component-13b/example.mod
index 49d275bb59..da102a915e 100644
--- a/tests/pac/trend-component-13b/example.mod
+++ b/tests/pac/trend-component-13b/example.mod
@@ -52,7 +52,7 @@ x1bar = x1bar(-1) + ex1bar;
 x2bar = x2bar(-1) + ex2bar;
 
 [name='zpac']
-diff(z) = e_c_m*(z(-1)-x1(-1)) + c_z_1*diff(z(-1))  + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
+diff(z) = e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1))  + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
 
 end;
 
@@ -69,6 +69,6 @@ end;
 // Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
 pac.initialize('pacman');
 
-if ~isequal(M_.pac.pacman.equations.(M_.pac.pacman.tag_map{strcmp(M_.pac.pacman.tag_map(:,1), 'zpac'),2}).ec.istarget, [false, true])
+if ~isequal(M_.pac.pacman.equations.(M_.pac.pacman.tag_map{strcmp(M_.pac.pacman.tag_map(:,1), 'zpac'),2}).ec.istarget, [true, false])
    error('ec.istarget vector is wrong.')
 end
diff --git a/tests/trend-component-and-var-models/tcm6.mod b/tests/trend-component-and-var-models/tcm6.mod
index 95c960a096..a44bd6b42b 100644
--- a/tests/trend-component-and-var-models/tcm6.mod
+++ b/tests/trend-component-and-var-models/tcm6.mod
@@ -108,15 +108,15 @@ diff(diff(log(U2_HH_OCOR))) =  u2_hh_ocor_ecm_u2_q_yed_L1   * (U2_Q_YED(-1) - U2
 U2_H_Q_YER400 = U2_H_Q_YER400(-1) + res_U2_H_Q_YER;
 
 [name='zpac']
-diff(log(U2_HH_COR)) = ecm_pac*(log(U2_HH_COR(-1))-log(U2_HH_OCOR(-1))) +
+diff(log(U2_HH_COR)) = ecm_pac*(log(U2_HH_OCOR(-1))-log(U2_HH_COR(-1))) +
                   u2_hh_cor_pac_u2_hh_cor_L1*diff(log(U2_HH_COR(-1))) +
                   pac_expectation(pacman)   +
                   res_ez;
 
 [name='zpac1']
-diff(log(U2_HH_COR1)) = ecm_pac*(log(U2_HH_COR1(-1))-log(U2_HH_OCOR(-1))) +
+diff(log(U2_HH_COR1)) = ecm_pac*(log(U2_HH_OCOR(-1))-log(U2_HH_COR1(-1))) +
                   u2_hh_cor_pac_u2_hh_cor_L1*diff(log(U2_HH_COR1(-1))) +
-                  pac_expectation(pacman1)   +
+                  pac_expectation(pacman1) +
                   res_ez;
 
 end;
diff --git a/tests/trend-component-and-var-models/tcm7.mod b/tests/trend-component-and-var-models/tcm7.mod
index 01c4dd6eec..d83815aaec 100644
--- a/tests/trend-component-and-var-models/tcm7.mod
+++ b/tests/trend-component-and-var-models/tcm7.mod
@@ -109,15 +109,15 @@ diff(U2_STN)   =   u2_stn_ecm_u2_q_yed_L1   * (U2_Q_YED(-1) - U2_EHIC(-1))
                  + res_U2_STN                                             ;
 
 [name='zpac']
-diff(log(U2_HH_COR)) = ecm_pac*(log(U2_HH_COR(-1))-log(U2_HH_OCOR(-1))) +
+diff(log(U2_HH_COR)) = ecm_pac*(log(U2_HH_OCOR(-1))-log(U2_HH_COR(-1))) +
                   u2_hh_cor_pac_u2_hh_cor_L1*diff(log(U2_HH_COR(-1))) +
                   pac_expectation(pacman)   +
                   res_ez;
 
 [name='zpac1']
-diff(log(U2_HH_COR1)) = ecm_pac*(log(U2_HH_COR1(-1))-log(U2_HH_OCOR(-1))) +
+diff(log(U2_HH_COR1)) = ecm_pac*(log(U2_HH_OCOR(-1))-log(U2_HH_COR1(-1))) +
                   u2_hh_cor_pac_u2_hh_cor_L1*diff(log(U2_HH_COR1(-1))) +
-                  pac_expectation(pacman1)   +
+                  pac_expectation(pacman1) +
                   res_ez;
 end;
 
diff --git a/tests/trend-component-and-var-models/tcm8.mod b/tests/trend-component-and-var-models/tcm8.mod
index 99f937be69..7269eb07e8 100644
--- a/tests/trend-component-and-var-models/tcm8.mod
+++ b/tests/trend-component-and-var-models/tcm8.mod
@@ -108,13 +108,13 @@ diff(U2_STN)   =   u2_stn_ecm_u2_q_yed_L1   * (U2_Q_YED(-1) - U2_EHIC(-1))
                  + res_U2_STN                                             ;
 
 [name='zpac']
-diff(log(U2_HH_COR)) = ecm_pac*(log(U2_HH_COR(-1))-log(U2_HH_OCOR(-1))) +
+diff(log(U2_HH_COR)) = ecm_pac*(log(U2_HH_OCOR(-1))-log(U2_HH_COR(-1))) +
                   u2_hh_cor_pac_u2_hh_cor_L1*diff(log(U2_HH_COR(-1))) +
                   pac_expectation(pacman)   +
                   res_ez;
 
 [name='zpac1']
-diff(log(U2_HH_COR1)) = ecm_pac*(log(U2_HH_COR1(-1))-log(U2_HH_OCOR(-1))) +
+diff(log(U2_HH_COR1)) = ecm_pac*(log(U2_HH_OCOR(-1))-log(U2_HH_COR1(-1))) +
                   u2_hh_cor_pac_u2_hh_cor_L1*diff(log(U2_HH_COR1(-1))) +
                   pac_expectation(pacman1)   +
                   res_ez;
-- 
GitLab