def _datetime_to_stata_elapsed_vec(dates, fmt):
index = dates.index<EOL>NS_PER_DAY = <NUM_LIT> * <NUM_LIT> * <NUM_LIT:1000> * <NUM_LIT:1000> * <NUM_LIT:1000><EOL>US_PER_DAY = NS_PER_DAY / <NUM_LIT:1000><EOL>def parse_dates_safe(dates, delta=False, year=False, days=False):<EOL><INDENT>d = {}<EOL>if is_datetime64_dtype(dates.values):<EOL><INDENT>if delta:<EOL><INDENT>delta = dates - stata_epoch<EOL>d['<STR_LIT>'] = delta.values.astype(<EOL>np.int64) // <NUM_LIT:1000>  <EOL><DEDENT>if days or year:<EOL><INDENT>dates = DatetimeIndex(dates)<EOL>d['<STR_LIT>'], d['<STR_LIT>'] = dates.year, dates.month<EOL><DEDENT>if days:<EOL><INDENT>days = (dates.astype(np.int64) -<EOL>to_datetime(d['<STR_LIT>'], format='<STR_LIT>').astype(np.int64))<EOL>d['<STR_LIT>'] = days // NS_PER_DAY<EOL><DEDENT><DEDENT>elif infer_dtype(dates, skipna=False) == '<STR_LIT>':<EOL><INDENT>if delta:<EOL><INDENT>delta = dates.values - stata_epoch<EOL>f = lambda x:US_PER_DAY * x.days + <NUM_LIT> * x.seconds + x.microseconds<EOL>v = np.vectorize(f)<EOL>d['<STR_LIT>'] = v(delta)<EOL><DEDENT>if year:<EOL><INDENT>year_month = dates.apply(lambda x: <NUM_LIT:100> * x.year + x.month)<EOL>d['<STR_LIT>'] = year_month.values // <NUM_LIT:100><EOL>d['<STR_LIT>'] = (year_month.values - d['<STR_LIT>'] * <NUM_LIT:100>)<EOL><DEDENT>if days:<EOL><INDENT>f = lambda x: (x - datetime.datetime(x.year, <NUM_LIT:1>, <NUM_LIT:1>)).days<EOL>v = np.vectorize(f)<EOL>d['<STR_LIT>'] = v(dates)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return DataFrame(d, index=index)<EOL><DEDENT>bad_loc = isna(dates)<EOL>index = dates.index<EOL>if bad_loc.any():<EOL><INDENT>dates = Series(dates)<EOL>if is_datetime64_dtype(dates):<EOL><INDENT>dates[bad_loc] = to_datetime(stata_epoch)<EOL><DEDENT>else:<EOL><INDENT>dates[bad_loc] = stata_epoch<EOL><DEDENT><DEDENT>if fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>d = parse_dates_safe(dates, delta=True)<EOL>conv_dates = d.delta / <NUM_LIT:1000><EOL><DEDENT>elif fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>warnings.warn("<STR_LIT>")<EOL>conv_dates = dates<EOL><DEDENT>elif fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>d = parse_dates_safe(dates, delta=True)<EOL>conv_dates = d.delta // US_PER_DAY<EOL><DEDENT>elif fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>d = parse_dates_safe(dates, year=True, days=True)<EOL>conv_dates = (<NUM_LIT> * (d.year - stata_epoch.year) + d.days // <NUM_LIT:7>)<EOL><DEDENT>elif fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>d = parse_dates_safe(dates, year=True)<EOL>conv_dates = (<NUM_LIT:12> * (d.year - stata_epoch.year) + d.month - <NUM_LIT:1>)<EOL><DEDENT>elif fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>d = parse_dates_safe(dates, year=True)<EOL>conv_dates = <NUM_LIT:4> * (d.year - stata_epoch.year) + (d.month - <NUM_LIT:1>) // <NUM_LIT:3><EOL><DEDENT>elif fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>d = parse_dates_safe(dates, year=True)<EOL>conv_dates = (<NUM_LIT:2> * (d.year - stata_epoch.year) +<EOL>(d.month > <NUM_LIT:6>).astype(np.int))<EOL><DEDENT>elif fmt in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>d = parse_dates_safe(dates, year=True)<EOL>conv_dates = d.year<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>".format(fmt=fmt))<EOL><DEDENT>conv_dates = Series(conv_dates, dtype=np.float64)<EOL>missing_value = struct.unpack('<STR_LIT>', b'<STR_LIT>')[<NUM_LIT:0>]<EOL>conv_dates[bad_loc] = missing_value<EOL>return Series(conv_dates, index=index)<EOL>
Convert from datetime to SIF. http://www.stata.com/help.cgi?datetime

Parameters
----------
dates : Series
    Series or array containing datetime.datetime or datetime64[ns] to
    convert to the Stata Internal Format given by fmt
fmt : str
    The format to convert to. Can be, tc, td, tw, tm, tq, th, ty