diff --git a/src/ExprNode.cc b/src/ExprNode.cc
index 4843c1b8b7793e613ed70451194f71df05bc308f..c5ccc66ec7ed447b0722d06c89376f8057061dfc 100644
--- a/src/ExprNode.cc
+++ b/src/ExprNode.cc
@@ -5198,12 +5198,10 @@ BinaryOpNode::PacMaxLag(int lhs_symb_id) const
 }
 
 int
-BinaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
+BinaryOpNode::getPacTargetSymbIdHelper(int lhs_symb_id, int undiff_lhs_symb_id, const set<pair<int, int>> & endogs) const
 {
-  set<pair<int, int>> endogs;
-  arg1->collectDynamicVariables(SymbolType::endogenous, endogs);
-  arg2->collectDynamicVariables(SymbolType::endogenous, endogs);
-  int ret_symb_id = -1;
+  int target_symb_id = -1;
+  bool found_lagged_lhs = false;
   for (auto & it : endogs)
     {
       int id = it.first;
@@ -5216,18 +5214,37 @@ BinaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
           {
             break;
           }
+      if (id == lhs_symb_id || id == undiff_lhs_symb_id)
+        found_lagged_lhs = true;
       if (id != lhs_symb_id && id != undiff_lhs_symb_id)
-        if (ret_symb_id < 0)
-          ret_symb_id = it.first;
-        else
-          {
-            cerr << "Error: Pac model is of wrong format: endogenous vars found: "
-                 << datatree.symbol_table.getName(ret_symb_id) << ", "
-                 << datatree.symbol_table.getName(it.first) << endl;
-            exit(EXIT_FAILURE);
-          }
+        if (target_symb_id < 0)
+          target_symb_id = it.first;
+    }
+  if (!found_lagged_lhs)
+    target_symb_id = -1;
+  return target_symb_id;
+}
+
+int
+BinaryOpNode::getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const
+{
+  set<pair<int, int>> endogs;
+  arg1->collectDynamicVariables(SymbolType::endogenous, endogs);
+  int target_symb_id = getPacTargetSymbIdHelper(lhs_symb_id, undiff_lhs_symb_id, endogs);
+  if (target_symb_id >= 0)
+    return target_symb_id;
+
+  endogs.clear();
+  arg2->collectDynamicVariables(SymbolType::endogenous, endogs);
+  target_symb_id = getPacTargetSymbIdHelper(lhs_symb_id, undiff_lhs_symb_id, endogs);
+
+  if (target_symb_id < 0)
+    {
+      cerr << "Error finding target variable in PAC equation" << endl;
+      exit(EXIT_FAILURE);
     }
-  return ret_symb_id;
+
+  return target_symb_id;
 }
 
 expr_t
diff --git a/src/ExprNode.hh b/src/ExprNode.hh
index eaee71aa80e62e20c4fdbd726a7c760739f5aec8..15aab14808b53e976e6ce5d5e28f9e992ac75e4a 100644
--- a/src/ExprNode.hh
+++ b/src/ExprNode.hh
@@ -1029,6 +1029,7 @@ public:
   int VarMinLag() const override;
   int VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs) const override;
   int PacMaxLag(int lhs_symb_id) const override;
+  int getPacTargetSymbIdHelper(int lhs_symb_id, int undiff_lhs_symb_id, const set<pair<int, int>> & endogs) const;
   int getPacTargetSymbId(int lhs_symb_id, int undiff_lhs_symb_id) const override;
   expr_t undiff() const override;
   expr_t decreaseLeadsLags(int n) const override;