def _cast_to_stata_types(data):
ws = '<STR_LIT>'<EOL>conversion_data = ((np.bool, np.int8, np.int8),<EOL>(np.uint8, np.int8, np.int16),<EOL>(np.uint16, np.int16, np.int32),<EOL>(np.uint32, np.int32, np.int64))<EOL>float32_max = struct.unpack('<STR_LIT>', b'<STR_LIT>')[<NUM_LIT:0>]<EOL>float64_max = struct.unpack('<STR_LIT>', b'<STR_LIT>')[<NUM_LIT:0>]<EOL>for col in data:<EOL><INDENT>dtype = data[col].dtype<EOL>for c_data in conversion_data:<EOL><INDENT>if dtype == c_data[<NUM_LIT:0>]:<EOL><INDENT>if data[col].max() <= np.iinfo(c_data[<NUM_LIT:1>]).max:<EOL><INDENT>dtype = c_data[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>dtype = c_data[<NUM_LIT:2>]<EOL><DEDENT>if c_data[<NUM_LIT:2>] == np.float64:  <EOL><INDENT>if data[col].max() >= <NUM_LIT:2> ** <NUM_LIT>:<EOL><INDENT>ws = precision_loss_doc % ('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT><DEDENT>data[col] = data[col].astype(dtype)<EOL><DEDENT><DEDENT>if dtype == np.int8:<EOL><INDENT>if data[col].max() > <NUM_LIT:100> or data[col].min() < -<NUM_LIT>:<EOL><INDENT>data[col] = data[col].astype(np.int16)<EOL><DEDENT><DEDENT>elif dtype == np.int16:<EOL><INDENT>if data[col].max() > <NUM_LIT> or data[col].min() < -<NUM_LIT>:<EOL><INDENT>data[col] = data[col].astype(np.int32)<EOL><DEDENT><DEDENT>elif dtype == np.int64:<EOL><INDENT>if (data[col].max() <= <NUM_LIT> and<EOL>data[col].min() >= -<NUM_LIT>):<EOL><INDENT>data[col] = data[col].astype(np.int32)<EOL><DEDENT>else:<EOL><INDENT>data[col] = data[col].astype(np.float64)<EOL>if data[col].max() >= <NUM_LIT:2> ** <NUM_LIT> or data[col].min() <= -<NUM_LIT:2> ** <NUM_LIT>:<EOL><INDENT>ws = precision_loss_doc % ('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>elif dtype in (np.float32, np.float64):<EOL><INDENT>value = data[col].max()<EOL>if np.isinf(value):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(col=col))<EOL><DEDENT>if dtype == np.float32 and value > float32_max:<EOL><INDENT>data[col] = data[col].astype(np.float64)<EOL><DEDENT>elif dtype == np.float64:<EOL><INDENT>if value > float64_max:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>.format(col=col, val=value,<EOL>float64_max=float64_max))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if ws:<EOL><INDENT>warnings.warn(ws, PossiblePrecisionLoss)<EOL><DEDENT>return data<EOL>
Checks the dtypes of the columns of a pandas DataFrame for
    compatibility with the data types and ranges supported by Stata, and
    converts if necessary.

    Parameters
    ----------
    data : DataFrame
        The DataFrame to check and convert

    Notes
    -----
    Numeric columns in Stata must be one of int8, int16, int32, float32 or
    float64, with some additional value restrictions.  int8 and int16 columns
    are checked for violations of the value restrictions and upcast if needed.
    int64 data is not usable in Stata, and so it is downcast to int32 whenever
    the value are in the int32 range, and sidecast to float64 when larger than
    this range.  If the int64 values are outside of the range of those
    perfectly representable as float64 values, a warning is raised.

    bool columns are cast to int8.  uint columns are converted to int of the
    same size if there is no loss in precision, otherwise are upcast to a
    larger type.  uint64 is currently not supported since it is concerted to
    object in a DataFrame.