genfuncs

genfuncs

Synopsis

int                 sort_series                         (const double *x,
                                                         double *y,
                                                         int f,
                                                         const DATAINFO *pdinfo);
int                 gretl_sort_by                       (const double *x,
                                                         const double *y,
                                                         double *z,
                                                         const DATAINFO *pdinfo);
int                 rank_series                         (const double *x,
                                                         double *y,
                                                         int f,
                                                         const DATAINFO *pdinfo);
gretl_matrix *      rank_vector                         (const gretl_matrix *x,
                                                         int f,
                                                         int *err);
int                 diff_series                         (const double *x,
                                                         double *y,
                                                         int f,
                                                         const DATAINFO *pdinfo);
int                 orthdev_series                      (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo);
int                 cum_series                          (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo);
int                 resample_series                     (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo);
int                 block_resample_series               (const double *x,
                                                         double *y,
                                                         int blocklen,
                                                         const DATAINFO *pdinfo);
int                 fracdiff_series                     (const double *x,
                                                         double *y,
                                                         double d,
                                                         int diff,
                                                         int obs,
                                                         const DATAINFO *pdinfo);
int                 boxcox_series                       (const double *x,
                                                         double *y,
                                                         double d,
                                                         const DATAINFO *pdinfo);
int                 filter_series                       (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         gretl_matrix *A,
                                                         gretl_matrix *C,
                                                         double y0);
int                 exponential_movavg_series           (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         double d,
                                                         int n);
int                 movavg_series                       (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         int k,
                                                         int center);
int                 seasonally_adjust_series            (const double *x,
                                                         double *y,
                                                         DATAINFO *pdinfo,
                                                         int tramo);
int                 panel_statistic                     (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         int k);
int                 hp_filter                           (const double *x,
                                                         double *hp,
                                                         const DATAINFO *pdinfo,
                                                         double lambda,
                                                         gretlopt opt);
int                 bkbp_filter                         (const double *x,
                                                         double *bk,
                                                         const DATAINFO *pdinfo,
                                                         int bkl,
                                                         int bku,
                                                         int k);
int                 butterworth_filter                  (const double *x,
                                                         double *bw,
                                                         const DATAINFO *pdinfo,
                                                         int n,
                                                         double cutoff);
int                 poly_trend                          (const double *x,
                                                         double *fx,
                                                         const DATAINFO *pdinfo,
                                                         int order);
int                 weighted_poly_trend                 (const double *x,
                                                         double *fx,
                                                         const DATAINFO *pdinfo,
                                                         int order,
                                                         gretlopt opt,
                                                         double wratio,
                                                         double midfrac);
void                poly_weights                        (double *w,
                                                         int T,
                                                         double wmax,
                                                         double midfrac,
                                                         gretlopt opt);
gretl_matrix *      hp_gain                             (double lambda,
                                                         int hipass);
gretl_matrix *      butterworth_gain                    (int n,
                                                         double cutoff,
                                                         int hipass);
int                 dummy                               (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         int center);
int                 panel_dummies                       (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt);
int                 gen_unit                            (double ***pZ,
                                                         DATAINFO *pdinfo);
int                 panel_unit_first_obs                (int t,
                                                         const DATAINFO *pdinfo);
int                 gen_time                            (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         int tm);
int                 gen_wkday                           (double ***pZ,
                                                         DATAINFO *pdinfo);
int                 plotvar_code                        (const DATAINFO *pdinfo);
const double *      gretl_plotx                         (const double **Z,
                                                         const DATAINFO *pdinfo);
double *            get_fit_or_resid                    (const MODEL *pmod,
                                                         DATAINFO *pdinfo,
                                                         ModelDataIndex idx,
                                                         char *vname,
                                                         char *vlabel,
                                                         int *err);
int                 get_observation_number              (const char *s,
                                                         const DATAINFO *pdinfo);
int                 get_t_from_obs_string               (const char *s,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo);
int                 list_linear_combo                   (double *y,
                                                         const int *list,
                                                         const gretl_vector *b,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo);
double              imhof                               (const gretl_matrix *m,
                                                         double arg,
                                                         int *err);
double              dw_pval                             (const gretl_matrix *u,
                                                         const gretl_matrix *X,
                                                         double *pDW,
                                                         int *err);
gretl_matrix *      multi_acf                           (const gretl_matrix *m,
                                                         const int *list,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         int p,
                                                         int *err);
gretl_matrix *      multi_xcf                           (const void *px,
                                                         int xtype,
                                                         const void *py,
                                                         int ytype,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         int p,
                                                         int *err);
gretl_matrix *      forecast_stats                      (const double *y,
                                                         const double *f,
                                                         int t1,
                                                         int t2,
                                                         gretlopt opt,
                                                         int *err);
double              gretl_round                         (double x);
double              gretl_bessel                        (char type,
                                                         double v,
                                                         double x,
                                                         int *err);
double              gretl_npv                           (int t1,
                                                         int t2,
                                                         const double *x,
                                                         double r,
                                                         int pd,
                                                         int *err);
double              gretl_irr                           (const double *x,
                                                         int n,
                                                         int pd,
                                                         int *err);
double              logistic_cdf                        (double x);
gretl_matrix *      matrix_chowlin                      (const gretl_matrix *Y,
                                                         const gretl_matrix *X,
                                                         int f,
                                                         int *err);
int                 list_ok_dollar_vars                 (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         PRN *prn);

Description

Details

sort_series ()

int                 sort_series                         (const double *x,
                                                         double *y,
                                                         int f,
                                                         const DATAINFO *pdinfo);


gretl_sort_by ()

int                 gretl_sort_by                       (const double *x,
                                                         const double *y,
                                                         double *z,
                                                         const DATAINFO *pdinfo);


rank_series ()

int                 rank_series                         (const double *x,
                                                         double *y,
                                                         int f,
                                                         const DATAINFO *pdinfo);


rank_vector ()

gretl_matrix *      rank_vector                         (const gretl_matrix *x,
                                                         int f,
                                                         int *err);


diff_series ()

int                 diff_series                         (const double *x,
                                                         double *y,
                                                         int f,
                                                         const DATAINFO *pdinfo);

Calculates the differenced counterpart to the input series x. If f = F_SDIFF, the seasonal difference is computed; if f = F_LDIFF, the log difference, and if f = F_DIFF, the ordinary first difference.

x :

array of original data.

y :

array into which to write the result.

f :

function, F_DIFF, F_SDIFF or F_LDIFF.

pdinfo :

data set information.

Returns :

0 on success, non-zero error code on failure.

orthdev_series ()

int                 orthdev_series                      (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo);

Calculates in y the forward orthogonal deviations of the input series x. That is, y[t] is the scaled difference between x[t] and the mean of the subsequent observations on x.

x :

array of original data.

y :

array into which to write the result.

pdinfo :

data set information.

Returns :

0 on success, non-zero error code on failure.

cum_series ()

int                 cum_series                          (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo);


resample_series ()

int                 resample_series                     (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo);


block_resample_series ()

int                 block_resample_series               (const double *x,
                                                         double *y,
                                                         int blocklen,
                                                         const DATAINFO *pdinfo);


fracdiff_series ()

int                 fracdiff_series                     (const double *x,
                                                         double *y,
                                                         double d,
                                                         int diff,
                                                         int obs,
                                                         const DATAINFO *pdinfo);

Calculates the fractionally differenced or lagged counterpart to the input series x. The fractional difference operator is defined as (1-L)^d, while the fractional lag operator 1-(1-L)^d.

x :

array of original data.

y :

array into which to write the result.

d :

fraction by which to difference.

diff :

boolean variable 1 for fracdiff, 0 for fraclag

obs :

used for autoreg calculation, -1 if whole series should be calculated otherwise just the observation for obs is calculated

pdinfo :

data set information.

Returns :

0 on success, non-zero error code on failure.

boxcox_series ()

int                 boxcox_series                       (const double *x,
                                                         double *y,
                                                         double d,
                                                         const DATAINFO *pdinfo);

Calculates in y the Box-Cox transformation for the input series x.

x :

array of original data.

y :

array into which to write the result.

d :

lambda parameter.

pdinfo :

data set information.

Returns :

0 on success, non-zero error code on failure.

filter_series ()

int                 filter_series                       (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         gretl_matrix *A,
                                                         gretl_matrix *C,
                                                         double y0);

Filters x according to y_t = C(L)/A(L) x_t. If the intended AR order is p, A should be a vector of length p. If the intended MA order is q, C should be vector of length (q+1), the first entry giving the coefficient at lag 0. However, if C is NULL this is taken to mean that the lag-0 MA coefficient is unity (and all others are zero).

x :

array of original data.

y :

array into which to write the result.

pdinfo :

data set information.

A :

vector for autoregressive polynomial.

C :

vector for moving average polynomial.

y0 :

initial value of output series.

Returns :

0 on success, non-zero error code on failure.

exponential_movavg_series ()

int                 exponential_movavg_series           (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         double d,
                                                         int n);

x :

array of original data.

y :

array into which to write the result.

pdinfo :

data set information.

d :

coefficient on lagged x.

n :

number of x observations to average to give the initial y value.

Returns :

0 on success, non-zero error code on failure.

movavg_series ()

int                 movavg_series                       (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         int k,
                                                         int center);

x :

array of original data.

y :

array into which to write the result.

pdinfo :

data set information.

k :

number of terms in MA.

center :

if non-zero, produce centered MA.

Returns :

0 on success, non-zero error code on failure.

seasonally_adjust_series ()

int                 seasonally_adjust_series            (const double *x,
                                                         double *y,
                                                         DATAINFO *pdinfo,
                                                         int tramo);


panel_statistic ()

int                 panel_statistic                     (const double *x,
                                                         double *y,
                                                         const DATAINFO *pdinfo,
                                                         int k);


hp_filter ()

int                 hp_filter                           (const double *x,
                                                         double *hp,
                                                         const DATAINFO *pdinfo,
                                                         double lambda,
                                                         gretlopt opt);

Calculates the "cycle" component of the time series in array x, using the Hodrick-Prescott filter. Adapted from the original FORTRAN code by E. Prescott.

x :

array of original data.

hp :

array in which filtered series is computed.

pdinfo :

data set information.

lambda :

smoothing parameter (or NADBL to use the default value).

opt :

if OPT_T, return the trend rather than the cycle.

Returns :

0 on success, non-zero error code on failure.

bkbp_filter ()

int                 bkbp_filter                         (const double *x,
                                                         double *bk,
                                                         const DATAINFO *pdinfo,
                                                         int bkl,
                                                         int bku,
                                                         int k);

Calculates the Baxter and King bandpass filter.

x :

array of original data.

bk :

array into which to write the filtered series.

pdinfo :

data set information.

bkl :

lower frequency bound (or 0 for automatic).

bku :

upper frequency bound (or 0 for automatic).

k :

approximation order (or 0 for automatic).

Returns :

0 on success, non-zero error code on failure.

butterworth_filter ()

int                 butterworth_filter                  (const double *x,
                                                         double *bw,
                                                         const DATAINFO *pdinfo,
                                                         int n,
                                                         double cutoff);

Calculates the Butterworth filter. The code that does this is based on D.S.G. Pollock's IDEOLOG -- see http://www.le.ac.uk/users/dsgp1/

x :

array of original data.

bw :

array into which to write the filtered series.

pdinfo :

data set information.

n :

desired lag order.

cutoff :

desired angular cutoff in degrees (0, 180).

Returns :

0 on success, non-zero error code on failure.

poly_trend ()

int                 poly_trend                          (const double *x,
                                                         double *fx,
                                                         const DATAINFO *pdinfo,
                                                         int order);

Calculates a trend via the method of orthogonal polynomials. Based on C code for D.S.G. Pollock's DETREND program.

x :

array of original data.

fx :

array into which to write the fitted series.

pdinfo :

data set information.

order :

desired polynomial order.

Returns :

0 on success, non-zero error code on failure.

weighted_poly_trend ()

int                 weighted_poly_trend                 (const double *x,
                                                         double *fx,
                                                         const DATAINFO *pdinfo,
                                                         int order,
                                                         gretlopt opt,
                                                         double wratio,
                                                         double midfrac);

Calculates a trend via the method of orthogonal polynomials, using the specified weighting scheme. Based on C code for D.S.G. Pollock's DETREND program.

x :

array of original data.

fx :

array into which to write the fitted series.

pdinfo :

data set information.

order :

desired polynomial order.

opt :

weighting option (OPT_Q = quadratic, OPT_B = cosine bell, OPT_C = crenelated).

wratio :

ratio of maximum to minimum weight.

midfrac :

proportion of the data to be treated specially, in the middle.

Returns :

0 on success, non-zero error code on failure.

poly_weights ()

void                poly_weights                        (double *w,
                                                         int T,
                                                         double wmax,
                                                         double midfrac,
                                                         gretlopt opt);

Calculates a set of weights; intended for use with polynomial trend fitting.

w :

array into which the weights will be written.

T :

the length of w.

wmax :

the ratio of maximum to minimum weight.

midfrac :

the size of the central section that should be given the minimum weight.

opt :

weighting scheme option (OPT_Q = quadratic, OPT_B = cosine bell, OPT_C = crenelated).

hp_gain ()

gretl_matrix *      hp_gain                             (double lambda,
                                                         int hipass);

lambda :

H-P parameter.

hipass :

1 for high-pass filter, 0 for low-pass.

Returns :

a matrix holding omega values from 0 to \pi in column 0, and the corresponding filter gain in column 1.

butterworth_gain ()

gretl_matrix *      butterworth_gain                    (int n,
                                                         double cutoff,
                                                         int hipass);

n :

order of the filter.

cutoff :

angular cutoff in radians.

hipass :

1 for high-pass filter, 0 for low-pass.

Returns :

a matrix holding omega values from 0 to \pi in column 0, and the corresponding filter gain in column 1.

dummy ()

int                 dummy                               (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         int center);

Adds to the data set (if these variables are not already present) a set of periodic (usually seasonal) dummy variables.

pZ :

pointer to data matrix.

pdinfo :

data information struct.

center :

if greater than zero subtract the population mean from each of the generated dummies; if less than zero, do not subtract the mean but generate dummies with labels on the same pattern as centered dummies (for internal use in VECMs). Usually this argument is set to zero.

Returns :

the ID number of the first dummy variable on success, or 0 on error.

panel_dummies ()

int                 panel_dummies                       (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         gretlopt opt);

Adds to the data set a set of dummy variables corresponding to either the cross-sectional units in a panel, or the time periods.

pZ :

pointer to data matrix.

pdinfo :

data information struct.

opt :

OPT_T for time dummies, otherwise unit dummies.

Returns :

0 on successful completion, error code on error.

gen_unit ()

int                 gen_unit                            (double ***pZ,
                                                         DATAINFO *pdinfo);

(For panel data only) adds to the data set an index variable that uniquely identifies the cross-sectional units.

pZ :

pointer to data matrix.

pdinfo :

data information struct.

Returns :

0 on successful completion, error code on error.

panel_unit_first_obs ()

int                 panel_unit_first_obs                (int t,
                                                         const DATAINFO *pdinfo);

t :

zero-based observation number.

pdinfo :

data information struct.

Returns :

1 if observation t is the first time-series observation on a given cross-sectional unit in a panel dataset, else 0.

gen_time ()

int                 gen_time                            (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         int tm);

Generates (and adds to the dataset, if it's not already present) a time-trend or index variable. This function is panel-data aware: if the dataset is a panel and tm is non-zero, the trend will not simply run consecutively over the entire range of the data, but will correctly represent the location in time of each observation. The index is 1-based.

pZ :

pointer to data array.

pdinfo :

data information struct.

tm :

if non-zero, an actual time trend is wanted, otherwise just an index of observations.

Returns :

0 on success, non-zero on error.

gen_wkday ()

int                 gen_wkday                           (double ***pZ,
                                                         DATAINFO *pdinfo);


plotvar_code ()

int                 plotvar_code                        (const DATAINFO *pdinfo);


gretl_plotx ()

const double *      gretl_plotx                         (const double **Z,
                                                         const DATAINFO *pdinfo);

Finds or creates a special dummy variable for use on the x-axis in plotting; this will have the full length of the data series as given in pdinfo, and will be appropriately configured for the data frequency. Do not try to free this variable.

pdinfo :

data information struct.

Returns :

pointer to plot x-variable, or NULL on failure.

get_fit_or_resid ()

double *            get_fit_or_resid                    (const MODEL *pmod,
                                                         DATAINFO *pdinfo,
                                                         ModelDataIndex idx,
                                                         char *vname,
                                                         char *vlabel,
                                                         int *err);

Creates a full-length array holding the specified model data, and writes name and description into the vname and vlabel.

pmod :

pointer to source model.

pdinfo :

information on the data set.

idx :

M_UHAT, M_UHAT2, M_YHAT, M_AHAT or M_H.

vname :

location to write series name (length VNAMELEN)

vlabel :

location to write series description (length should be MAXLABEL).

err :

location to receive error code.

Returns :

allocated array on success or NULL on failure.

get_observation_number ()

int                 get_observation_number              (const char *s,
                                                         const DATAINFO *pdinfo);


get_t_from_obs_string ()

int                 get_t_from_obs_string               (const char *s,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo);


list_linear_combo ()

int                 list_linear_combo                   (double *y,
                                                         const int *list,
                                                         const gretl_vector *b,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo);


imhof ()

double              imhof                               (const gretl_matrix *m,
                                                         double arg,
                                                         int *err);


dw_pval ()

double              dw_pval                             (const gretl_matrix *u,
                                                         const gretl_matrix *X,
                                                         double *pDW,
                                                         int *err);


multi_acf ()

gretl_matrix *      multi_acf                           (const gretl_matrix *m,
                                                         const int *list,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         int p,
                                                         int *err);


multi_xcf ()

gretl_matrix *      multi_xcf                           (const void *px,
                                                         int xtype,
                                                         const void *py,
                                                         int ytype,
                                                         const double **Z,
                                                         const DATAINFO *pdinfo,
                                                         int p,
                                                         int *err);


forecast_stats ()

gretl_matrix *      forecast_stats                      (const double *y,
                                                         const double *f,
                                                         int t1,
                                                         int t2,
                                                         gretlopt opt,
                                                         int *err);


gretl_round ()

double              gretl_round                         (double x);


gretl_bessel ()

double              gretl_bessel                        (char type,
                                                         double v,
                                                         double x,
                                                         int *err);


gretl_npv ()

double              gretl_npv                           (int t1,
                                                         int t2,
                                                         const double *x,
                                                         double r,
                                                         int pd,
                                                         int *err);


gretl_irr ()

double              gretl_irr                           (const double *x,
                                                         int n,
                                                         int pd,
                                                         int *err);


logistic_cdf ()

double              logistic_cdf                        (double x);


matrix_chowlin ()

gretl_matrix *      matrix_chowlin                      (const gretl_matrix *Y,
                                                         const gretl_matrix *X,
                                                         int f,
                                                         int *err);

Interpolate, from annual to quarterly or quarterly to monthly, via the Chow-Lin method. See Gregory C. Chow and An-loh Lin, "Best Linear Unbiased Interpolation, Distribution, and Extrapolation of Time Series by Related Series", The Review of Economics and Statistics, Vol. 53, No. 4 (November 1971) pp. 372-375.

If X is provided, it must have T * f rows.

Y :

T x k: holds the original data to be expanded, series in columns.

X :

(optionally) holds covariates of Y at the higher frequency: if these are supplied they supplement the default set of regressors, namely, constant plus quadratic trend.

f :

the expansion factor: 3 for quarterly to monthly or 4 for annual to quarterly. Only these factors are supported.

err :

location to receive error code.

Returns :

matrix containing the expanded series, or NULL on failure.

list_ok_dollar_vars ()

int                 list_ok_dollar_vars                 (double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         PRN *prn);