Hi Allin,

Thanks for your prompt help. This is really very much helpful for me.

Just to check with you, I am getting linker error for the function dataset_set_time_series(dset, 4, 1980, 1); I have build the latest source from CVS. Do you have any idea. If I comment that line, things are just fine.

Thanks,
Sanzad

On Tue, Oct 16, 2012 at 12:31 PM, Allin Cottrell <cottrell@wfu.edu> wrote:
On Mon, 15 Oct 2012, Sanzad Siddique wrote:

> I would like to generate an arma dataset using libgretl which is same as
> the datase created by below code:
>
> nulldata 2000
> setobs 7 2006/06/02
> series a = normal()
> series z = 0
> z = 0.4*z(-1) + 0.40*z(-2) + a + 0.5*a(-1) + 0.6*a(-2)
> z1 = z-mean(z)
> z2 = z/sd(z)
> z3 = (z-mean(z))/sd(z)
>
> I have started with  DATASET *dset = create_new_dataset(3, 2000, 0); and
> don't know how to move further. Is there any sample code for data series
> generation like above? can anyone help?

As it happens I've been working with something very similar
lately, so here's a stripped-down version of my program (it
requires current CVS for a couple of small things):

<C>
#include <gretl/libgretl.h>

static int make_ARMA_data (int nobs, PRN *prn)
{
     DATASET *dset;
     gretl_matrix *A;
     gretl_matrix *B;
     double *y, *eps, *u;
     double mu = 4.0;
     int Nrep = 1;
     int k, t;

     dset = create_new_dataset(4, nobs, 0);
     dataset_set_time_series(dset, 4, 1980, 1);
     dataset_rename_series(dset, 1, "y");
     dataset_rename_series(dset, 2, "eps");
     dataset_rename_series(dset, 3, "u");

     y   = dset->Z[1];
     eps = dset->Z[2];
     u   = dset->Z[3];

     /* simulated data spec:
        y = mu + u(t)
        u(t) = 0.5*u(t-1) + eps(t) + 0.3*eps(t-1)
     */

     /* AR term */
     A = gretl_vector_alloc(1);
     A->val[0] = 0.5;

     /* MA terms */
     B = gretl_vector_alloc(2);
     B->val[0] = 1;
     B->val[1] = 0.3;

     for (k=0; k<Nrep; k++) {
        gretl_rand_normal_full(eps, 0, dset->n-1, 0.0, 1.0);
        filter_series(eps, u, dset, A, B, 0.0);
        for (t=0; t<dset->n; t++) {
            y[t] = mu + u[t];
        }
        printdata(NULL, NULL, dset, OPT_O, prn);
        /* now actually do stuff with data */
     }

     gretl_matrix_free(A);
     gretl_matrix_free(B);
     destroy_dataset(dset);

     return 0;
}

int main (void)
{
     PRN *prn;
     int nobs = 50;
     int err = 0;

     libgretl_init();
     prn = gretl_print_new(GRETL_PRINT_STDOUT, &err);

     make_ARMA_data(nobs, prn);

     gretl_print_destroy(prn);
     libgretl_cleanup();

     return 0;
}
</C>

Allin Cottrell
_______________________________________________
Gretl-devel mailing list
Gretl-devel@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel