def _check_column_names(self, data):
converted_names = {}<EOL>columns = list(data.columns)<EOL>original_columns = columns[:]<EOL>duplicate_var_id = <NUM_LIT:0><EOL>for j, name in enumerate(columns):<EOL><INDENT>orig_name = name<EOL>if not isinstance(name, str):<EOL><INDENT>name = str(name)<EOL><DEDENT>for c in name:<EOL><INDENT>if ((c < '<STR_LIT:A>' or c > '<STR_LIT>') and (c < '<STR_LIT:a>' or c > '<STR_LIT:z>') and<EOL>(c < '<STR_LIT:0>' or c > '<STR_LIT>') and c != '<STR_LIT:_>'):<EOL><INDENT>name = name.replace(c, '<STR_LIT:_>')<EOL><DEDENT><DEDENT>if name in self.RESERVED_WORDS:<EOL><INDENT>name = '<STR_LIT:_>' + name<EOL><DEDENT>if name[<NUM_LIT:0>] >= '<STR_LIT:0>' and name[<NUM_LIT:0>] <= '<STR_LIT>':<EOL><INDENT>name = '<STR_LIT:_>' + name<EOL><DEDENT>name = name[:min(len(name), <NUM_LIT:32>)]<EOL>if not name == orig_name:<EOL><INDENT>while columns.count(name) > <NUM_LIT:0>:<EOL><INDENT>name = '<STR_LIT:_>' + str(duplicate_var_id) + name<EOL>name = name[:min(len(name), <NUM_LIT:32>)]<EOL>duplicate_var_id += <NUM_LIT:1><EOL><DEDENT>converted_names[orig_name] = name<EOL><DEDENT>columns[j] = name<EOL><DEDENT>data.columns = columns<EOL>if self._convert_dates:<EOL><INDENT>for c, o in zip(columns, original_columns):<EOL><INDENT>if c != o:<EOL><INDENT>self._convert_dates[c] = self._convert_dates[o]<EOL>del self._convert_dates[o]<EOL><DEDENT><DEDENT><DEDENT>if converted_names:<EOL><INDENT>conversion_warning = []<EOL>for orig_name, name in converted_names.items():<EOL><INDENT>try:<EOL><INDENT>orig_name = orig_name.encode('<STR_LIT:utf-8>')<EOL><DEDENT>except (UnicodeDecodeError, AttributeError):<EOL><INDENT>pass<EOL><DEDENT>msg = '<STR_LIT>'.format(orig_name, name)<EOL>conversion_warning.append(msg)<EOL><DEDENT>ws = invalid_name_doc.format('<STR_LIT>'.join(conversion_warning))<EOL>warnings.warn(ws, InvalidColumnName)<EOL><DEDENT>self._converted_names = converted_names<EOL>self._update_strl_names()<EOL>return data<EOL>
Checks column names to ensure that they are valid Stata column names.
This includes checks for:
    * Non-string names
    * Stata keywords
    * Variables that start with numbers
    * Variables with names that are too long

When an illegal variable name is detected, it is converted, and if
dates are exported, the variable name is propagated to the date
conversion dictionary