OxMetrics Program to Print Model Results in Latex Tables

This is a short guide that illustrates how to use the Ox class that I have written called PrintModels. The class takes estimated PcGive models as inputs and presents the estimation results for different models in a nice table and a latex code. The reported results include the estimates and standard errors, the estimated residual standard deviation and the log-likelihood value, the AIC, HQ, and BIC/SQ information criteria, the p-values for the standard misspecification tests, the number of observations and the effective sample period.

Disclaimer: Using this Ox class is at your own risk! I have written the code quite fast, so it might include errors. Please check that the results in the generated tables correspond to the results when you manually estimate each of the models. Let me know if you find any bugs.

To use the code requires some programming skills as you need to edit a few things in an Ox code that is automatically produced for you. The steps are outlined and explained below. Also, take a look at the example included in the zip-file under Step 1 below.

Step 1: Unzip the Files

Download the following zip-file:

PrintModels.zip Download PrintModels.zip.

Place all files in the same folder on your computer.

The zip-file contains the PrintModels Ox class in the files "PrintModels.ox" and "PrintModels.oxh". Additionally, there is an example of how to use it in the file "PrintModels Example.ox". If you open and run this code, you can see how the PrintModels class works.

Step 2: Estimate the models using PcGive and Create Ox Code

To use the Ox class in practice, you first need to estimate the models you want to report the results for using the standard time series module PcGive. After estimating all the models you want to include, you click the "Model" menu, click "Ox Batch Code", and select "PcGive". That will produce an ox code that estimate

After estimating all the models you want to include, you click the "Model" menu, click "Ox Batch Code", and select "PcGive". That will produce an ox code that estimates all the models you have just estimated.

The generated Ox code should look similar to the file "Ox Code Example.ox".

Save the generated Ox code in the folder where you put the files from PrintModels.zip in Step 1.

Step 3: Edit the Generated Ox Code

The generated Ox code includes a main() function at the end which is run when you execute the code by clicking run (Ctrl + R). Above that, the code includes a function for each of the estimated models called run_1(), run_2(), etc. Each of these is executed by the main() function when the program is executed, and each of the functions estimates the PcGive models you manually estimated, to begin with.

Note, that in OxMetrics each line must end with a semi-colon and that you can comment out lines by adding //.

In the generated Ox code, you need to make five changes/additions. In the example code file, "PrintModels Example.ox", I have included comments explaining what to edit and add. Below, the edits and additions are listed and explained.

Edit 1: Add the PrintModel Class

At the top of the code file, add the line:

#import <PrintModels>

If you have placed the files "PrintModels.ox" and "PrintModels.oxh" in the same folder as the Ox code you are editing, then this line will add the PrintModels Ox class.

In the example "PrintModels Example.ox", this is done in line 8.

Edit 2: Change "delete model;" to "return model;"

In each of the functions run_1(), run_2(), etc. find the line

delete model;

and replace it with

return model;

Thereby, the function run_1() returns the PcGive class with the estimated model called model instead of deleting it.

In the example "PrintModels Example.ox", this is done in lines 32, 59, 86, 113, and 139.

Edit 3: Declare models in the main() function

Find the main() function at the bottom of the code.

Replace the lines

run_1(); run_2();

etc. with

decl m1 = run_1(); decl m2 = run_2();

You have to do that for each of the different models you estimate.

This defines a new object m1 which is set to equal the PcGive model returned by the function run_1() (which you edited under Edit 2 above).

In the example "PrintModels Example.ox", this is done in lines 154-158.

Edit 4: Declare the PrintModels() class and add the estimated PcGive models

At the end of the main() function, but before the final }, add the following lines:

decl printmodels = new PrintModels();
printmodels.AddModels(m1, m2, m3, m4, m5);
printmodels.SetModelNames({"(1)", "(2)", "(3)", "(4)", "(5)"});
printmodels.PrintTable();

The first line declares a new class object called printmodels. We can use this object to print the estimated models. In general, we can execute functions included in the class by writing

printmodels.FunctionToExecute()

The first thing to do with the class is to add the estimated models, which we do on the second line. In the example above, I have added five estimated models called m1, m2, m3, m4, and m5. These names must correspond to the names declared under Edit 3 above. If you only have three models, you just replace

printmodels.AddModels(m1, m2, m3, m4, m5);

with

printmodels.AddModels(m1, m2, m3);

In the third line above, you manually add the model names. Here, I just call the models "(1)", "(2)", etc. If you have three models instead of five, just replace

printmodels.SetModelNames({"(1)", "(2)", "(3)", "(4)", "(5)"});

with

printmodels.SetModelNames({"(1)", "(2)", "(3)"});

You can then specify the number of lags used in the tests for no autocorrelation and no ARCH. This is dones using the functions below, where we chosen to include 5 lags in both tests.

printmodels.SetARTestLags(5); br>printmodels.SetARCHTestLags(5);

Finally, the last line

printmodels.PrintTable();

prints the estimation results in a simple table and with a latex code that you can copy-paste into your latex editor.

In the example "PrintModels Example.ox", this addition is included in lines 163-168.

Edit 5: Delete the class objects

The last thing to do, is to delete the PcGive model objects and the PrintModels class object. At the end of the main() function, but before the final }, add the following lines:

delete m1, m2, m3, m4, m5;
delete printmodels;

This deletes the objects from the memory. If you only have three models, just remove m4 and m5 in the first of the two lines.

In the example "PrintModels Example.ox", this addition is included in lines 175-176.