code: def write_panel_to_tsfile(
      data, path, target=None, problem_name="sample_data", header=None
  ):
      """Write an sktime multi-instance dataset to text file in .ts format.
  
      Write metadata and data stored in sktime compatible data set to file.
      A description of the ts format is in docs/source/api_reference/data_format.rst
  
      Parameters
      ----------
      data : Panel.
          dataset containing multiple time series instances, referred to as a Panel in
          sktime.
          Series can univariate, multivariate, equal or unequal length
      path : String.
          Location of the directory to write file
      target: None or ndarray, default = None
          Response variable, discrete for classification, continuous for regression
          None if clustering.
      problem_name : String, default = "sample_data"
          The file is written to <path>/<problem_name>/<problem_name>.ts
      header: String, default = None
          Optional text at the top of the file that is ignored when loading.
      """
      data_valid, _, data_metadata = check_is_scitype(
          data, scitype="Panel", return_metadata=True
      )
      if not data_valid:
          raise TypeError(" Wrong input data type ", type(data))
      if data_metadata["is_equal_length"]:
          # check class labels
          data = convert_to(
              data,
              to_type="numpy3D",
              as_scitype="Panel",
              store_behaviour="freeze",
          )
          series_length = data.shape[2]
          write_ndarray_to_tsfile(
              data,
              path,
              problem_name=problem_name,
              class_value_list=target,
              equal_length=True,
              series_length=series_length,
              comment=header,
          )
      else:
          write_dataframe_to_tsfile(
              data,
              path,
              problem_name=problem_name,
              class_value_list=target,
              equal_length=False,
              comment=header,
          )
  
file_path: sktime/sktime/datasets/_readers_writers/ts.py
imports: import itertools
  import numpy
  import pandas
  from sktime.datasets._readers_writers.utils import _alias_mtype_check, _write_header
  from sktime.datatypes import MTYPE_LIST_PANEL, check_is_scitype, convert, convert_to
  from sktime.utils.validation.panel import check_X, check_X_y
label_desc: Use image node_id 5 for calling a global function with example usage: write_panel_to_tsfile(data, path, target, problem_name, header) without return types