Write the file header

def _write_header(self, data_label=None, time_stamp=None):
        """Write the file header"""
        byteorder = self._byteorder
        self._file.write(bytes('<stata_dta>', 'utf-8'))
        bio = BytesIO()
        # ds_format - 117
        bio.write(self._tag(bytes('117', 'utf-8'), 'release'))
        # byteorder
        bio.write(self._tag(byteorder == ">" and "MSF" or "LSF", 'byteorder'))
        # number of vars, 2 bytes
        assert self.nvar < 2 ** 16
        bio.write(self._tag(struct.pack(byteorder + "H", self.nvar), 'K'))
        # number of obs, 4 bytes
        bio.write(self._tag(struct.pack(byteorder + "I", self.nobs), 'N'))
        # data label 81 bytes, char, null terminated
        label = data_label[:80] if data_label is not None else ''
        label_len = struct.pack(byteorder + "B", len(label))
        label = label_len + bytes(label, 'utf-8')
        bio.write(self._tag(label, 'label'))
        # time stamp, 18 bytes, char, null terminated
        # format dd Mon yyyy hh:mm
        if time_stamp is None:
            time_stamp = datetime.datetime.now()
        elif not isinstance(time_stamp, datetime.datetime):
            raise ValueError("time_stamp should be datetime type")
        # Avoid locale-specific month conversion
        months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
                  'Sep', 'Oct', 'Nov', 'Dec']
        month_lookup = {i + 1: month for i, month in enumerate(months)}
        ts = (time_stamp.strftime("%d ") +
              month_lookup[time_stamp.month] +
              time_stamp.strftime(" %Y %H:%M"))
        # '\x11' added due to inspection of Stata file
        ts = b'\x11' + bytes(ts, 'utf8')
        bio.write(self._tag(ts, 'timestamp'))
        bio.seek(0)
        self._file.write(self._tag(bio.read(), 'header'))