static void audioprint_summary (Summary *summ, const DATASET *dset, PRN *prn) { char date1[OBSLEN], date2[OBSLEN]; int lo = summ->list[0], i, vi; ntodate(date1, dset->t1, dset); ntodate(date2, dset->t2, dset); if (lo == 1) { pprintf(prn, "Summary Statistics for the variable '%s' using the " "observations %s to %s.\n", dset->varname[summ->list[1]], date1, date2); } else { pprintf(prn, "Summary Statistics, using the observations %s to %s.\n", date1, date2); } for (i=0; i<summ->list[0]; i++) { vi = summ->list[i + 1]; if (lo > 1) { pprintf(prn, "%s, ", dset->varname[vi]); } pprintf(prn, "mean, %.4g,\n", summ->mean[i]); pprintf(prn, "median, %.4g,\n", summ->median[i]); pprintf(prn, "minimum, %.4g,\n", summ->low[i]); pprintf(prn, "maximum, %.4g,\n", summ->high[i]); pprintf(prn, "standard deviation, %.4g.\n", summ->sd[i]); } }
static void audioprint_matrix (const VMatrix *vmat, const DATASET *dset, PRN *prn) { int i, j, k; int n = vmat->t2 - vmat->t1 + 1; int lo = vmat->dim; if (vmat->ci == CORR) { char date1[OBSLEN], date2[OBSLEN]; ntodate(date1, vmat->t1, dset); ntodate(date2, vmat->t2, dset); pprintf(prn, "Correlation coefficients, using the observations " "%s to %s.\n", date1, date2); pprintf(prn, " The 5%% critical value (two-tailed) is %.3f.\n", rhocrit95(n)); } else { pputs(prn, "Coefficient covariance matrix.\n"); } for (i=1; i<=lo; i++) { for (j=i; j<=lo; j++) { k = ijton(i-1, j-1, lo); if (i == j) { if (vmat->ci == CORR) { continue; } pprintf(prn, "%s, ", vmat->names[i-1]); } else { pprintf(prn, "%s and %s, ", vmat->names[i-1], vmat->names[j-1]); } if (vmat->ci == CORR) { pprintf(prn, "%.3f.\n", vmat->vec[k]); } else { pprintf(prn, "%.4g.\n", vmat->vec[k]); } } } }
static void audioprint_model (MODEL *pmod, const DATASET *dset, PRN *prn) { char startdate[OBSLEN], enddate[OBSLEN]; if (pmod->ci != OLS) { pputs(prn, "Sorry, this model is not O.L.S. I can't read it.\n"); return; } ntodate(startdate, pmod->t1, dset); ntodate(enddate, pmod->t2, dset); pprintf(prn, "O.L.S estimates using the %d observations %s to %s.\n", pmod->nobs, startdate, enddate); pprintf(prn, "Dependent variable %s.\n", dset->varname[pmod->list[1]]); audioprint_coefficients(pmod, dset, prn); audio_rsqline(pmod, prn); }
static void make_confirmation_text (char *ctxt, DATASET *dwinfo, gretlopt *flags) { if (dwinfo->structure == CROSS_SECTION) { sprintf(ctxt, _("%s, observations 1 to %d"), _("Cross-sectional data"), dataset->n); } else if (time_series(dwinfo)) { int lastobs = dwinfo->t1 + dataset->n - 1; char stobs[OBSLEN]; char endobs[OBSLEN]; const char *tslabel; tslabel = _(ts_frequency_string(dwinfo)); if (lastobs > dwinfo->n - 1) { dwinfo->n = lastobs + 1; } ntodate(stobs, dwinfo->t1, dwinfo); ntodate(endobs, lastobs, dwinfo); sprintf(ctxt, _("%s, %s to %s"), tslabel, stobs, endobs); } else if (dwinfo->structure == PANEL_UNKNOWN) { sprintf(ctxt, _("Panel data (%s)\n" "%d cross-sectional units observed over %d periods"), _("stacked time series"), dwinfo->n, dwinfo->pd); } else if (known_panel(dwinfo)) { int nunits = dwinfo->t1; int nperiods = dataset->n / nunits; sprintf(ctxt, _("Panel data (%s)\n" "%d cross-sectional units observed over %d periods"), (dwinfo->structure == STACKED_TIME_SERIES)? _("stacked time series") : _("stacked cross sections"), nunits, nperiods); } if (*flags & DW_DROPMISS) { strcat(ctxt, "\n"); strcat(ctxt, _("(dropping missing observations)")); } }
static gboolean obs_button_output (GtkSpinButton *spin, gpointer p) { gpointer rset; gchar buf[OBSLEN]; int n = gtk_spin_button_get_value_as_int(spin); ntodate(buf, n, (DATASET *) p); if (strcmp(buf, gtk_entry_get_text(GTK_ENTRY(spin)))) { gtk_entry_set_text(GTK_ENTRY(spin), buf); } rset = g_object_get_data(G_OBJECT(spin), "rset"); if (rset != NULL) { update_obs_label(NULL, rset); } return TRUE; }
static gint32 get_stata_t0 (const DATASET *dset, char *timevar, int *add_time) { gint32 t0 = 0; char obs[OBSLEN]; *timevar = '\0'; ntodate(obs, dset->t1, dset); if (dset->pd == 1 && dset->sd0 > 999) { /* we just want the year */ t0 = atoi(obs); strcpy(timevar, "year"); *add_time = TIME_AUTO; } else if ((dset->pd == 4 || dset->pd == 12) && dset->sd0 > 999) { /* quarters or months since the start of 1960 */ int y, p; char c; sscanf(obs, "%d%c%d", &y, &c, &p); t0 = dset->pd * (y - 1960) + p - 1; strcpy(timevar, dset->pd == 4 ? "quarter" : "month"); *add_time = TIME_AUTO; } else if (calendar_data(dset)) { strcpy(timevar, "date"); *add_time = TIME_CAL; } else { t0 = atoi(obs); strcpy(timevar, "generic_t"); *add_time = TIME_AUTO; } if (*timevar != '\0') { /* don't collide with regular series */ if (current_series_index(dset, timevar) > 0) { strncat(timevar, "_t", 2); } } return t0; }
char *retrieve_date_string (int t, const DATASET *dset, int *err) { char *ret = NULL; if (t <= 0 || t > dset->n) { *err = E_DATA; } else if (dset->S != NULL) { ret = gretl_strdup(dset->S[t-1]); if (ret == NULL) { *err = E_ALLOC; } } else { char datestr[OBSLEN] = {0}; ntodate(datestr, t - 1, dset); ret = gretl_strdup(datestr); if (ret == NULL) { *err = E_ALLOC; } } return ret; }
void set_sample_label (DATASET *dset) { GtkWidget *dlabel; char tmp[256]; int tsubset; if (mdata == NULL) { return; } /* set the sensitivity of various menu items */ time_series_menu_state(dataset_is_time_series(dset)); panel_menu_state(dataset_is_panel(dset)); ts_or_panel_menu_state(dataset_is_time_series(dset) || dataset_is_panel(dset)); flip(mdata->ui, "/menubar/Data/DataTranspose", !dataset_is_panel(dset)); tsubset = dset->t1 > 0 || dset->t2 < dset->n - 1; /* construct label showing summary of dataset/sample info (this goes at the foot of the window) */ if (complex_subsampled() && !tsubset && dataset_is_cross_section(dset)) { sprintf(tmp, _("Undated: Full range n = %d; current sample" " n = %d"), get_full_length_n(), dataset->n); gtk_label_set_text(GTK_LABEL(mdata->status), tmp); } else if (complex_subsampled() && dataset_is_panel(dset)) { char t1str[OBSLEN], t2str[OBSLEN]; const char *pdstr = get_pd_string(dset); ntodate(t1str, dset->t1, dset); ntodate(t2str, dset->t2, dset); sprintf(tmp, _("%s; sample %s - %s"), _(pdstr), t1str, t2str); gtk_label_set_text(GTK_LABEL(mdata->status), tmp); } else { char t1str[OBSLEN], t2str[OBSLEN]; const char *pdstr = get_pd_string(dset); if (tsubset && calendar_data(dset)) { /* it's too verbose to print both full range and sample */ ntodate(t1str, dset->t1, dset); ntodate(t2str, dset->t2, dset); sprintf(tmp, _("%s; sample %s - %s"), _(pdstr), t1str, t2str); gtk_label_set_text(GTK_LABEL(mdata->status), tmp); } else { ntodate(t1str, 0, dset); ntodate(t2str, dset->n - 1, dset); sprintf(tmp, _("%s: Full range %s - %s"), _(pdstr), t1str, t2str); if (tsubset) { gchar *fulltext; ntodate(t1str, dset->t1, dset); ntodate(t2str, dset->t2, dset); fulltext = g_strdup_printf(_("%s; sample %s - %s"), tmp, t1str, t2str); gtk_label_set_text(GTK_LABEL(mdata->status), fulltext); g_free(fulltext); } else { gtk_label_set_text(GTK_LABEL(mdata->status), tmp); } } } /* construct label with datafile name (this goes above the data series window) */ dlabel = g_object_get_data(G_OBJECT(mdata->main), "dlabel"); if (dlabel != NULL) { if (strlen(datafile) > 2) { /* data file open already */ const char *p = strrchr(datafile, SLASH); gchar *trfname; if (p != NULL) { trfname = my_filename_to_utf8(p + 1); } else { trfname = my_filename_to_utf8(datafile); } strcpy(tmp, " "); if (data_status & SESSION_DATA) { sprintf(tmp + 1, "Imported %s", trfname); } else if (data_status & MODIFIED_DATA) { sprintf(tmp + 1, "%s *", trfname); } else { sprintf(tmp + 1, "%s", trfname); } gtk_label_set_text(GTK_LABEL(dlabel), tmp); g_free(trfname); } else if (data_status & MODIFIED_DATA) { strcpy(tmp, _(" Unsaved data ")); gtk_label_set_text(GTK_LABEL(dlabel), tmp); } } if (complex_subsampled() || dset->t1 > 0 || dset->t2 < dset->n - 1) { restore_sample_state(TRUE); } console_record_sample(dataset); }
DATASET *midas_aux_dataset (const int *list, const DATASET *dset, int *err) { DATASET *mset = NULL; gretlopt opt = 0; int mpd, pd = dset->pd; int T, m = list[0]; int yr, mon; int daily = 0; if (m < 3 || gretl_list_has_separator(list)) { *err = E_INVARG; } else if (!dataset_is_time_series(dset)) { *err = E_INVARG; } else if (pd != 1 && pd != 4 && pd != 12) { /* host dataset should be annual, quarterly or monthly */ *err = E_PDWRONG; } if (*err) { return NULL; } if (pd == 1) { /* annual: midas series should be quarterly or monthly */ if (m != 4 && m != 12) { *err = E_INVARG; } else { mpd = m; } } else if (pd == 4) { /* quarterly: midas series should be monthly or daily */ if (m == 3) { mpd = 12; } else if (m == midas_days_per_period(5, 4)) { mpd = 5; } else if (m == midas_days_per_period(6, 4)) { mpd = 6; } else if (m == midas_days_per_period(7, 4)) { mpd = 7; } else { *err = E_INVARG; } } else { /* monthly: midas series should be daily */ if (m == midas_days_per_period(5, 12)) { mpd = 5; } else if (m == midas_days_per_period(6, 12)) { mpd = 6; } else if (m == midas_days_per_period(7, 12)) { mpd = 7; } else { *err = E_INVARG; } } if (*err) { return NULL; } if (!gretl_is_midas_list(list, dset)) { gretl_warnmsg_set("The argument does not seem to be a MIDAS list"); } T = sample_size(dset) * m; if (mpd >= 5 && mpd <= 7) { /* we'll add markers for daily dates */ daily = 1; opt = OPT_M; } mset = create_auxiliary_dataset(1, T, opt); if (mset == NULL) { *err = E_ALLOC; } if (!*err) { char *p, obs[OBSLEN]; int nonex, qtr = 0; int i, t, s, m3 = 0; mset->pd = mpd; mset->structure = TIME_SERIES; strcpy(mset->varname[0], dset->varname[list[1]]); p = strrchr(mset->varname[0], '_'); if (p != NULL) *p = '\0'; ntodate(obs, dset->t1, dset); if (mpd == 4) { sprintf(mset->stobs, "%d:1", atoi(obs)); } else if (mpd == 12) { sprintf(mset->stobs, "%d:01", atoi(obs)); } if (daily && pd == 4) { m3 = m / 3; } /* loop across observations in low-frequency dataset */ s = 0; for (t=dset->t1; t<=dset->t2; t++) { if (daily) { ntodate(obs, t, dset); sscanf(obs, "%d:%d", &yr, &mon); if (pd == 4) { qtr = mon; } } /* read data right-to-left! */ for (i=m; i>0; i--) { int vi = list[i]; if (daily) { if (pd == 4) { mon = quarter_to_month(qtr, m, m-i+1); nonex = daily_index_to_date(mset->S[s], yr, mon, (m-i) % m3, mpd); } else { nonex = daily_index_to_date(mset->S[s], yr, mon, m-i, mpd); } if (nonex) { /* skip any non-existent daily dates */ mset->t2 -= 1; } else { mset->Z[0][s++] = dset->Z[vi][t]; } } else { mset->Z[0][s++] = dset->Z[vi][t]; } } } if (daily) { strcpy(mset->stobs, mset->S[0]); strcpy(mset->endobs, mset->S[mset->t2]); mset->markers = DAILY_DATE_STRINGS; } mset->sd0 = get_date_x(mset->pd, mset->stobs); if (!daily) { ntodate(mset->endobs, mset->t2, mset); } } return mset; }
static void compute_default_ts_info (DATASET *dwinfo) { #if DWDEBUG char obsstr[OBSLEN]; fprintf(stderr, "compute_ts_info() called: pd=%d, structure=%d\n", dwinfo->pd, dwinfo->structure); if (dwinfo->pd == PD_SPECIAL) { fprintf(stderr, "breakage: pd = PD_SPECIAL\n"); } #endif if (dwinfo->pd < 0) { dwinfo->pd = 1; } if (dwinfo->structure == SPECIAL_TIME_SERIES) { /* non-standard time series */ dwinfo->n = 9999 * dwinfo->pd; dwinfo->t1 = 0; if (dwinfo->pd > 1) { int p = dwinfo->pd; strcpy(dwinfo->stobs, "1:"); while ((p = p / 10) > 0) { strcat(dwinfo->stobs, "0"); } strcat(dwinfo->stobs, "1"); } else { strcpy(dwinfo->stobs, "1"); } } else if (dwinfo->pd == 1) { strcpy(dwinfo->stobs, "1"); dwinfo->n = 2100; dwinfo->t1 = 1959; /* 1960 */ } else if (dwinfo->pd == 10) { int dd = default_start_decade(); sprintf(dwinfo->stobs, "%d", dd); if (dd > 1700) { dwinfo->n = 30; dwinfo->t1 = 0; } else { dwinfo->n = 40; dwinfo->t1 = 25; } } else if (dwinfo->pd == 4) { strcpy(dwinfo->stobs, "1700:1"); dwinfo->n = 1400; dwinfo->t1 = 1040; /* 1960:1 */ } else if (dwinfo->pd == 12) { strcpy(dwinfo->stobs, "1700:01"); dwinfo->n = 4200; dwinfo->t1 = 3120; /* 1960:01 */ } else if (dwinfo->pd == 24) { strcpy(dwinfo->stobs, "1:01"); dwinfo->n = 1500; dwinfo->t1 = 0; } else if (dwinfo->pd == 52) { if (dwinfo->v >= 7) { dwinfo->n = 500; dwinfo->t1 = 0; strcpy(dwinfo->stobs, "1"); } else { make_weekly_stobs(dwinfo); dwinfo->n = 13000; dwinfo->t1 = 7826; } } else if (dwinfo->pd == 5 || dwinfo->pd == 6 || dwinfo->pd == 7) { strcpy(dwinfo->stobs, "1900-01-01"); dwinfo->n = 50000; /* set default start to 1960-01-01 (a Friday) */ if (dwinfo->pd == 5) { dwinfo->t1 = 15654; } else if (dwinfo->pd == 6) { dwinfo->t1 = 18784; } else { dwinfo->t1 = 21914; } } dwinfo->sd0 = get_date_x(dwinfo->pd, dwinfo->stobs); if (dataset->structure == TIME_SERIES && dataset->pd == dwinfo->pd) { /* make the current start the default */ dwinfo->t1 = dateton(dataset->stobs, dwinfo); } ntodate(dwinfo->endobs, dwinfo->n - 1, dwinfo); #if DWDEBUG ntodate(obsstr, dwinfo->t1, dwinfo); fprintf(stderr, "dwinfo: v=%d, pd=%d, stobs='%s', endobs='%s', sd0=%g, t1=%d (%s)\n", dwinfo->v, dwinfo->pd, dwinfo->stobs, dwinfo->endobs, dwinfo->sd0, dwinfo->t1, obsstr); ntodate(obsstr, dataset->t1, dataset); fprintf(stderr, "dataset: pd=%d, stobs='%s', sd0=%g, t1=%d (%s)\n", dataset->pd, dataset->stobs, dataset->sd0, dataset->t1, obsstr); #endif }
static int dwiz_make_changes (DATASET *dwinfo, dw_opts *opts, GtkWidget *dlg) { gchar *setobs_cmd = NULL; gretlopt opt = OPT_NONE; int create = (opts->flags & DW_CREATE); int delmiss = (opts->flags & DW_DROPMISS); int delete_markers = 0; int err = 0; #if DWDEBUG fprintf(stderr, "dwiz_make_changes: create = %d\n", create); #endif /* preliminaries */ if (time_series(dwinfo)) { ntodate(dwinfo->stobs, dwinfo->t1, dwinfo); } else if (known_panel(dwinfo)) { if (!dataset_is_panel(dataset)) { /* Turning a subset of a non-panel dataset into a panel: this change will be irreversible */ maybe_unrestrict_dataset(); } } /* special: reorganizing dataset based on panel index vars */ if (dwinfo->structure == PANEL_UNKNOWN) { int uv, tv; err = translate_panel_vars(opts, &uv, &tv); if (!err) { err = set_panel_structure_from_vars(uv, tv, dataset); } if (!err) { setobs_cmd = g_strdup_printf("setobs %s %s --panel-vars", dataset->varname[uv], dataset->varname[tv]); } goto finalize; } /* check for nothing to be done */ if (dwinfo->structure == dataset->structure && dwinfo->pd == dataset->pd && strcmp(dwinfo->stobs, dataset->stobs) == 0) { if (create || delmiss) { /* recording? */ goto finalize; } else { infobox(_("No changes were made")); return 0; } } /* if converting to time series, we probably don't want to retain any original observation-marker strings */ if (dwinfo->structure == TIME_SERIES && dataset->markers && !delmiss) { delete_markers = 1; } /* handle panel structure */ if (known_panel(dwinfo)) { int nunits = dwinfo->t1; int nperiods = dataset->n / nunits; /* we don't offer a choice of "starting obs" */ dwinfo->pd = (dwinfo->structure == STACKED_TIME_SERIES)? nperiods : nunits; strcpy(dwinfo->stobs, "1.1"); } /* handle conversion to cross-section */ if (dwinfo->structure == CROSS_SECTION) { strcpy(dwinfo->stobs, "1"); } if (dwinfo->structure == TIME_SERIES) { opt = OPT_T; } else if (dwinfo->structure == STACKED_TIME_SERIES) { opt = OPT_S; } else if (dwinfo->structure == STACKED_CROSS_SECTION) { opt = OPT_C; } else if (dwinfo->structure == CROSS_SECTION) { opt = OPT_X; } else if (dwinfo->structure == SPECIAL_TIME_SERIES) { opt = OPT_N; } err = simple_set_obs(dataset, dwinfo->pd, dwinfo->stobs, opt); #if DWDEBUG fprintf(stderr, "pd=%d, stobs='%s', opt=%d; set_obs returned %d\n", dwinfo->pd, dwinfo->stobs, opt, err); #endif if (!err && setobs_cmd == NULL) { setobs_cmd = g_strdup_printf("setobs %d %s%s", dwinfo->pd, dwinfo->stobs, print_flags(opt, SETOBS)); } finalize: if (!err && delmiss) { err = dataset_purge_missing_rows(dataset); } if (err) { gui_errmsg(err); } else if (create) { if (opts->flags & DW_SSHEET) { gtk_widget_hide(dlg); maybe_start_editing(); } else { register_data(NULLDATA_STARTED); lib_command_sprintf("nulldata %d", dataset->n); record_command_verbatim(); } } else { if (delete_markers) { dataset_destroy_obs_markers(dataset); } mark_dataset_as_modified(); } if (!err && setobs_cmd != NULL) { lib_command_strcpy(setobs_cmd); record_command_verbatim(); } g_free(setobs_cmd); #if DWDEBUG fprintf(stderr, "dwiz_make_changes: returning %d\n", err); #endif return err; }
int set_obs (const char *line, DATASET *dset, gretlopt opt) { char pdstr[VNAMELEN]; char stobs[OBSLEN]; int structure = STRUCTURE_UNKNOWN; double sd0 = dset->sd0; int pd, dated = 0; int panel = 0; int err = 0; if (dset == NULL) { return E_NODATA; } if ((opt & (OPT_R | OPT_P)) && dset->Z == NULL) { return E_NODATA; } if ((opt & (OPT_G | OPT_I)) && !dataset_is_panel(dset)) { return E_DATA; } gretl_error_clear(); if (opt & OPT_R) { /* restructure panel: "hidden" option */ return switch_panel_orientation(dset); } if (!strcmp(line, "setobs")) { /* we'll just print current obs info */ return 0; } if (opt & OPT_P) { return set_panel_structure_from_line(line, dset); } else if (opt & OPT_G) { /* --panel-groups */ return set_panel_group_strings(line, dset); } /* now we get down to business */ if (sscanf(line, "%*s %15s %10s", pdstr, stobs) != 2) { gretl_errmsg_set(_("Failed to parse line as frequency, startobs")); return E_PARSE; } pd = gretl_int_from_string(pdstr, &err); if (!err && pd < 1) { gretl_errmsg_sprintf(_("frequency (%d) does not make seem to make sense"), pd); err = E_DATA; } if (err) { return err; } /* if an explicit structure option was passed in, respect it */ if (opt == OPT_X) { structure = CROSS_SECTION; } else if (opt == OPT_T) { structure = TIME_SERIES; } else if (opt == OPT_S) { structure = STACKED_TIME_SERIES; panel = 1; } else if (opt == OPT_C) { structure = STACKED_CROSS_SECTION; panel = 1; } else if (opt == OPT_N) { structure = SPECIAL_TIME_SERIES; } else if (opt == OPT_I) { /* --panel-time */ structure = TIME_SERIES; } if (panel && dset->n > 0 && pd > dset->n) { gretl_errmsg_sprintf(_("frequency (%d) does not make seem to make sense"), pd); return 1; } err = process_starting_obs(stobs, pd, &structure, &sd0, &dated); if (err) { return err; } if (opt == OPT_I) { dset->panel_pd = pd; dset->panel_sd0 = sd0; return 0; } if (panel && dset->n % pd != 0) { int sts = structure == STACKED_TIME_SERIES; gretl_errmsg_sprintf(_("Panel datasets must be balanced.\n" "The number of observations (%d) is not a multiple\n" "of the number of %s (%d)."), dset->n, sts ? _("periods") : _("units"), pd); return E_DATA; } if (dated) { /* replace any existing markers with date strings */ dataset_destroy_obs_markers(dset); } else if (structure == TIME_SERIES && (pd == 1 || pd == 4 || pd == 12)) { /* force use of regular time-series obs labels */ dataset_destroy_obs_markers(dset); } dset->pd = pd; dset->structure = structure; dset->sd0 = sd0; ntodate(dset->stobs, 0, dset); ntodate(dset->endobs, dset->n - 1, dset); /* pre-process stacked cross-sectional panels: put into canonical stacked time series form */ if (dset->structure == STACKED_CROSS_SECTION) { if (dset->Z == NULL) { err = E_NODATA; } else { err = switch_panel_orientation(dset); } } return err; }
static int parse_wf1_header (FILE *fp, int ftype, DATASET *dset, unsigned *offset) { int nvars = 0, nobs = 0, startyr = 0; short pd = 0, startper = 0; unsigned off; int err = 0; fseek(fp, 80, SEEK_SET); off = read_unsigned(fp, &err); *offset = off + 26; fseek(fp, 114, SEEK_SET); nvars = read_int(fp, &err); fseek(fp, 124, SEEK_SET); pd = read_short(fp, &err); fseek(fp, 128, SEEK_SET); startyr = read_int(fp, &err); fseek(fp, 132, SEEK_SET); startper = read_short(fp, &err); fseek(fp, 140, SEEK_SET); nobs = read_int(fp, &err); #if EVDEBUG > 1 analyse_mystery_vals(fp); #endif if (pd == 1) { startper = 0; } if (nvars <= 2 || nobs <= 0 || startyr < 0 || pd <= 0 || startper < 0) { err = E_DATA; fprintf(stderr, "header info:\n" " nvars = %d\n" " nobs = %d\n" " pd = %d\n" " starting year or major = %d\n" " starting sub-period or minor = %d\n", nvars, nobs, (int) pd, startyr, (int) startper); } else { dset->v = nvars - 2; /* skip C and RESID */ dset->n = nobs; dset->pd = pd; fprintf(stderr, "header info:\n" " number of variables = %d\n" " number of observations = %d\n" " data frequency = %d\n" " starting year or major = %d\n" " starting sub-period or minor = %d\n", dset->v, dset->n, dset->pd, startyr, (int) startper); } if (!err) { if (startper > 0) { int p10 = log(pd) / log(10.0); if (p10 > 0) { char fmt[16]; sprintf(fmt, "%%d:%%0%dd", p10 + 1); sprintf(dset->stobs, fmt, startyr, startper); } else { sprintf(dset->stobs, "%d:%d", startyr, startper); } } else { sprintf(dset->stobs, "%d", startyr); } if (dset->pd > 1 || startyr > 10) { dset->structure = TIME_SERIES; } dset->sd0 = get_date_x(dset->pd, dset->stobs); ntodate(dset->endobs, dset->n - 1, dset); } return err; }