On Sun, 4 Jul 2010, Joel Bycraft wrote:
I am approaching the library in this way as I need to run
estimation on a window of data, and then increment forward
throughout a time series period, with a moving window. So, for
each period t, I need to estmate the residuals from the previous
X days, based on a regression from the same previous x days. On
day t+1 is another regression, etc.
If you have a preferred way for me to do this, certainly let me
know...
You can do something like this:
open data9-7
series uhat
# the first five-year window
smpl 1975:1 1979:4
loop 10
ols 1 0 2 --quiet
uhat = $uhat
print uhat # or do something else with it
# advance the window by one quarter
smpl +1 +1
endloop
I have it all working with OLS at the moment, I can get
residuals and it matches gretl. The only thing missing is the
coefficients of the constant and independent variable...
[ trouble with gretl_model_get_matrix() ]
I just tested here with the following code (assuming that Z and
the DATAINFO pointer pdinfo and present and correct):
<code-fragment>
MODEL *model = gretl_model_new();
int list[] = {3, 1, 0, 2};
gretl_matrix *b;
*model = lsq(list, &Z, pdinfo, OLS, OPT_NONE);
if (model->errcode) {
pprintf(prn, "Got error %d estimating model\n",
model->errcode);
} else {
b = gretl_model_get_matrix(model, M_COEFF, &err);
if (err) {
pprintf(prn, "Got error %d grabbing coeffs\n", err);
} else {
gretl_matrix_print_to_prn(b, "coeffs", prn);
gretl_matrix_free(b);
}
}
gretl_model_free(model);
</code-fragment>
The grabbing of a matrix via gretl_model_get_matrix() worked fine.
Allin Cottrell