STAMP Ox code generator
Basic functions
STAMP is mostly menu-driven for ease of use. To add flexibility, STAMP 8.30 contains the facility to generate Ox code for the model that is estimated in STAMP. It complements the Batch code generator in STAMP. It is particularly useful for those who use Ox regularly as their programming environment for analysing time series. In this short documentation for the Ox code generator in STAMP, we present a list of functions and an examples of its use.
After STAMP has estimated the parameters of the BSM, the standard output is sent to the Text/Results and the Graphics/Model windows. The Ox code generator is activated by pressing Alt-o when STAMP is actived. In case a model is formulated in STAMP and parameters are estimated, the option Alt-o opens the menu window ``Generate Ox code'' in which the user has two options. The default choice is ``Most recent model'' and can be accepted. STAMP then outputs the following Ox code
#include "oxstd.h" #import "packages/stamp/stamp_ox_uc" main() { //--- Ox code for UC( 1) decl model = new UCstamp(); model.Load("ENERGYmiss.in7"); model.Select(Y_VAR, {"ofuELl", 0, 0}); model.SetSelSample(1960, 3, 1986, 1); model.SetMethod(M_ML); model.StartStamp(); model.AddComponent(COM_LEVEL, 1, 0.000387097); model.AddComponent(COM_SLOPE, 1, 1.87978e-006); model.AddComponent(COM_SEASONAL, 4, 0.00017307); model.AddComponent(COM_IRREG, 0, 0.000524284); model.Estimate(); delete model; }
When STAMP is installed on the computer, the ``stamp_ox_uc'' library offers many Ox functions that are developed for STAMP. These functions are collected in the class ``UCstamp'' which is activated by the ``new'' command in Ox. The command ``Load'' reads in the data file ``ENERGYmiss.in7'' and ``Select'' takes the variable ofuELl as the dependent variable to analyze. In the Ox code, we can first select the sample and the estimation method using the commands ``SetSelSample'' and ``SetMethod'', respectively.
The command ``StartStamp'' initializes the settings for formulating an UC model. The next part of the Ox code is similar to the Batch code. The inclusion of a component is established by the command ``AddComponent''. In case of the seasonal component, the constant ``COM_SEASONAL'' indicates that the seasonal component is included in the model. Other possible constants are ``COM_LEVEL'', ``COM_SLOPE'', ``COM_CYCLE'', ``COM_AR'' and ``COM_IRREG''. The second constant indicates that we work with quarterly data (seasonal length is 4) and the value 0.00017307 is the value of the seasonal variance, as estimated by the STAMP program. The ``Estimate'' command (re-)estimates the variances (and, possibly, other parameters).
Other commands in the ``stamp_ox_uc'' library are ``AddIntervention'' for including interventions in the model, ``GetForecast'' for generating forecasts from the model, ``Store'' for storing residuals and estimated components from STAMP and ``PrintState'' for printing the estimated state vector.
In the following list, Ox code function arguments are indicated by words, whereas the areas where statement blocks are expected are indicated by .... An example follows the list of descriptions. For terms in double quotes, the desired term must be substituted and provided together with the quotes.
- ♦ AddComponent(cmp, order, variance, par1, par2);
Introduces an unobserved component in the model. The possibilities are:
- AddComponent(COM_LEVEL, -, 1.0); where - refers to "not a
relevant number" and 1.0 is the variance.
- AddComponent(COM_SLOPE, 2, 1.0); where 2 is the order of the
trend.
- AddComponent(COM_SEASONAL, 4, 1.0); where 4 is the length of
the seasonal.
- AddComponent(COM_IRREG, -, 1.0);
- AddComponent(COM_CYCLE, 2, 1.0, 5, 0.9); where 2 is the order of the
cycle, 5 is the period and 0.9 is the discounting factor of the
cycle.
- AddComponent(COM_AR, 1, 1.0, 0.8); where 1 is the order of the
autoregressive process, AR(1) and 0.8 is the autoregressive
coefficient.
- AddComponent(COM_AR, 2, 1.0, 0.8, 0.2); where 2 is the order of the autoregressive process, AR(2), 0.8 is the first autoregressive coefficient and 0.2 is the second autoregressive coefficient.
- AddComponent(COM_LEVEL, -, 1.0); where - refers to "not a
relevant number" and 1.0 is the variance.
- ♦ AddIntervention(component, year, period);
The component argument specifies the type of intervention to be included in the model:
- include outlier: ITV_IRREG;
- include structural break: ITV_LEVEL;
- include slope change: ITV_SLOPE.
The year and period indicates the start of the intervention. When year and period refer to a non-existing date within the sample, the intervention will not enter the model.
- include outlier: ITV_IRREG;
- ♦ AutoIntervention();
Activates the option to automatic detection of interventions in the time series as in the main STAMP program.
- ♦ Estimate();
Starts the estimation process.
- ♦ GetCmpEstimate(component, optional);
Returns the estimated component COM_LEVEL,COM_SLOPE, COM_SEASONAL, etc. The optional argument can have value "filter" (for filtered estimate), "prediction" (for predictive filtered estimate) and "smooth" (for smoothed estimate, is the default).
- ♦ GetCmpResiduals(component);
Returns the standardized smoothed errors associated with the component:
- irregular: COM_IRREG;
- level: COM_LEVEL;
- slope: COM_SLOPE.
- irregular: COM_IRREG;
- ♦ GetDataX();
Returns the observation matrix for the explanatory variables.
- ♦ GetDataY();
Returns the observation matrix for the dependent variables.
- ♦ GetForecast(nrfor, incr, option);
Returns nrfor ahead forecasts of dependent variables. When explanatory variables are included in the model, the incr value is the increment value for all exogenous variables. Otherwise, no value for incr should be given. When the data is in logs and the forecasts need to be anti-logged, the option variable must be set to "logs". Otherwise, no value is required for option. Furthermore it prints a forecasting report in the Results window.
- ♦ GetResiduals();
Returns the standardized one-step ahead prediction errors of the model fitted in STAMP.
- ♦ PrintDiagnostics();
Prints the diagnostic statistics based on the standardized one-step ahead prediction residuals.
- ♦ PrintState(number);
Prints the most recent (number) of predicted, filtered and smoothed state estimates.
- ♦ Select(Y_VAR, {"ofuELl", 0, 0}) {Y=...; X=...; }
Include a variable from the database in the model, consisting of the following components:
- Y_VAR for a dependent variable; X_VAR for an explanatory variable.
- range {"name", 0, 0} where name is a series in the database.
The variables listed are separated by commas, the base names (that is, name excluding lag length) for Y and X must be in the database. If the variable names are not a valid token, the name must be enclosed in double quotes.
- Y_VAR for a dependent variable; X_VAR for an explanatory variable.
- ♦ StartStamp();
This Ox function is required to activate all specified unobserved components in the STAMP program. This function must always be placed in the Ox program before the first AddComponent statement.
Creating a link with SsfPack
For SsfPack users, the Ox code generator can facilitate a convenient link with the SsfPack functions. We can illustrate the link with the following extended example Ox code.
#include "oxstd.h" #include "packages/ssfpack/ssfpack.h" #import "packages/stamp/stamp_ox_uc" main() { //--- Ox code for UC( 1) decl model = new UCstamp(); model.Load("ENERGYmiss.in7"); model.Select(Y_VAR, {"ofuELl", 0, 0}); model.SetSelSample(1960, 3, 1986, 1); model.SetMethod(M_ML); model.StartStamp(); model.AddComponent(COM_LEVEL, 1, 0.000387097); model.AddComponent(COM_SLOPE, 1, 1.87978e-006); model.AddComponent(COM_SEASONAL, 4, 0.00017307); model.AddComponent(COM_IRREG, 0, 0.000524284); model.Estimate(); decl dlik, dvar, vy, mphi, momega, msigma; vy = model.GetDataY(); model.GetSsf(&mphi;, &momega;, &msigma;); SsfLikEx(&dlik;, &dvar;, vy, mphi, momega, msigma); println("The SsfPack loglikelihood value is ", dlik); delete model; }
The Ox code includes the SsfPack library of functions. All necessary variables for SsfPack can be obtained from the ``stamp_ox_uc'' library. The command ``GetDataY'' returns the data vector of the dependent variable (as a row vector). The command ``GetSsf'' returns the state space system matrices of the UC model. The system matrices are required for the SsfPack function. We illustrate it for the computation of the loglikelihood value using the SsfPack function ``SsfLikEx''.
The SsfPack Ox code produces the output:
The SsfPack loglikelihood value is 87.6671
All other SsfPack functions can be used in this framework as well and we refer to the SsfPack manual for a full description of SsfPack.