diff --git a/src/SubModel.cc b/src/SubModel.cc
index 526492463c79ef7159d37a77eadc95aa3ee6fa71..c24a99a55ddb0d23788cd60edc9166466bb7dee5 100644
--- a/src/SubModel.cc
+++ b/src/SubModel.cc
@@ -273,10 +273,6 @@ TrendComponentModelTable::writeOutput(const string &basename, ostream &output) c
              << "M_.trend_component." << name << ".eqn = [";
       for (auto it : eqnums.at(name))
         output << it + 1 << " ";
-      output << "];" << endl
-             << "M_.trend_component." << name << ".target_eqn = [";
-      for (auto it : target_eqnums.at(name))
-        output << it + 1 << " ";
       output << "];" << endl
              << "M_.trend_component." << name << ".targets = [";
       for (auto it : eqnums.at(name))
@@ -325,6 +321,29 @@ TrendComponentModelTable::writeOutput(const string &basename, ostream &output) c
         output << (it >= 0 ? symbol_table.getTypeSpecificID(it) + 1 : -1) << " ";
       output << "];" << endl;
 
+      vector<string> target_eqtags_vec = target_eqtags.at(name);
+      output << "M_.trend_component." << name << ".target_eqtags = {";
+      for (auto it : target_eqtags_vec)
+        output << "'" << it << "';";
+      output << "};" << endl;
+
+      vector<string> eqtags_vec = eqtags.at(name);
+      output << "M_.trend_component." << name << ".target_eqn = [";
+      for (auto it : target_eqtags_vec)
+        {
+          int i = 0;
+          for (auto it1 : eqtags_vec)
+            {
+              i++;
+              if (it == it1)
+                {
+                  output << i << " ";
+                  break;
+                }
+            }
+        }
+      output << "];" << endl;
+
       vector<int> target_lhs_vec = getTargetLhs(name);
       vector<int> nontarget_lhs_vec = getNonTargetLhs(name);