static gint32 stata_date (int t, const DATASET *dset) { long ed = -1; if (dataset_has_markers(dset)) { ed = get_epoch_day(dset->S[t]); } else { ed = epoch_day_from_t(t, dset); } return ed - STATA_DAY_OFFSET; }
static int process_starting_obs (char *stobs, int pd, int *pstructure, double *psd0, int *pdated) { int structure = *pstructure; double sd0 = 0.0; int maybe_tseries = 1; int dated = 0; int err = 0; if (structure == CROSS_SECTION || structure == STACKED_TIME_SERIES || structure == STACKED_CROSS_SECTION) { maybe_tseries = 0; } /* truncate stobs if not a calendar date */ if (likely_calendar_obs_string(stobs)) { if (maybe_tseries) { dated = 1; } else { return invalid_stobs(stobs); } } else { stobs[8] = '\0'; } if (dated) { if (pd == 5 || pd == 6 || pd == 7 || pd == 52) { /* calendar-dated data, daily or weekly */ long ed0 = get_epoch_day(stobs); if (ed0 < 0) { return invalid_stobs(stobs); } else { if (pd < 7) { maybe_fix_daily_start(&ed0, pd); } sd0 = ed0; structure = TIME_SERIES; } } else { return invalid_stobs(stobs); } } else if (structure == TIME_SERIES && pd == 10) { /* decennial data */ sd0 = (double) atoi(stobs); } else { int maj = 0, min = 0; if (get_stobs_maj_min(stobs, structure, &maj, &min)) { return invalid_stobs(stobs); } if ((pd == 5 || pd == 6 || pd == 7 || pd == 52) && min == 0 && maybe_tseries) { /* catch undated daily or weekly data */ structure = TIME_SERIES; } else { if (catch_setobs_errors(stobs, pd, min, structure)) { return E_DATA; } else if (pd == 1) { sprintf(stobs, "%d", maj); if (structure == STRUCTURE_UNKNOWN) { if (maj > 1) { structure = TIME_SERIES; /* annual? */ } else { structure = CROSS_SECTION; } } } else { if (structure == TIME_SERIES && min > 0 && !recognized_ts_frequency(pd)) { structure = SPECIAL_TIME_SERIES; } real_format_obs(stobs, maj, min, pd, '.'); if (structure == STRUCTURE_UNKNOWN && recognized_ts_frequency(pd)) { structure = TIME_SERIES; } } } /* for non-calendar data */ sd0 = dot_atof(stobs); } if (!err) { *pstructure = structure; *psd0 = sd0; *pdated = dated; } return err; }