Skip to content

Table Creator Tutorials

Erica Clower edited this page Mar 11, 2018 · 4 revisions

Tutorial One: OLS Regression

This tutorial will demonstrate how to use the GAUSS table creator library to customize and export a publication quality table in GAUSS. This tutorial will demonstrate how to use the a number of features in the GAUSS table creator library including:

Loading the tabout library

Prior to using any of the tabout library tools, the library must be loaded. Detailed directions on loading the library are included in the repository README file. This tutorial uses the library tabout statement to load the file:

library tabout;

Run GAUSS OLS regression

Though the emphasis in this tutorial is on using the table creator library, we must have some results to work with prior to customizing our table. For this tutorial, we use OLS results generated using the built-in GAUSS dataset, auto.dat, and the GAUSS procedure olsmt.

//Run OLS with auto data
struct olsmtControl oc0;
struct olsmtOut oOut;
oc0 = olsmtControlCreate;

//Load filename
filename = getGAUSShome() $+ "examples/auto.dat";

//Run ols
oOut = olsmt(oc0, filename, "mpg~weight + length");
print;
print;

Creating a table using outputTable

The table creator function for generating publication tables is outputTable

struct regressEstimateTable regEstTab;
regEstTab = outputTable(tableCtl, coeff [, se, tstat, pval])

This function requires at least two inputs, the tableControl structure and a vector of coefficients. In addition, it accepts up to three optional arguments. The optional can include a vector of standard error, a vector of t-stats, and a vector of p-val. These must be entered as inputs into outputTable in that order.

The tableControl structure

The tableControl structure houses the variables that are used to control the look and format of the table. This tutorial will not cover all the details of GAUSS structures. For a more detailed explanation of structures please see the the GAUSS tutorials "Why Learn to Use Structures?" and "A gentle introduction to using structures".

The first step to using the tableControl structure is to declare an instance of the structure. The default values for the members in the tableControl structure can be set using the tableGetDefaults function:

//Step one: Declare the tableControl structure
struct tableControl tblCtl;
tblCtl = tableGetDefaults("OLS");

The parameters within the tableControl structure can be set using the suite of tableSet functions. All of these functions require a pointer a previously declared tableControl structure as the first input. This is done using &structureName . Each of these functions has it's own command reference page, including a usage example, in the docs directory of the repository. However, we will examine setting up our table using some of the functions below.

Setting the table title

To start, consider setting the title of the table to reflect that this is an OLS regression using the tableSetTitle function. In addition to the tableControl pointer the. the tableSetTitle function requires a string specifying the title:

//Set up table title
tableSetTitle(&tblCtl,"OLS Regression");

Setting the values included in the table

The tables created by the tabout library can include coefficient values, standard error values, t-stats, and p-values. The tableSetVars procedure is used to specify which of these to include in the table. The tableSetVars procedure uses a comma separate string to specify the values to include on the table:

//Set up values to include in table
tableSetVars(&tblCtl, "coefficients, se, tstat");

Labelling the variables

Two procedures are useful for labelling variables on the table. The tableSetVarNames procedure is used to label the variables corresponding to the estimated coefficients. The tableSetColumnHeaders procedure can be used to set the column label to reflect the dependent variable:

//Name variables included in model
tableSetVarNames(&tblCtl, "Const., Weight, Length");

//Set column header to independent variable
tableSetColumnHeaders(&tblCtl, "mpg");

Setting the significant figures

The tableSetSigFig procedure is used to set the significant figures of the values included on the table. This procedure takes a scalar input specifying the number of significant figures to include on the table:

//Significant figures
tableSetSigFig(&tblCtl, 6);

Adding significance asterisks to the table

A key feature of many publication quality tables is an indicator of variable significance. Asterisks for indicating significance levels can be added to the table using the tableSetAsterisk procedure. This procedure requires a string input indicating the value that the asterisks should be included on. An optional 3x1 vector input specifying the significance level cut-off values can also be included. Default p-value cut-offs of 10%, 5% and 1% are used if no cut-off levels are specified:

//Set up asterisks
tableSetAsterisk(&tblCtl, "coefficients");

Adding brackets around values

Adding brackets around values can help make tables more readable. The procedure tableSetBrackets sets brackets around a specified value on the table. This function requires a string input indicating which value, coefficients, standard errors, t-stats, or p-values, to place brackets around:

//Set up brackets
tableSetBrackets(&tblCtl, "se");

Setting up table export

Once created, the table can be exported to Excel for easy future use. This is controlled using the tableSetExport procedure. This procedure allows you to set the export filename and the filetype:

//Export Table
tableSetExport(&tblCtl,"TableOutOLS");

The outputTable procedure is used to produce and export the table once the table format is set-up. The outputTable procedure sends all results to a regressEstimateTable structure:

struct regressEstimateTable regEstTab;
regEstTab = outputTable(tblCtl, oOut.b, oOut.stderr);

Once the outputTable is called the following table is saved in the file TableOutOLS and printed to the GAUSS output screen:

OLS Regression
----------------------------------

Variables       mpg             
Const.           47.8849***     
                [ 6.08787]      
                 7.86562        
Weight          -0.00385148*    
                [ 0.00158598]   
                -2.42845        
Length          -0.0795935      
                [ 0.0553577]    
                -1.4378         
----------------------------------

Estimate se in brackets.
*p-val<0.001 **p-val<0.05 ***p-val<0.01