OxMetrics Reference

Short table of contents
Return to OxMetrics Help

10 OxMetrics Statistics
11 Algebra Language
12 Batch Language
13 OxMetrics Graphics
14 OxMetrics Data Management
 References
Table of contents
  Part:1 OxMetrics Reference
10 OxMetrics Statistics
  10.1 Actual series and scatter plots
  10.2 Mean, standard deviation and variance
  10.3 Autocorrelation function (ACF) or covariogram
  10.4 Partial autocorrelation function (PACF)
  10.5 Correlogram
  10.6 Cross-correlation function (CCF)
  10.7 Periodogram
  10.8 Spectral density
  10.9 Histogram, estimated density and distribution
  10.10 Regression lines and smooths
  10.10.1 Kernel smooth
  10.10.2 Spline smooth
  10.11 QQ plot
  10.12 Box plot
  10.13 Exponentially-weighted moving average (EWMA)
  10.14 Exponentially-weighted moving correlation
11 Algebra Language
  11.1 Introduction
  11.2 Executing Algebra code
  11.2.1 Calculator (Alt+c)
  11.2.2 Algebra Editor (Alt+a)
  11.2.3 Algebra from Results windows (Ctrl+a)
  11.2.4 Algebra from a Batch file
  11.3 Syntax of Algebra language
  11.3.1 Variables and variable names
  11.3.2 Comment
  11.3.3 Constants
  11.3.4 Algebra operators
  11.3.4.1 Arithmetic operators
  11.3.4.2 Relational and logical operators
  11.3.4.3 Algebra operator precedence
  11.3.5 Assignment statements
  11.3.6 Conditional assignment statements
  11.3.7 Indexing
  11.3.8 Keywords
  11.4 Algebra implementation
  11.5 Algebra Functions
  11.5.1 Differencing and lag functions
  11.5.2 ACF and periodogram functions
  11.5.3 Sorting functions
  11.5.4 Smoothing functions
  11.5.4.1 Hodrick--Prescott filter
  11.5.4.2 Kernel and spline smoothing
  11.5.4.3 Exponentially-weighted moving average and correlation
  11.5.4.4 Date and time functions
  11.6 Algebra function summary
12 Batch Language
  12.1 Introduction
  12.2 Executing Batch commands
  12.2.1 Batch Editor (Alt+b)
  12.2.2 Batch from Results windows (Ctrl+b)
  12.2.3 Batch from the File/Open command
  12.2.4 Batch from the Windows Explorer
  12.2.5 Batch from a Batch file
  12.3 Batch files and default folders
  12.4 General Batch command summary
  12.4.1 Comment
  12.4.2 Command types
  12.4.3 Default arguments
  12.5 Batch commands
  12.5.1 algebra {...}
  12.5.2 appenddata("filename", "group"="");
  12.5.3 appresults("filename");
  12.5.4 break;
  12.5.5 chdir("path");
  12.5.6 closedata("databasename");
  12.5.7 command("command_line");
  12.5.8 database("name", year1, period1, year2, period2, freq);
  12.5.9 draw(area, "y", "mode"="");
  12.5.10 drawf(area, "y", "function", d1=0, d2=0);
  12.5.11 drawx(area, "y", "x", "mode"="");
  12.5.12 drawz(area, "y", "x", "mode"="");
  12.5.13 exit;
  12.5.14 loadalgebra("filename");
  12.5.15 loadbatch("filename");
  12.5.16 loadcommand("filename");
  12.5.17 loaddata("filename");
  12.5.18 loadgraph("filename");
  12.5.19 module("name");
  12.5.20 package("packagename", "modeltype"="");
  12.5.21 print("text");
  12.5.22 println("text");
  12.5.23 printdate;
  12.5.24 savedata("filename");
  12.5.25 savedrawwindow("filename", "window"="");
  12.5.26 saveresults("filename");
  12.5.27 setdraw("option", i1=0, i2=0, i3=0, i4=0, i5=0);
  12.5.28 setdrawwindow("name");
  12.5.29 show;
  12.5.30 usedata("databasename", i1=0);
  12.6 Examples
13 OxMetrics Graphics
  13.1 Graphics paper
  13.2 Creating graphs
  13.2.1 Actual series with optional transformations
  13.2.2 Multiple series with optional transformations
  13.2.3 Scatter plots
  13.2.4 Distribution
  13.2.5 Time-series: ACF etc.
  13.2.6 QQ plots
  13.2.7 Two series by a third
  13.2.8 3-dimensional plots
  13.3 Printing graphs
  13.4 Graphics formats
  13.5 Saving and loading graphs
  13.6 Editing graphs
  13.6.1 Graph layout
  13.6.2 Area layout
  13.6.3 Variable against time, scatter, or 3D
  13.6.3.1 Error bars
  13.6.3.2 Regression, Scale
  13.6.4 Axes
  13.6.4.1 Settings for non-default labelling
  13.6.4.2 Location and transformation
  13.6.4.3 Style
  13.6.4.4 Label style
  13.6.5 Legend style
  13.6.6 Histogram
  13.6.7 Copy properties to other areas
  13.6.8 Text
  13.6.9 Lines and symbols
  13.6.10 Adding, moving and deleting objects
  13.6.11 Pointing
  13.6.12 Graphics setup
  13.7 Copy and paste
  13.8 Graphs and sample selection
  13.9 Text formatting
14 OxMetrics Data Management
  14.1 Creating data
  14.2 Database font
  14.3 Database description
  14.4 Printing data
  14.5 Data formats
  14.6 Summary statistics
  14.7 Saving data
  14.8 Navigation and editing
  14.9 Renaming variables
  14.10 Deleting variables
  14.11 Reordering variables
  14.12 Adding variables
  14.13 Extending or reducing the sample period
  14.13.1 Changing the sample period
  14.14 Copy and paste
  14.15 Appending data
  14.16 Daily, weekly and timed data
List of tables
  Table:11.1 Algebra operator precedence
  Table:11.2 Reserved Algebra keywords
  Table:11.3 Algebra functions
  Table:12.1 Batch command summary
  Table:13.1 Greek symbols
  Table:13.2 Arrows
  Table:13.3 Mathematics accents
  Table:13.4 Foreign and accented characters
  Table:13.5 Mathematical symbols
  Table:13.6 Log-like symbols
  Table:13.7 Miscellaneous symbols
  Table:13.8 Fonts and sizes

Part:1 OxMetrics Reference

Chapter 10 OxMetrics Statistics

OxMetrics provides many convenient graphical options for prior data analysis. For simplicity, we denote the selected variable by xt, t=1,...,T. This chapter summarizes the underlying formulae, discussing each available graph type in turn.

10.1 Actual series and scatter plots

Actual series gives a graph for each selected variable, showing the variable over time. The All scatter plots option gives scatter plots between all selected variables (omitting redundant scatter plots).

10.2 Mean, standard deviation and variance

These are relevant for the statistics described below. For a series xt, t=...,T:

sample mean x= 1/T ∑t=1Txt,
sample variance σ̃2x = 1/T ∑t=1T( xt-x)2,
sample standard deviation σ̃x.
(eq:10.1)

Note that an alternative definition of the variance would divide by T-1 instead of T.

[Note: The maximum likelihood estimate for a linear model gives 1/T, while regression on a constant using OLS produces an unbiased estimate of the variance using 1/(T-1).]

sample variance (OLS) σ̂2x = 1/T-1 ∑t=1T( xt-x)2,
sample standard error σ̂x.
(eq:10.2)

10.3 Autocorrelation function (ACF) or covariogram

Define the sample autocovariances {ĉj} of a series xt, t=...,T:

ĉj= 1/T ∑t=j+1T( xt-x) ( xt-j-x),  j=0,...,T-1,
(eq:10.3)

using the full sample mean x= 1/T ∑t=1Txt. The variance σ̃2x corresponds to ĉ0, see (eq:10.1).

The sample autocorrelation function (ACF) is the series {r̂j} where r̂j is the sample correlation coefficient between xt and xt-j. The length of the correlogram is specified by the user, leading to a figure which shows ( r̂1,r̂2,...,r̂s) plotted against ( 1,2,...,s) where for any j when x is any chosen variable:

r̂j=ĉj / ĉ0,  j=0,...,T-1.
(eq:10.4)

The first autocorrelation, {r̂0}, is equal to one, and omitted from the graphs.

The asymptotic variance of the autocorrelations is 1/T, so approximate 95% error bars are indicated at ±2T-1/2 (see e.g. Harvey, 1993, p.42).

If there are missing values in the data series, the correlogram uses all valid observation as follows: the mean is computed for all valid observations; terms where xt or xt-j are missing are omitted from the summation in (eq:10.3). Consequently, the same procedure is used in (eq:10.4) and any other derived functions such as the spectrum and periodogram.

10.4 Partial autocorrelation function (PACF)

Given the sample autocorrelation function {r̂j} the partial autocorrelations are computed using Durbin's method as described in Golub and Van Loan (1989, §4.7.2). This corresponds to recursively solving the Yule--Walker equations. For example, with autocorrelations, r̂0, r̂1, r̂2, ..., the first partial correlation is α̂0=1 (omitted from the graphs). The second, α̂1, is the solution from

(
r̂0
r̂1
) = (
r̂0 r̂1
r̂1 r̂0
) (
α̂0
α1
),

et cetera.

10.5 Correlogram

The sample correlogram plots the series {r̂j*} where r̂j* is the correlation coefficient between xt and xt-j. The length of the correlogram is specified by the user, leading to a figure which shows ( r̂1*,r̂2*,...,r̂s*) plotted against ( 1,2,...,s) where for any j when x is any chosen variable:

r̂j*=
t=j+1T( xt-x0) ( xt-j-xj)

(∑t=j+1T( xt-x0) 2t=j+1T( xt-j-xj) 2)½
.
(eq:10.5)

Here x0= 1/T-j ∑t=j+1Txt is the sample mean of xt, t=j+1,...,T, and xj= 1/T-j ∑t=j+1Txt-j is the sample mean of xt-j, so that r̂j* corresponds to a correlation coefficient proper.

Note the difference with the definition of the sample autocorrelations {r̂j} in (eq:10.4) above. This difference tends to be small, and vanishes asymptotically, provided the series are stationary. But, as argued in Nielsen (2006), the correlogram provides a better discrimination between stationary and non-stationary variables: for an autoregressive value of one (or higher), the correlogram declines more slowly than the ACF.

When the correlogram is selected for plotting, the PACF is based on the correlogram values, rather than the ACF. Handling of missing values is the same as for the ACF.

10.6 Cross-correlation function (CCF)

The sample cross-correlation function (CCF) graphs the correlation between a series xt and the lags of another series yt:

r̂xyj=
t=j+1T( xt-x) ( yt-j-y)

t=1T( xt-x) ∑t=1T( yt-y)
=
ĉxyj

( ĉx0 ĉy0)1/2
,  j=0,...,T-1,
(eq:10.6)

using the full sample means x and y.

The CCF between xt and yt is different from that between yt and xt: r̂xyjr̂yxj. Both are plotted in the same graph.

10.7 Periodogram

The periodogram is defined as:

p( ω) = 1/2π ∑j=-T+1T-1 ĉ| j| e -iωj = 1/2π ∑j=-T+1T-1 ĉ| j| cos ( jω)
= ĉ0/2π ∑j=-T+1T-1 r̂| j| cos ( jω) ,
for ω= 0, 2π/T, 4π/T, ..., (int(T/2)2π)/T.
(eq:10.7)

Note that p(0)=0.

When the periodogram is plotted, only frequencies greater than zero and up to π are used. Moreover, the x-axis, with values 0,...,π, is represented as 0,...,1. So, when T=4 the x coordinates are 0.5,1 corresponding to π/2, π. When T=5, the x coordinates are 0.4,0.8 corresponding to 2π/5, 4π/5.

However, when the periodogram is evaluated using the Algebra function periodogram, it is evaluated at all frequencies up to 2π, resulting in T periodogram values. For T=4 these are evaluated at 0, π/2, π, 3π/2. For T=5: 0, 2π/5, 4π/5, 6π/5, 8π/5. The frequencies are returned in the last argument of periodogram.

10.8 Spectral density

The estimated spectral density is a smoothed function of the sample autocorrelations {r̂j}, defined as in (eq:10.4). The sample spectral density is then defined as:

ŝ( ω) =
1

j=-(T-1)T-1K( j) r̂| j| cos ( jω) ,  0≤ω≤π,
(eq:10.8)

where | .| takes the absolute value, so that, for example, r̂| -1| =r̂1. The K( .) function is called the lag window. OxMetrics uses the Parzen window:

K( j) = 1-6( j/m ) 2+6| j/m | 3, | j/m | ≤0.5,
= 2( 1-| j/m | ) 3, 0.5≤| j/m | ≤1.0,
= 0, | j/m | >1.
(eq:10.9)

We have that K(-j)=K(j), so that the sign of j does not matter ( cos (x)= cos (-x)). The r̂js are based on fewer observations as j increases. The window function attaches decreasing weights to the autocorrelations, with zero weight for j>m. The parameter m is called the lag truncation parameter. In OxMetrics, this is taken to be the same as the chosen length of the correlogram. For example, selecting s=12 (the with length setting in the dialog) results in m=12. The larger m, the less smooth the spectrum becomes, but the lower the bias. The spectrum is evaluated at 128 points between 0 and π. For more information see Priestley (1981) and Granger and Newbold (1986).

10.9 Histogram, estimated density and distribution

Given a data set {xt}=( x1...xT) which are observations on a random variable X. The range of {xt} is divided into N intervals of length h with h defined below. Then the proportion of xt in each interval constitutes the histogram; the sum of the proportions is unity on the scaling in OxMetrics. The density can be estimated as a smoothed function of the histogram using a normal or Gaussian kernel. This can then be summed (`integrated') to obtain the estimated cumulative distribution function (CDF).

Denote the actual density of X at x by fx( x) . A non-parametric estimate of the density is obtained from the sample by:

fx( x) ̂= 1/Th ∑t=1TK(
x-xt

h
) ,
(eq:10.10)

where h is the window width or smoothing parameter, and K( .) is a kernel such that:

-∞ K( z) dz=1.

OxMetrics sets:

h=1.06σ̃ x/T0.2

as a default, and uses the standard normal density for K( .) :

K(
x-xt

h
) =
1

(2π)½
exp [ - ½(
x-xt

h
) 2] .
(eq:10.11)

The default window width is used when the dialog option is set to Default bars. Alternatively, it is possible to directly choose the number of bars, in which case, the more bars, the less smooth the density estimate will be. The histogram uses the whole sample, skipping over missing values.

fx( x) ̂ is usually calculated for 128 values of x, but since direct evaluation can be somewhat expensive in computer time, a fast Fourier transform is used (we are grateful to Dr. Silverman for permission to use his algorithm). The estimated CDF of X can be derived from fx( x) ̂; this is shown with a standard normal CDF for comparison. An excellent reference on density function estimation is Silverman (1986).

10.10 Regression lines and smooths

The scatter plots option allows for various types of regression lines to be drawn. A single regression line draws the fitted values from the OLS estimates α̂ and β̂ in

t=α̂+β̂xt,  t=1,...T,

assuming that yt and xt are the selected variables. The distinction between sequential and recursive regression lines is easily explained using three lines. Divide the sample in three parts: 1,...,T/3, T/3+1,...,2T/3 and 2T/3+1,...,T, then:

sequential
line 1 t=α̂ 1+β̂ 1xt, t=1,...T/3,
line 2 t=α̂ 2+β̂ 2xt, t=T/3+1,...,2T/3,
line 3 t=α̂ 3+β̂ 3xt, t=2T/3+1,...,T,
recursive
line 1 t=α̂ 1+β̂ 1xt, t=1,...T/3,
line 2 t=α̂ 4+β̂ 4xt, t=1,...,2T/3,
line 3 t=α̂ +β̂ xt, t=1,...,T.

The regression line is fitted over the whole sample, skipping over missing values inside sample.

10.10.1 Kernel smooth

As a first step towards non-parametric regression, we start with a scatter plot of yt and xt, with xt along the horizontal axis. Divide the x-axis in N intervals, and compute the average y-value in each interval. The resulting step function provides a non-parametric regression line: to compute ŷ(x0) we locate the interval on which x0 falls, and use the mean of y in that interval as ŷ. An obvious drawback is that, if x0 is towards the edge of an interval, most of the observations are on the other side. Solve this by centring the interval in x0. This still gives as much weight to points far away as to points nearby. In line with the smoothing functions (kernels) in the spectrum and density estimates, we use a density function to take a weighted average.

The non-parametric estimate of y is obtained from

h( x) =( ∑t=1TK(
x-xt

h
) ) -1( ∑t=1TK(
x-xt

h
) yt) ,
(eq:10.12)

where, as for (eq:10.10), h is the window width, bandwidth or smoothing parameter, and K( .) is a kernel which integrates to 1. OxMetrics uses the Epanechnikov kernel:

K( u) = 3/4 ( 1-u2) , | u| ≤1,
= 0, | u| >1,
(eq:10.13)

which is optimal in a certain sense. The optimal bandwidth, equivalent to the default chosen for the non-parametric density estimate is:

h=0.75σ̃ x/T0.2.

The function ŷh( .) is computed at 128 points. As h→0, ŷh( .) →y: the sample mean is the fitted value for any x. On the other hand, if h→∞ the interval goes to zero, and we fit the nearest corresponding y-value so that each data point is picked up exactly. Note, however, that the ŷ( .) function is evaluated at the T data points xt (which is time in the absence of x). Härdle (1990) is a general reference on the subject of non-parametric regression.

There are three ways of specifying the bandwidth:

The kernel smooth is not computed using a Fourier transform, but directly, so can be slow for large T. The smooth is fitted over the whole sample skipping over missing values inside sample, which are estimated by the fit from the smooth.

One drawback of this smooth is that, for trending lines, it behaves counter intuitively at the edges. Consider, for example, the left edge of the kernel smooth of a variable which is upwardly trending. Since the smooth starts as a moving average of points which are only to the right, and hence mainly higher, the left edge will have a J shape, starting above what would be fitted by eye.

10.10.2 Spline smooth

A spline is another method for smoothing a scatter plot. Consider a plot of yt, against xt, and sort the data according to x: a<x[1]<...<x[T]<b. In a spline model, the sum of squared deviations from a function g is minimized, subject to a roughness penalty:

min ∑t=1T [ yt - g(x[t])]2 +α∫ab [ g''(x)]2 dx.

OxMetrics uses a natural cubic spline, which is cubic because the function g is chosen as a third degree polynomial, and natural because the smooth is a straight line between a and x[1] and between x[T] and b. This avoids the end-point problem of the kernel smooth of the previous section. Two good references on splines and nonparametric regression are Green and Silverman (1994) and Hastie and Tibshirani (1994).

The α parameter is the bandwidth: the smaller α, the lower the roughness penalty, and hence the closer the smooth will track the actual data.

The spline is evaluated at all the data points, where missing y values are estimated by the fit from the smooth. The spline procedure handles ties in the x variable. The algorithm used to compute the spline is of order T, and discussed extensively in Green and Silverman (1994, Chs.2,3).

For evenly-spaced data (e.g. scatter plot against time), the algorithm involves a Toeplitz matrix. This illustrates the closeness of a natural cubic spline to the Hodrick--Prescott filter which is popular in macro-economics:

diagonal 2nd diag 3rd diagremainder
Hodrick--Prescott 6α+ 1 -4αα0
spline 6α+ 2/3 -4α+ 1/6 α0

The only difference is in this Toeplitz matrix. Since the Hodrick--Prescott filter uses α=1600 (for quarterly data), the smoothers from both methods are virtually identical.

[Note: Some articles describe computation of the Hodrick--Prescott filter as involving inversion of a T×T matrix. This is clearly not the case. It is avoided in the Reinsch algorithm used for the general scatter-plot smooth, and more obviously in the evenly spaced case, where all that is required is the solution of a linear system involving a banded Toeplitz matrix. Alternatively, the Kalman filter may be used, as in Koopman, Harvey, Doornik, and Shephard (2013).]

There are three ways of specifying the bandwidth:

10.11 QQ plot

Draws a QQ plot. The variable would normally hold critical values which are hypothesized to come from a certain distribution. This function then draws a cross plot of these observed values (sorted), against the theoretical quantiles (the horizontal axis). The 45o line is drawn for reference (the closer the cross plot to this line, the better the match). The QQ plot line is drawn over the whole sample, skipping over missing values.

The following distributions are supported:

The normal QQ plot includes the pointwise asymptotic 95% standard error bands, as derived in Engler and Nielsen (2009) for residuals of regression models (possibly autoregressive) with an intercept. Here the normal QQ plot is created for the standardized data, but drawn on the original scale. The standard errors are given by the square root of:

T-1(
Φ(z)(1 - Φ(z))

φ(z)2
- z2 / 2 - 1),

where z denotes the coordinates of the reference distribution (the standard normal), Φ is the standard normal cdf, and φ the density.

10.12 Box plot

A box plot shows the distribution of a variable in terms of its quartiles, labelled Q1, Q2, Q3 (the 25%, 50%and 75%quartiles). Define the interquartile range as IQR = 1.5 (Q3 - Q1). The box plot consists of the following elements:

The box plot uses the whole sample, skipping over missing values.

10.13 Exponentially-weighted moving average (EWMA)

A simple exponentially-weighted moving average of a series yt, t=1,...,T, is defined as:

mt = αyt + (1 - α)mt-1,  t=2,...,T,
(eq:10.15)

using m1=y1. The resulting series zt is zt=mt, except when any yt+h is missing for h≥1, in which case it is replaced by forecasts zt+h=mt.

An extended version introduces a slope coefficient β, and is also called Holt's method:

mt =αyt + (1 - α)(mt-1+bt-1),
bt =β(mt-mt-1) + (1 - β)bt-1.

In this case m1=y1, m2=y2, b2=y2-y1; when β=0 the EWMA (eq:10.15) is used. The resulting series zt is zt=mt, except when any yt+h is missing for h≥1, in which case it is replaced by forecasts zt+h=mt+hbt.

Back-substitution in the EWMA without slope coefficient shows that:

mt = (1-α)t-1m1 + α∑s=0t-1(1-α)s yt-s.

See e.g. Harvey (1993, Ch. 5), or Makridakis, Wheelwright, and Hyndman (1998, Ch. 4).

10.14 Exponentially-weighted moving correlation

The exponentially weighted moving sample correlation of two series yt and xt, both having expectation zero, is defined as:

rt =
pt(x,y)

[pt(x,x)pt(y,y)]1/2
,  t=3,...,T

where

pt(x,y) = ∑s=0t-1λs xt-s yt-s,  t=1,...,T,

and r1,r2 are set to missing values. When any yt+h or xt+h is missing rt+h is set to rt.

Premultiplying the numerator and denominator of rt by 1-λ, shows that mt*=(1-λ)pt(x,y) is the EWMA of the cross-product with α=1-λ and m1=0. This does not work for λ=1.

Chapter 11 Algebra Language

11.1 Introduction

OxMetrics is mostly menu-driven for ease of use. To add flexibility, certain functions can be accessed through entering commands. The syntax of these commands, which can be seen as small computer languages, is described in this and the next chapter. In addition, there is the Ox language, which is a more serious computer language, and described in a separate book.

11.2 Executing Algebra code

Algebra is a simple vector language, operating on only one type of object: the variables in the database. This object is manipulated as a whole, although it is possible to limit access to a subsample. The only valid statements are assignments and conditional assignments. Statements have to be terminated with a semicolon.

If an error occurs while executing the algebra code, the processing will be aborted, and control returned to OxMetrics. All successful statements up to that point will have been executed, with corresponding changes to the database. Take this into account when rerunning the corrected code.

There are three ways of running Algebra code, as discussed in the next three sections.

11.2.1 Calculator (Alt+c)

The calculator enables easy manipulation of the variables in the database, and is a convenient way to write algebra expressions.

The aim is to build a valid algebra expression in the expression window (without the assignment part and the terminating semi-colon). All successful transformations are logged in the Results window as Algebra code.

11.2.2 Algebra Editor (Alt+a)

The Tools/Algebra Editor command enables you to transform the database variables by typing mathematical formulae into an editor. The algebra code can be saved and reloaded. The Algebra editor also allows for choosing the database to which the code is applied.

11.2.3 Algebra from Results windows (Ctrl+a)

A text selection containing Algebra code can be run directly from that window using the Edit/Run as Algebra command (or Ctrl+a as short cut). The code is applied to the currently active database. The current database is changed by setting focus to that database, or using any of the drop down boxes (calculator, algebra editor, graphics), or using the usedata() batch command.

11.2.4 Algebra from a Batch file

Algebra code can be specified in a Batch program, see Ch. 12, and specifically §12.5.1. An Algebra file can also be loaded into a batch file (§12.5.14).

11.3 Syntax of Algebra language

11.3.1 Variables and variable names

Names are made up of letters and digits. The first character must be a letter. Underscores (_) count as a letter. Valid names are CONS, cons, cons_1, _a_1_b, etc. Examples of invalid names are ΔCONS, 1-CONS, log(X), etc. Invalid names may be used in Algebra when enclosed in double quotes, so

"log(X)" = log(X);

is valid as long as the variable called X exists. Algebra is case-sensitive: CONS and cons refer to different variables. When you create a new variable through an assignment operation, it is immediately added to the database, and initialized to missing values. If necessary the database name will be truncated (longer names are allowed in algebra than in the database).

11.3.2 Comment

Anything between /* and */ is considered comment. Note that this comment cannot be nested. So

aap = CONS + 1; /* comment /* nested comment */ */

leads to a syntax error. Everything following // up to the end of the line is also comment.

11.3.3 Constants

A constant is a number which is used in an expression. Examples are 1, 1.2, .5, -77000, -.5e-10 and 2.1E-12.

11.3.4 Algebra operators

11.3.4.1 Arithmetic operators

The binary arithmetic operators are ^4 , *, /, +, -. The ^4 is the power operator; CONS ^4 2 raises the variable CONS to the power two. All computations are double precision floating point arithmetic. The precedence order is: ^4, unary + and unary -, then *, /, and finally +, -. An example of unary minus is: x = -1. Any arithmetic operation involving missing values returns a missing value.

11.3.4.2 Relational and logical operators

The relational operators are <, <=, >, >=, standing for `less', `less or equal', `greater', `greater or equal'. The equality operators are == and !=, `is equal to' and is `not equal to'. These are ranked below the relational operators in precedence. Ranked yet lower are logical AND (&&) and logical OR (||). The unary negation operator ! has the highest precedence. An example of unary negation is:

new = !season();

new will have a 0 where the season function returns a 1, and vice versa. Boolean arithmetic is also done in floating point. The numeric result is 1. for an expression that evaluates to true, and 0. for one that is false. An expression with value 0 is false, whereas a value that is not 0 is true.

Missing values are treated as follows:

a op b result when a and/or b is a missing value
<, <=, >, >= FALSE if a and/or b is missing
== TRUE if both a and b are missing
!= TRUE if either a or b is missing (but not both)
&&, || no special treatment of missing values

11.3.4.3 Algebra operator precedence

Table Table:11.1 lists the operator precedence, with the highest precedence at the top of the table.

Table:11.1 Algebra operator precedence

Symbol Description Associativity
^4 Power Left to right
! Logical NOT Right to left
- Unary minus
+ Unary plus
* Multiply Left to right
/ Divide
+ Add Left to right
- Subtract
< Less than Left to right
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal Left to right
!= Not equal
&& Logical AND Left to right
|| Logical OR Left to right

11.3.5 Assignment statements

The assignment operator is the = symbol. Assignment statements have to be terminated by a semicolon (;). If the variable to which a result is assigned does not yet exist, it is created and added to the database. Otherwise the existing variable is overwritten. Note that assignment expressions are vector expressions: all observations will be overwritten (it is possible to restrict assignment to a subsample using the insample function). Some valid assignment statements are:

cons2 = 2 * CONS - 1;
cons3 = CONS / 3 - (cons2 + 5) * 1.55;
Seasonal = season();

The last statement constructs a variable called Seasonal, which is 1 in period 1, and 0 otherwise. This variable will be used in further examples in this chapter.

Take care not to confuse the = and == symbols: = assigns, while == compares. Parentheses may be used in expressions in the usual way; in the example above (cons2 + 5) * 1.55 evaluates to cons2 * 1.55 + 5 * 1.55.

11.3.6 Conditional assignment statements

The conditional assignment expression has the following form:

TestExpression ? TrueExpression : FalseExpression

First the TestExpression is evaluated; if it is true (not 0.), then TrueExpression will be evaluated, else FalseExpression. Let us consider an example involving the Seasonal variable created above, which is 1 in the first quarter, and 0 in the other quarters. The statement

new = Seasonal ? CONS : 0;

can be read as follows: the variable new will get the value of CONS when Seasonal is true (that is, when Seasonal is not 0., so in the first quarter of each year), else it will get the value 0. In this case, the same result could have been reached with:

new = Seasonal * CONS;

However, if we had used a seasonal with the value 2 in the first quarter, and the rest zeros, then only the conditional assignment would have given the desired result (since 2 is not false, and hence true).

Note that the `: FalseExpression' part is optional. For example:

new = Seasonal ? CONS;

is a valid conditional assignment statement. Now the variable will have the value of CONS for the first quarter, but the other observations of new are not touched (so if new is created by this expression, it will contain missing values for quarters 2, 3 and 4, making the variable unusable for modelling purposes). Another example:

new = (CONS == MISSING) ? 0 : CONS;

This new variable takes the values of CONS, replacing missing values by zeros.

11.3.7 Indexing

It is possible to index a particular observation in a variable using rectangular brackets. For example:

CONS_1 = CONS[-1];

There are three methods of indexing:

11.3.8 Keywords

The following keywords are reserved by algebra:

Table:11.2 Reserved Algebra keywords

keyword value
FALSE 0.
TRUE !FALSE
FREQUENCY data frequency
MISSING the missing value
PI Pi (3.1415..)
NOBS number of observations

11.4 Algebra implementation

Each Algebra statement has an implicit loop over the sample size around it. E.g.

LCONS = log(CONS);
meanLCONS = mean(LCONS);

is equivalent to the following pseudo code:

for (t = first observation; t <= last observation; t = t + 1)
    LCONS[t] = log(CONS[t]);
for (t = first observation; t <= last observation; t = t + 1)
    meanLCONS[t] = mean(LCONS);

So meanLCONS will have the same value for every observation.

By default, the loop is over all the observations of the database. However, the insample function can restrict the loop to a subsample.

Implementing transformations in Ox is different: there, variables are extracted from the database as column vectors and operations work on the vector as a whole. Implementing the same code in Ox:

#include <oxstd.h>
#import <database>
main()
{
    decl db = new Database();
    db.Load("data.in7");
    db.Append(log(db.GetVar("CONS")), "LCONS");
    decl mean = meanc(db.GetVar("LCONS"));
    db.Append(constant(mean, db.GetSize(), 1), "meanLCONS");
    db.Info();
    delete db;
}

Note that the mean of a vector is just a single number, so creating a vector which has this value for every observation is implemented with the constant function in Ox (and adding this to the database is not very useful).

11.5 Algebra Functions

A large set of functions is provided by algebra. Most of these take both variables and constants as arguments. A function name must be followed by parentheses, even if it does not take any arguments. See the Algebra function list of Table Table:11.3 for function definitions. Some examples of statements involving functions are:

lcons = log (CONS);      // takes the natural logarithm of CONS
cons_1 = lag(CONS, 1);                   // lag CONS one period
ccons = exp(log(CONS));             // gives back original CONS
dummy = insample(1979, 1, 1983, 4) ? log(CONS) : 0;
              // Dummy will be log(CONS) for the period 1979(1)
              // to 1983(4), and 0 outside it.
trough = (lag(trough,1) == MISSING || CONS < lag(trough,1))
       ? CONS : lag(trough,1);
              // a trough can also be created with the built in
                                   // algebra function trough()
dummy  = (year() == 1979) ? 1 : 0;  // creates a dummy variable

11.5.1 Differencing and lag functions

A variable is lagged using the lag function,

[Note: In most cases it is better to avoid storing lags in the database: most estimation modules handle lags explicitly, allowing for dynamic analysis of the model.]

and differenced using the diff function. For example, for first lag and difference respectively, as well as second lag and difference:

Y_1 = lag(Y, 1);
DY = diff(Y, 1);
Y_2 = lag(Y, 2);
D2Y = diff(Y, 2);

This code adopts the naming convention which is used by OxMetrics: append an underscore followed by lag length for a lagged variable, and a prefix `D' for differenced variables.

When taking a first difference or lag, the first observation becomes missing; for a second difference or lag, the first two observations are missing, etc.

Neither function can have an expression as the argument for differencing. So you cannot write diff(diff(Y,1),1) but must write:

DY = diff(Y, 1);
DDY = diff(DY, 1);

Note that this DDY is not the same as D2Y above.

Finally, the dlog(.) function takes the first difference of the (natural) logarithm of the variable.

11.5.2 ACF and periodogram functions

The sample autocorrelation function can easily be plotted. To compute the exact values of the ACF, use the following algebra code:

acf_lag = MISSING;
acf_dcons = MISSING;
acf(DCONS, acf_dcons, acf_lag);

The first two lines are required to create the output variables for the acf function. The output from acf is the actual ACF values (here stored in ACF_DCONS), and the lag length (in ACF_LAG).

The periodogram function has a similar syntax, returning the sample periodogram in the second argument, and the frequencies at which it was computed in the third.

11.5.3 Sorting functions

The sort functions change the order of observations in the database and must be handled with care. Note that the trend() function can be used to create a variable which corresponds to the original observation index of the data. So if that variable is sorted together with the variable we wish to sort, it can be used to `unsort' the variable.

 sort(arg1)

Sorts the variable arg1 in increasing order (arg1 must be a variable, and cannot be an expression). Returns the value of arg1 after sorting. Suppose the residuals of a regression have been saved in the variable called Residual, then a sorted copy is created as follows:

res = Residual;
sort(res);

 _sortby(arg1, arg2)

Sorts the variable arg1 in increasing order, and sorts arg2 accordingly. Returns the value of arg1 after sorting. Both arg1 and arg2 must be variables. Suppose the residuals of a regression have been saved in the variable called Residual, then a sorted residual is created as follows:

index = trend();
tmp = _sortby(Residual, index);
            /* Residual is sorted, and index accordingly */
                             /* tmp is a dummy variable, */
                 /* at this stage identical to Residual. */
        /* Now it is easy to locate outliers in Residual */

The following statement will reset the old ordering (do not rerun the index = trend(); statement, because that will overwrite the index and lose the information on the original ordering):

tmp = _sortby(index, Residual);
                         /* Restores index and Residual, */
               /* at this stage index is equal to Trend. */

 _sortallby(arg1)

Sorts the variable arg1 in increasing order, and sorts the whole database accordingly. Returns the value of arg1 after sorting. This function will be most useful with cross-section data; for example, to push missing values to the end:

exclude =
   (Var1 == MISSING || Var2 == MISSING || Var3 == MISSING);
   /* exclude is 1 for each observation where any of the
        three variables has a missing value, 0 elsewhere */
tmp = _sortallby(exclude);
       /* the observations without any missing values will
         precede those with missing values, making it easy
                      to exclude them from the regression.
      An index variable can be used to restore the order */

11.5.4 Smoothing functions

The smoothing functions which are available in scatter plots can also be accessed from algebra.

11.5.4.1 Hodrick--Prescott filter

The Hodrick--Prescott is a filter which is popular in macro-economics, and virtually identical to a natural cubic spline (§10.10.2). The syntax is:

var_dest = smooth_hp(var,alpha,var_dest);

where var is the variable to be smoothed, alpha is the bandwith (use 0 for the default of 1600), and var_dest is the destination variable (must be different from var). For example:

hpCONS = smooth_hp(CONS, 0, hpCONS);

which creates hpCONS through the assignment statement, and uses it as the destination for the fitted values from the filter.

If there are missing values in the data series, smooth_hp uses data starting from the first valid observation, and stopping at the first missing value thereafter (this is unlike the smoothing functions of the next section, which will skip over missing values, using the maximum sample). The sample used can be restricted using the insample function.

The bandwidth parameter associated with the Hodrick--Prescott filter is 100 (freq)2:

annual data 100
quarterly data 1600
monthly data 14400

11.5.4.2 Kernel and spline smoothing

The kernel based smoother (using the Epanechnikov kernel, §10.10.1), and the natural cubic spline (§10.10.2) are computed respectively by:

var_dest = smooth_np(var,alpha,var_dest);
var_dest = smooth_sp(var,alpha,var_dest);

where var is the variable to be smoothed, var_dest is the destination variable (must be different from var), and alpha is the bandwith, used as follows:

0 use automatic bandwidth selection based on generalized cross validation;
<0 the absolute value is used for the bandwidth;
>0 specifies the equivalent number of parameters to be used.

These functions will use all available observations (unless restricted by the insample function), and will fill in missing values using the fit from the smoother.

11.5.4.3 Exponentially-weighted moving average and correlation

A simple exponentially-weighted moving average (see §10.13) of a series y can be created using:

    ysmo = ewma(y, 0.5, 0, ysmo);

Here α=0.5. An extended version introduces a slope coefficient β, and is also called Holt's method, e.g. with β=0.1:

    ysmo = ewma(y, 0.5, 0.1, ysmo);

In both cases, in-sample missing values are replaced by forecasts.

The exponentially weighted moving sample correlation (see §10.14) of two series y and x (both assumed to have expectation zero) can be created by:

    xysmo = ewmc0(x, y, 0.5, xysmo);

Here, λ is set to 0.5.

11.5.4.4 Date and time functions

When a database is dated, there are functions to return components of the current date and time for each observation: day, month, week, hours, minutes, seconds.

The makedate and maketime functions translate year, month, day and hours, minutes, seconds to date and time respectively. These can be added together to create a date with a time.

The dayofweek, isdayofmonth and iseaster functions are needed when determining holidays, for example to delete all holidays and weekends from a database. The following code, supplied as holiday_us.alg in the algebra folder, determines all the official US holidays:

hol_us_fix =                   /* official US holidays: fixed dates */
       (month()==1 && day()==1)                /* New Year's Day    */
    || (month()==7 && day()==4)                /* Independence Day  */
    || (month()==11 && day()==11)              /* Veterans Day      */
    || (month()==12 && day()==25);             /* Christmas Day     */
hol_us_fix = hol_us_fix                 /* fixed dates moved to Fri */
    || (month()==12 && day()==31 && dayofweek()==6)
    || (month()==7 && day()==3 && dayofweek()==6)       
    || (month()==11 && day()==10 && dayofweek()==6) 
    || (month()==12 && day()==24 && dayofweek()==6);    
hol_us_fix = hol_us_fix                 /* fixed dates moved to Mon */
    || (month()==1 && day()==2 && dayofweek()==2)
    || (month()==7 && day()==5 && dayofweek()==2)       
    || (month()==11 && day()==12 && dayofweek()==2) 
    || (month()==12 && day()==26 && dayofweek()==2);    
hol_us_flt =                /* official US holidays: floating dates */
       isdayofmonth(1,2,3) /* 3rd Mon in Jan: Martin Luther King day*/
    || isdayofmonth(2,2,3) /* 3rd Mon in Feb: Washington's Birthday */
    || isdayofmonth(5,2,-1)/*last Mon in May: Memorial Day          */
    || isdayofmonth(9,2,1) /* 1st Mon in Sep: Labor Day             */
    || isdayofmonth(10,2,2)/* 2nd Mon in Oct: Columbus Day          */
    || isdayofmonth(11,5,4);/*4th Thu in Nov: Thanksgiving          */

UK holidays also require the iseaster function:

hol_uk =                     /* Bank holidays for England and Wales */
       (month()==1 && day()==1)                            /* Jan 1 */
    || (month()==1 && day()==2 && dayofweek() == 2) /* Jan 1 on Sun */
    || (month()==1 && day()==3 && dayofweek() == 2) /* Jan 1 on Sat */
    || iseaster(-2)                                  /* Good Friday */
    || iseaster(1)                                 /* Easter Monday */
    || isdayofmonth(5,2,1)                /* Early May Bank Holiday */
    || isdayofmonth(5,2,-1)                  /* Spring Bank Holiday */
    || isdayofmonth(8,2,-1)                  /* Summer Bank Holiday */
    || (month()==12 && day()==25)                  /* Christmas day */
    || (month()==12 && day()==26)                     /* Boxing day */
    || (month()==12 && day()==27 && dayofweek() == 3)/* Xmas on Sun */
    || (month()==12 && day()==27 && dayofweek() == 2)/* Xmas on Sat */
    || (month()==12 && day()==28 && dayofweek() == 3);/*Xmas on Sat */

11.6 Algebra function summary

Available functions are listed in Table Table:11.3. Any function operating on missing values returns a missing value. Any function which fails also returns a missing value. Where the argument is var, it must be just a variable name, e.g. one = 1; cum(one); is allowed, but cum(1) is not. Similarly: lag(CONS+1,1) is not allowed, while lag(CONS,1)+1 is.

Several examples of Algebra code were given above; for convenience these are summarized here:

    LX = log(X);
    DX = diff(X, 1);
    "log(X)" = log(X);
    aap = CONS + 1; /* comment /* nested comment */ */
    new1 = !season();
    cons2 = 2 * CONS - 1;
    cons3 = CONS / 3 - (cons2 + 5) * 1.55;
    Seasonal = season();
    new2 = Seasonal ? CONS : 0;
    new3 = Seasonal * CONS;
    new4 = Seasonal ? CONS;
    new5 = (CONS == MISSING) ? 0 : CONS;
    CONSlag1 = CONS[-1];
    X = INC + CONS[1980(1)];
    y[1955(1)] = 12;
    X = INC + CONS[0(0)];   // add first CONS value

Table:11.3 Algebra functions

Chapter 12 Batch Language

12.1 Introduction

The Batch language gives some control over OxMetrics through a command language. This allows for automating repetitive tasks, or as a quick way to get to a certain point in your analysis. Other programs (such as PcGive, STAMP and X12arima) extend this batch language with their own module-specific commands.

OxMetrics allows you to save the most recent model from the current module as a batch file (if supported by the module). If a model has been created interactively, it can be saved as a batch file for further editing or easy recall in a later session. This is also the most convenient way to create a batch file.

12.2 Executing Batch commands

If an error occurs while executing the Batch commands, the processing will be aborted, and control returned to OxMetrics. All successful statements up to that point will have been executed.

There are five ways of running Batch commands, as discussed in the next four sections.

12.2.1 Batch Editor (Alt+b)

The Tools/Batch Editor command activates the edit window in which you can edit/load/save a set of batch commands. The file extension used for batch files is .FL.

12.2.2 Batch from Results windows (Ctrl+b)

A text selection containing Batch commands can be run directly from that window using the Edit/Run as Batch command (or Ctrl+b as short cut).

12.2.3 Batch from the File/Open command

If you use File/Open, and set the file type to Run Batch file (*.fl), then the batch file is run immediately.

12.2.4 Batch from the Windows Explorer

You can double click on a .FL file in the Windows Explorer to run the file directly. If OxMetrics is not active yet, it will be started automatically.

12.2.5 Batch from a Batch file

A batch file can be called from another batch file, see §12.5.15.

12.3 Batch files and default folders

When a batch file is run, the working folder is set to that of the batch file. This allows data and algebra files which reside in the folder of the batch file to be found, even if the batch file is run from somewhere else. In addition the chdir command allows specifying a new default directory. Finally, paths to data files can be hard coded, but that is to be avoided if possible.

When a batch file is loaded in the batch editor, and then run, there will not be an associated default folder. However, the process of opening the batch file would set the default folder to that of the batch file.

12.4 General Batch command summary

Table Table:12.1 gives an alphabetical list of the OxMetrics batch language statements.

Table:12.1 Batch command summary

algebra {...}
appenddata("filename", "group"="");
appresults("filename");
break;
chdir("path");
closedata("databasename");
command("command_line");
database("name", year1, period1, year2, period2, frequency);
draw(area, "y", "mode"="");
drawf(area, "y", "function", d1=0, d2=0);
drawx(area, "y", "x", "mode"="");
drawz(area, "y", "x", "mode"="");
exit;
loadalgebra("filename");
loadbatch("filename");
loadcommand("filename");
loaddata("filename");
loadgraph("filename");
module("name");
package("packagename", "modeltype"="");
print("text");
printdate;
println("text");
savedata("filename");
savedrawwindow("filename", "window"="");
saveresults("filename");
setdraw("option", i1=0, i2=0, i3=0, i4=0, i5=0);
setdrawwindow("name");
show;
usedata("databasename", i1=0);

12.4.1 Comment

Anything between /* and */ is considered comment. Note that this comment cannot be nested. Everything following // up to the end of the line is also comment.

12.4.2 Command types

There are two types of batch commands:

12.4.3 Default arguments

Table Table:12.1 shows two instances of default arguments, in the appenddata command, and in the setdraw command. For example, when omitting the last argument as in

    appenddata("data.in7");

the command is actually interpreted as:

    appenddata("data.in7", "");

12.5 Batch commands

In the following list, function arguments are indicated by words, whereas the areas where statement blocks are expected are indicated by .... Examples follow the list of descriptions. For terms in double quotes, the desired term must be substituted and provided together with the quotes. A command summary is given in Table Table:12.1. Module specific commands are documented with each module (so, for PcGive batch commands consult Volume I of the PcGive books).

12.5.1 algebra {...}

Contains the algebra code to execute. The block of algebra should be enclosed in curly braces, for example:

algebra
{                           // Create SAVINGSL in database test
    SAVINGSL = lag(INC,1) - lag(CONS, 1);
    y = log(Y);
}

12.5.2 appenddata("filename", "group"="");

Appends the data from the named data file to the existing in-memory database. If no database exists yet, the named data file will be opened as in the loaddata() command. If the second argument is omitted, or equal to "" (that is, no group name is specified) the whole file will be appended, otherwise only the named group.

12.5.3 appresults("filename");

Append the contents of the Results window to the named file and clear the Results window.

12.5.4 break;

Stop the batch file, return to OxMetrics menus. While a batch file is running, there is no way of stopping it other than this batch command.

12.5.5 chdir("path");

Sets the current working folder to the specified path. There are three special forms of this command:

  1. chdir("#batch") sets the working folder to that of the batch file;

  2. chdir("#home") sets the working folder to that of the OxMetrics.exe executable file (but if it ends in \bin that will be deleted). If OxMetrics.exe is in its default folder \Program Files\OxMetrics\bin, then this command will set the working folder to \Program Files\OxMetrics.

  3. chdir("") prints the current working folder.

12.5.6 closedata("databasename");

Closes the database, which is currently loaded in OxMetrics. The database is closed without saving, so any changes which have been made since the last save are lost.

12.5.7 command("command_line");

Sends the line of text directly to the active module. The module must be able to accept commands (either via batch, or as an input console module).

12.5.8 database("name", year1, period1, year2, period2, freq);

Creates a database with the specified name and frequency, and sample period year1 (period1) to year2 (period2).

12.5.9 draw(area, "y", "mode"="");

Graphs variable y from the current database in the requested area (the first area has number 0). If the second argument is missing, the graph is a standard time-series plot. For other types of graphs, mode can be one of:

"bar" draw bars
"diff" take first differences of y
"dlog" growth rates (first difference of natural logarithm)
"index" draw index line
"log" take natural logarithms of y
"logscale" take natural logarithms and show on (natural) log scale
"match" match in variables area by means and ranges to first variable
"shading" draw shading
"startat100"scale the variable to start at 100.
"symbol" draw symbols as well as the line
"twoscale" as "match", but showing second variable in area on right-hand axis
"seasonal" draw seasonal sub-plot

12.5.10 drawf(area, "y", "function", d1=0, d2=0);

Graphs a function of the variable y from the current database in the requested area (the first area has number 0). The mode argument can be one of:

"acf" autocorrelation function with specified lag length
"boxplot" boxplot
"cdf" estimated distribution (QQ plot against normal)
"chisq" QQ plot against Chi2(d1)
"cumfreq" cumulative frequency count (for non-standard bars, specify the bar count)
"density" estimated density (for non-standard bars, specify the bar count)
"f" QQ plot against F(d1,d2)
"frequency" frequency count (for non-standard bars, specify the bar count)
"histogram" histogram (for non-standard bars, specify the bar count)
"normal" QQ plot against normal with same mean and variance
"pacf" partial autocorrelation function with specified lag length
"periodogram"periodogram
"spectrum" spectral density using specified lag length
"t" QQ plot against student-t(d1)
"uniform" Quantile plot (QQ against uniform)

12.5.11 drawx(area, "y", "x", "mode"="");

Graphs variable y against x from the current database in the requested area (the first area has number 0). This is a standard scatter plot, but if the second argument equals "", the graph is a standard time-series plot. For other types of graphs, mode can be one of:

"alt" use alternate style: x,y labels along axes
"project" add regression line with projections
"regression"add a regression line
"smooth" add a cubic spline (automatic bandwidth)

12.5.12 drawz(area, "y", "x", "mode"="");

Graphs variable y against x by z from the current database in the requested area (the first area has number 0). This is a standard scatter plot, but the second argument may equal "" for a time-series plot. The mode argument can be one of:

"bar" z is error bar
"band" z is error band
"fan" z is error fan
"hilo" high-low
"symbol" z is symbol size
"value" print values of z
For 3-dimensional graphs, the mode argument can be one of:
"contour" contour from scattered data; x,y,z are vectors
"contourx" contour from tabular data; x,y are vectors, z=z(x,y)
"contoury" contour from tabular data; x,y are vectors, z=z(y,x)
"points" sequence of 3D points
"surface" surface from scattered data; x,y,z are vectors
"surfacex" surface from tabular data; x,y are vectors, z=z(x,y)
"surfacey" surface from tabular data; x,y are vectors, z=z(y,x)
"trisurface"triangulated surface from scattered data; x,y,z are vectors

12.5.13 exit;

Stops the batch file and exits OxMetrics.

12.5.14 loadalgebra("filename");

Loads and executes the algebra code from the named .ALG file. The extension must be provided. See §12.3 on the default folder.

12.5.15 loadbatch("filename");

Loads and executes the batch code from the named .FL file. The extension must be provided. See §12.3 on the default folder.

12.5.16 loadcommand("filename");

Sends the contents of the named file to the active module. The module must be able to accept commands (either via batch, or as an input console module).

12.5.17 loaddata("filename");

Load the data from the named .IN7 file. To load, a full pathname would sometimes have to be specified, e.g. "c:\mydata\data.in7". The extension indicates the data type and must be provided. Inside OxMetrics, the database will then be known as data.in7, and will be the current default database. See §12.3 on the default folder.

If the database is already opened, the command works as usedata().

12.5.18 loadgraph("filename");

Load the graph from the named file. To load, a full pathname would sometimes have to be specified, e.g. "c:\mydata\data.in7". The extension indicates the file type and must be provided (but OxMetrics will always require the .gwg file for loading, so when using loadgraph("fig1.eps"), OxMetrics will look for fig1.gwg.

12.5.19 module("name");

Starts the specified module. When the module is already active, it becomes the focus for subsequent module-specific batch commands. Otherwise the module is started first.

12.5.20 package("packagename", "modeltype"="");

Used to specify the package and model type for modelling:

package("PcGive", "Single-equation");

12.5.21 print("text");

12.5.22 println("text");

Prints the specified text in the Results window. This can be useful to introduce explanatory notes. The println commands adds a new line after printing the text.

12.5.23 printdate;

Prints the current date and time in the Results window. The date and time are pasted into the text in ISO format yyyy-mm-dd hh:mm:ss, so putting the year first and using a 24-hour clock.

12.5.24 savedata("filename");

Save the current database to the named .IN7 file. The .BN7 file will get the same base name. If files with these names already exist, they will be overwritten!

12.5.25 savedrawwindow("filename", "window"="");

If no window is specified, the command saves the current Batch Graphics window to the named file (or gives an error message `Cannot save to' if there is no Batch Graphics window or the file cannot be saved). Otherwise it saves the named graphics window.

12.5.26 saveresults("filename");

Save the contents of the results to the named file and clear the Results window. If a file with that name already exists, it will be overwritten!

12.5.27 setdraw("option", i1=0, i2=0, i3=0, i4=0, i5=0);

This command changes the default settings used in graphics. The easiest way to use this command is to design the layout using the interactive dialogs (Graphics Setup and Postscript Setup). Then use the Write as batch command on both pages of the Graphics Setup dialog to record the batch code in the results window. This can then be pasted to the batch editor, and saved to a file. Or edited, and run directly from the results window.

option changes option changes
"axis" axis fonts/ticks "legendfontsize" legend font size
"axisline" axis options "legendhide" legend hiding
"axisformat" format of labels "legendresize"legend resizing
"box" box and grid "line" colour line settings
"bw" black&white settings "linebw" b&w line settings
"color" colour settings "margin" paper margins
"colormodel" PostScript model "palette_max" palette light colour
"default" reset default "palette_min" palette dark colour
"font" font "papercolor" Paper colour
"grid" grid style "printpage" PostScript paper
"histogram" bar colours "symbol" symbol settings
"legend" legend style "xystyle" cross-plot style

Use of the default option is as follows:

setdraw("default") reset all graphics defaults,
setdraw("default", 0) reset all graphics defaults,
setdraw("default", 1) reset layout, leave line types and colours,
setdraw("default", 2) reset line types and colours, leave layout.

The following table lists the integer arguments for each option, with the range of possible values. If no range is given, the argument is a size in pixel coordinates (see Ch. 13). The default width and precision for axisformat is 8 and 6 respectively.

option i1 i2 i3 i4 i5
"axis" fontsizestep tick
"axisline" no X-line:0--1no Y-line:0--1 :0--1 no small Y:0--1
"axisformat" widthprecision:0--1:0--1
"box" box:0--1X-grid:0--1 Y-grid:0--1
"bw" lineno:0--15red:0--255 green:0--255 blue:0--255
"color" lineno:0--15red:0--255 green:0--255 blue:0--255
"colormodel" model:0--3
"default" 0,1,2
"font" fontno:0--3fontsize
"grid" color:0--15type:0--15
"histogram" inside:0--15outside:0--15
"legend" boxed:0--1columns
"legendfontsize"
"legendhide" hide:0--1
"legendresize"resize:0--1
"line" lineno:0--15linetype:0--4 width on off
"linebw" lineno:0--15linetype:0--4 width on off
"margin" lefttop
"palette_max" index:0--7red:0--255 green:0--255 blue:0--255
"palette_min" index:0--7red:0--255 green:0--255 blue:0--255
"papercolor" red:0--255 green:0--255 blue:0--255
"printpage" :0--1papertype:0--2 X-size Y-size
"symbol" lineno:0--15symtype:0--4 size
"xystyle" :0--13d along axes:0--1

linetypepapertypecolormodel
solid 0 A4 0 black &white
dotted 1 Letter 1 black, white, gray
dashed 2 user defined2 gray
long dashes 3 color
user defined

symboltype
0 solid box 5 none 10 diamond
1 open box 6 line 11 solid diamond
2 plus 7 solid circle 12 cross
3 dash 8 triangle
4 circle 9 solid triangle

12.5.28 setdrawwindow("name");

Sets the name of the graphics window in which the graphs appear. The default is "Batch Graphics".

12.5.29 show;

Shows the graph created in batch. Note that graphs from draw/drawf/drawx/drawz commands are not displayed until the show command is issued.

12.5.30 usedata("databasename", i1=0);

Sets the default database to databasename. The database must already be loaded into OxMetrics. Normally, only the one-argument function would be used, e.g, usedata("ukm1.in7"). If the second argument is 1, the database is marked clean: when it is closed there is no prompt for saving it. This can be useful after a section of algebra, which implements basic transformation for a dataset. This can be used as follows:

loaddata("ukm1.in7");
loadalgebra("ukm1.alg");
usedata("ukm1.in7", 1);

12.6 Examples

We finish with two example batch files. The first uses most non-graphics Batch commands, as well as some commands from the PcGive module.

    database("test", 1950, 1, 2000, 4, 4);   // Create the database
                            // Append the tutorial data set to test
                // note that test has a longer sample then data.in7
    chdir("C:\Program Files\OxMetrics7"); // default install folder
                             // it is better to use chdir("#home");
    appenddata("data.in7");
    loaddata("data.in7");  // Load the tutorial data. Now there are
               // two databases, with data.in7 the default database
    usedata("test");              // make test the default database
    
    algebra
    {                           // Create SAVINGSL in database test
        SAVINGSL = lag(INC,1) - lag(CONS, 1);
    }
    package("PcGive", "Single-equation");
    system
    {
        Y = CONS;                        // The endogenous variable
        Z = Constant, CONS_1, CONS_2;             // the regressors
    }
    estimate("OLS", 1953, 3, 1992, 3, 8);
                 // Estimate the system by OLS over 1953(2)-1992(3)
                                            // withhold 8 forecasts
    println("Saving results to test.out");                                        
    saveresults("test.out");    // Save the contents of the Results
                         // window to test.out and clear the window
    testsummary;                             // Do the test summary
    println("Appending results to test.out");                                        
    appresults("test.out");   // Append the contents of the Results
                        // window to test.out, and clear the window
    
    break;                         // stop the batch run, remaining
                                   // commands will not be executed
    savedata("newtest.in7");// save test to newtest.in7/newtest.bn7
    exit;                              // Exit OxMetrics and PcGive

The final example uses many graphics batch commands, and is supplied as plots.fl with OxMetrics:

    chdir("#home");
    loaddata("data.in7");
    setdrawwindow("Time plots");
    draw(0, "CONS");
    draw(0, "INC","match");
    draw(1, "CONS");
    draw(1, "INC","twoscale");
    draw(2, "CONS","startat100");
    draw(2, "INC","startat100");
    draw(3, "CONS","log");
    draw(4, "CONS","logscale");
    draw(5, "CONS","dlog");
    show;
    
    setdrawwindow("Scatter plots");
    drawx(0, "CONS","INC","alt");
    drawx(1, "CONS","INC","regression");
    drawx(2, "CONS","INC","project");
    drawx(3, "CONS","INC","smooth");
    show;
    
    setdrawwindow("Function plots");
    drawf(0, "CONS","acf", 5);
    drawf(0, "CONS","pacf", 5);
    drawf(1, "CONS","periodogram");
    drawf(2, "CONS","spectrum", 5);
    drawf(3, "CONS","density");
    drawf(3, "CONS","histogram");
    drawf(4, "CONS","cdf");
    drawf(5, "CONS","frequency");
    drawf(6, "CONS","cumfreq", 20);
    drawf(7, "CONS","boxplot");
    drawf(8, "CONS","normal");
    show;
    
    algebra
    {
        z = fabs(INC - 890) * 10;
    }
    usedata("data.in7", 1);  // mark as clean
    
    setdrawwindow("Z plots");
    drawz(0, "CONS","","z", "bar");
    drawz(1, "CONS","","z", "band");
    drawz(2, "CONS","","INC", "hilo");
    drawz(3, "CONS","INC","z", "value");
    drawz(4, "CONS","INC","z", "symbol");
    show;
    
    database("3d_scatter", 1, 1, 625, 1, 1);
    algebra
    {   x = (ranu() - 0.5) * 5;
        y = (ranu() - 0.5) * 5;
        z = exp(-x^2-y^2);
    }
    setdrawwindow("3D contour plots");
    drawz(0, "x","y","z", "contour");
    show;
    
    setdrawwindow("3D surface plots");
    drawz(0, "x","y","z", "surface");
    drawz(1, "x","y","z", "trisurface");
    show;

Chapter 13 OxMetrics Graphics

13.1 Graphics paper

Graphs in OxMetrics are drawn on a graphics worksheet, consisting of 10000 by 15000 pixels, with (0,0) in the bottom left corner:

These pixels are virtual and different from screen pixels: the paper is always 10000 ×15000, regardless of the screen resolution or the size on screen.

Positions can be specified in pixel coordinates, as for example (px,py) =(700,3200). More often it is convenient to use real-world coordinates to map the pixel coordinates into real data values. This is done by specifying an area on the graphics worksheet, and attaching real-world coordinates to it. These areas are allowed to overlap, but need not:

The areas are numbered from left to right and top to bottom, counting starts at zero. Suppose we have set up all areas as being from (x,y)=(0.0,0.0) to (x,y)=(1.0,1.0) (again within each area the origin is the lower left corner). Then we can draw a line through area 2 in two ways:

  1. in real coordinates within an area
    1. step 1: select area 2;
    2. step 2: move to (0.0, 0.0);
    3. step 3: draw a line to (1.0,1.0).

  2. using pixel coordinates on the worksheet
    1. step 1: move to pixel coordinates (600,600);
    2. step 2: draw a line to pixel coordinates (3600, 3600).

where we assume that (600,600) to (3600,3600) are the pixel coordinates chosen for area 2. Drawing in real-world coordinates has the advantage that it corresponds more closely to our data.

13.2 Creating graphs

A graph is created from data in a database using the Graphics toolbar button, or Model/Graphics. These graphs appear in the window labelled OxMetrics Graphics. Subsequent graphs are added to this window. To start from scratch, close the window, or select and delete each area. To keep the existing OxMetrics graphics window and open a new one for subsequent graphs, use File/New Data Plot Window (note that the menu contents change according to the type of window which is active).

Modules such as PcGive will put their graphs in a window with a different name.

13.2.1 Actual series with optional transformations

plots the actual values of all selected variables against time (or the observation index for undated series), together or each in a separate graph. If there are missing values, these show up as gaps in the line.

13.2.2 Multiple series with optional transformations

13.2.3 Scatter plots

The available scatter-plot types are:

The Style, Regression and Smoothing sections allow additional options and combinations.

If there are missing values, these are omitted from the graphs.

13.2.4 Distribution

13.2.5 Time-series: ACF etc.

13.2.6 QQ plots

QQ (quantile-quantile), or cross-probability, plots:

As discussed in the companion book on PcGive, statisticians view variables as being described by probability distributions. If X is the variable, and x a value it could take, then

Px( X>x)

is the probability that the value is in fact greater than x. For example, if the variable is the height of a child, when x is one metre, Px( X>1) is the probability that the child is taller than a metre. The values of x can be any number, but Px( .) cannot be negative or exceed unity. Plotting Px( X>x) against x generates an ∫-shaped curve (but more stretched out horizontally), which is hard to interpret.

When X has a uniform distribution over ( 0,1) , if Px( .) is plotted against x in a unit square, the result is a straight line. A similar idea applies to all distributions and QQ plots can be selected so some reference distribution is a straight line with the empirical distribution compared to it.

The QQ plot options page on the Graphics dialog allows for a choice of reference distributions. For the t, F and χ2 distribution it is necessary to also supply the degrees of freedom arguments. Drawing a variable against a uniform results in a so-called quantile plot.

13.2.7 Two series by a third

13.2.8 3-dimensional plots

With 3-dimensional plots there are two ways of presenting the data: as a scatter of points in three-dimensional space, or as a table with the X and Y values along the side, and the Z values in the cells. The tabular format specifies the 3D surface directly, whereas for the scatter it is left to OxMetrics to work out the surface. Although the tabular format leads to better results, the scatter is easier to use, as it requires only three variables.

To create a surface from a scatter, OxMetrics derives a triangulation, and from the triangulation a smooth surface. This method works best when the surface is smooth.

There are a few additional edit actions available for 3-dimensional graphs:

13.3 Printing graphs

Select File/Print to print to an attached printer and File/Print Preview to first view the results. The following control of headers and footers is available for printing from File/Print Page Setup:

Other print setup options are printer specific.

Use File/Print Preview to view the result before printing. Note that colours are shown in the preview, but will come out in grey levels (unless you have a colour printer of course).

13.4 Graphics formats

Graphs can be saved to disk in various formats:

The GWG format is particular to OxMetrics; no other program can read it and no printer can handle it. OxMetrics requires the GWG format, because it needs to be able to allow re-editing of the graph when it is reloaded; the other formats do not store sufficient information.

When you save a graph in any format, the GWG file is automatically saved alongside it. Then, when loading a previously saved EPS file (say), OxMetrics can use the GWG file to reload the graph.

13.5 Saving and loading graphs

Use File/Save As or the diskette toolbar button to save the graph to a file. At the bottom of the dialog is a dropdown listbox in which you select the type of file.

When you save a graph in any format, the GWG file is automatically saved alongside it. Then, when loading a previously saved EPS file (say), OxMetrics can use the GWG file to reload the graph.

Choose File/Open, to open a previously saved graphics file type.

13.6 Editing graphs

Each graph consists of a collection of objects, which in most cases can be manipulated, moved or deleted. The main one, the area, was introduced in §13.1.

13.6.1 Graph layout

An area defines a rectangle on the paper which has world coordinates attached to it. The concept of areas enables multiple graphs on the paper, up to 36. Areas are allowed to overlap.

The Graph Layout page of the Edit Graphics dialog allows for making adjustments that are relevant for the whole graph. Activate this through Edit/Edit Graph, or by double clicking in an area. You can:

13.6.2 Area layout

By default, an area has `automatic' pixel coordinates, which means that, when an area is added, the pre-existing area will automatically shrink to make space. An area can be selected with the mouse, and moved around the paper. This changes the automatic paper positioning into a fixed position. Real world coordinates are also selected automatically, but can be set to fixed values.

The Area Layout page of the Edit Graphics dialog contains the settings that relate to positioning and layout of each individual area. You can:

The Edit menu allows you to rotate 3-dimensional graphs. This applies to the currently selected 3D area, or all 3D areas if none is selected:

13.6.3 Variable against time, scatter, or 3D

The title of this section is derived from the variables being plotted, such as CONS x (time) x z or INC x (time).

The variable (or vector) is the main graphics object: it consists of a sequence of observations, graphed against time or another variable. A variable cannot be moved, nor can observations be moved on screen. There are essentially four types of vectors:

The Lines page of the Graphics Property dialog controls how the vector is displayed. The line type joining the observations can be:

Style allows a choice of the colour or pattern for the currently selected entry; the type choice is repeated in the drop-down box. The colour with which lines and symbols are drawn is set in the first column; the line width and pattern is set in the second combo box. In both cases an entry is selected from one of the 16 defined line types. These can be changed in Model/Preferences/Graphics Setup

The observations can be marked by a symbol, and the style and size of that symbol can be set in the third column.

For 3D graphs it is possible to change the colour palette, or add contour lines (but not for a triangulation). The global palette definition is set in Model/Graphics Setup

The entries used in the legend can be changed by renaming the labels of the variables in the X, Y, Z label boxes. If there is no name, that component will be omitted from the legend label for the vector: if all labels are empty, the legend entry will be omitted alltogether.

13.6.3.1 Error bars

Error bar options are only shown if the line object has error bars. Then you can switch between bars, bands and fans, choose a color for the bars/bands. A multiplication factor may also be set for error bars and bands. For example, if the data in the Z variable are standard errors, then a factor 2 will show the data plus/minus 2 standard errors (which would be a 95confidence interval if the data come from a normal distribution).

To rename a label for the selected vector, click on Rename, or double-click on the vector in the list box.

13.6.3.2 Regression, Scale

The Regression, Scale page of the Edit Graphics dialog allows adding regression lines to variables, and adjustment of the scaling (relative to the selected variable):

The scale and shift factor can also be set directly.

The regression options in this page are:

13.6.4 Axes

An X and Y axis (and Z for 3D graphs) is added automatically to each graph. Usually the default suffices, but a large number of adjustments can be made in the Axis entries of the Edit Graphics dialog.

13.6.4.1 Settings for non-default labelling

Each axis consists of (values are in world coordinates):

These values are all set to a default, but can be changed when Default labelling is unchecked.

13.6.4.2 Location and transformation

The location and transformation settings further position and define the axis:

13.6.4.3 Style

The following adjustments can be made to an axis (all adjustments apply to the current axis only):

13.6.4.4 Label style

Note that you may have as many axes as you wish. Axes can be selected on screen with the mouse.

13.6.5 Legend style

Legends are added automatically in an appropriate size, unless the legend font gets too small. In that case (normally with more than sixteen areas), the legend will be omitted. In addition, a legend can be hidden, and subsequently unhidden.

Legends can be selected with the mouse, and moved around. Deleting the legend results in it being hidden. The available options in the Legend style page of the Edit Graphics dialog are:

13.6.6 Histogram

The only available options for histograms is to select a line color/pattern for the outside line and for the area inside the boxes.

13.6.7 Copy properties to other areas

Some aspects of one area can be copied to all other areas in the graph:

13.6.8 Text

Text can be added from the Edit menu using Add Text. Text belongs to an area, in which case it is deleted if the area is deleted (or copied when the area is copied). Text entered outside any area will be part of area 0. More than one line of text can be entered at a time. Text can also be rotated, by specifying the angle in degrees. This does not work so well for multiple line text blocks. Text entered immediately above the graph will have the title property, which means that it is moved with the area when the area is moved.

Text uses a LaTeX-style of formatting, see §13.9.

13.6.9 Lines and symbols

Lines can be added from the Edit menu using Draw. Line coordinates may be specified in world coordinates (the default when the line is drawn inside an area), in which case the line is deleted if the area is deleted (or copied when the area is copied). Alternatively, lines may be specified in pixel coordinates. The appearance of a line can be changed to a box or a solid box.

13.6.10 Adding, moving and deleting objects

Objects are added from the Edit menu. Most objects can be selected with the mouse, and moved and deleted subsequently.

13.6.11 Pointing

The status bar shows the graphics coordinates of the the mouse.

13.6.12 Graphics setup

Persistent setup for graphics is set through the Model/Preferences/Graphics Setup dialog.

13.7 Copy and paste

There is a distinction between use of the clipboard inside OxMetrics, and that for external use. There are three copy commands:

  1. Copy is for internal use.

    When no area is selected, the whole graphics window is copied. When an area is selected, only that is copied to the clipboard. These clipboard items are not recognized by other programs.

    When a OxMetrics graphics format is on the clipboard, it can be added to an existing graph (no area selected) or to an existing area (which must be selected). Copying in the internal format is delayed, which means that the full copying is not actually performed until a paste is requested. This implies that when a graphics window is closed it is not available for pasting anymore.

  2. Copy Bitmap to Clipboard copies the whole graphics window in bitmap format. This can be pasted into other programs that recognize bitmaps.

  3. Copy Metafile to Clipboard copies the whole graphics window in EMF format, from which is a vector format that can be pasted into other programs.

It is not possible to paste from other programs into OxMetrics graphs, with the exception of text.

13.8 Graphs and sample selection

All types of graphs will use all valid observations, just skipping over missing values.

13.9 Text formatting

Text uses a LaTeX-style of formatting, which allows for complex mathematics be used to annotate graphs. OxMetrics implements a subset of the normal LaTeX commands, and mathematics is typeset using the Symbol font.

Mathematics is enclosed in $...$; superscripts and subscripts are only allowed in math mode. A superscript is written as ^{...}, a subscript as _{...}. For example, $\hat \epsilon _{i-1}^{k+1}$ gives ε̂ i-1k+1. Tables Table:13.1 to Table:13.6 list the mathematics symbols which are available in OxMetrics.

The entries in Tables Table:13.7 to Table:13.8 do not require math mode. Note that, to write $ \ _ { } % you must enter \$ \\ \_ \{ \} \% respectively (\\ for a backslash is not standard in LaTeX, where it denotes a line break).

Table:13.1 Greek symbols

α \alpha θ \theta o o υ \upsilon
β \beta θ \vartheta π \pi φ \phi
γ \gamma ι \iota π \varpi φ \varphi
δ \delta κ \kappa ρ \rho χ \chi
ε \epsilon λ \lambda ρ \varrho ψ \psi
ε \varepsilon μ \mu σ \sigma ω \omega
ζ \zeta ν \nu σ \varsigma
η \eta ξ \xi τ \tau
Γ \Gamma Λ \Lambda Σ \Sigma Ψ \Psi
Δ \Delta Ξ \Xi Υ \Upsilon Ω \Omega
Θ \Theta Π \Pi Φ \Phi

Table:13.2 Arrows

\ \ \arrowext* \Leftarrow \Rightarrow
\downarrow \leftarrow \rightarrow
\Downarrow \Leftrightarrow \uparrow
\leftrightarrow \Uparrow
\leftarrow\arrowext
* indicates that the command is not a standard LaTeX command.

Table:13.3 Mathematics accents

á \acute a \dot a à \grave a \tilde a
a \bar a \ddot a \hat a

Table:13.4 Foreign and accented characters

å\aa æ\ae ø\o ß\ss
Å\AA Æ\AE Ø\O
á \'a \^a \~a \.a
à \`a \"a \=a

Table:13.5 Mathematical symbols

\aleph \exists | \mid \rfloor
\angle \forall ¬ \neg ~ \sim
\approx \geq \neq \spadesuit
* \ast > \gt* or >\ni \subset
\bullet \heartsuit \oplus \subseteq
\cap \Im \otimes \sum
. \cdot \in \partial \supset
\clubsuit \infty \perp \supseteq
\cong \int ± \pm \surd
\cup \langle ' \prime \therefore
° \degree \lceil \prod × \times
\Diamond ... \ldots ~ \propto \triangledown
\diamondsuit \leq \rangle \vee
/ \div \lfloor \rceil \wedge
\emptyset < \lt* or <\Re \wp
\equiv
* indicates that the command is not a standard LaTeX command.

Table:13.6 Log-like symbols

arccos \arccos csc \csc ker \ker min \min
arcsin \arcsin deg \deg lg \lg Pr \Pr
arctan \arctan det \det lim \lim sec \sec
arg \arg dim \dim liminf \liminf sin \sin
cos \cos exp \exp limsup \limsup sinh \sinh
cosh \cosh gcd \gcd ln \ln sup \sup
cot \cot hom \hom log \log tan \tan
coth \coth inf \inf max \max tanh \tanh

Table:13.7 Miscellaneous symbols

©\copyright \P §\S
Euro* \euro £\pounds tm \trademark*
f \florin* O\registered*
$\$ \ \\ _\_
{\{ }\} %\%
* indicates that the command is not a standard LaTeX command.

Table:13.8 Fonts and sizes

bold \bf roman \rm small \small
bold italic \bi sans serif \sf large \large
font 0 to 9 \f0 -- \f9typewriter \tt normalsize \normalsize
italic \it

Chapter 14 OxMetrics Data Management

14.1 Creating data

File/New allows for the creation of a new database. All variables in a database have the same frequency. A sample period is required, but can be extended or changed later.

14.2 Database font

View/Increase Text Size and View/Decrease Text Size are useful to select a smaller or larger font size for displaying the database on screen.

14.3 Database description

A database can have a description for documentation purposes, and separate from the variable description. Only .in7/.bn7 data files can preserve the description.

14.4 Printing data

Use File/Print when a database has the focus to print the database. File/Print Preview is available to view the result before printing.

Select File/Print to print to an attached printer and File/Print Preview to first view the results. The following control of headers and footers is available for printing from File/Print Page Setup:

14.5 Data formats

The data format specific to OxMetrics consists of a pair of files with extensions .in7 and .bn7. The latter is a binary file containing the actual data, whereas the .in7 file holds the information on the contents of the binary file such as variable names, sample periods, frequencies etc. The information file is a human-readable file, the .bn7 is binary and is not human-readable.

In addition, OxMetrics can read and write human-readable files, Excel spreadsheet files, comma-separated files, and GAUSS and Stata files.

14.6 Summary statistics

This command prints the name of the database, the sample period and number of variables to the Results window. For each variable in the database the name is printed as well as:

leading sample
-- the first valid sample period without missing values,
#obs
-- number of valid observations,
#miss
-- number of observations with missing values,
minimum
-- minimum value,
mean
-- mean of valid observations, see (eq:10.1),
maximum
-- maximum value,
std.dev
-- standard deviation of valid observations, see (eq:10.1).

14.7 Saving data

Use File/Save As or the diskette toolbar button to save the data to a disk file. At the bottom of the dialog is a dropdown listbox in which you select the type of file.

14.8 Navigation and editing

A database cursor indicates which is the current observation. The cursor can be moved from the keyboard or using the mouse. A block of observations can be selected (highlighted) for:

Press Enter or double click on an observation to edit the value. Single click on a cell with the cursor will give access to the inline editor. Algebra and the Calculator allows manipulation of variables through mathematical expressions.

14.9 Renaming variables

Press Enter or double click on the variable name in the database to change the name or documentation. When in the Calculator or the Algebra Editor, click Ren when a variable is selected in the list box to rename.

14.10 Deleting variables

Click on the variable name in the database to select the variable (or a group of variables), then press the Del key to delete (confirmation of the deletion will be required). When in the Calculator, press the Del buttonwhen a variable is selected in the list box to delete, confirmation will be required again.

14.11 Reordering variables

The variables listbox in the Calculator and Algebra Editor allows variables to be picked up with the mouse and moved down or up in the listbox.

14.12 Adding variables

Double click on an empty field in the database next to an existing variable to create a new variable. Alternatively use Edit/New Variable.

14.13 Extending or reducing the sample period

Double click on an empty field in the database below an existing variable to activate the Extend Database sample dialog. Alternatively use Edit/Extend sample. Enter a negative value to reduce the sample size.

The Change Sample option on the Edit menu allows the following actions:

14.13.1 Changing the sample period

The Change Sample option on the Edit menu allows changing the start year and period, as well as the frequency. The number of observations remains unchanged, and no data will be lost.

14.14 Copy and paste

The standard copy and paste facilities are available, also see §14.8.

14.15 Appending data

A database can be appended from disk to an open database, using Append Data File when right clicking on a database in the workspace. This requires the frequencies to match. OxMetrics will make additional adjustments when these are required:

14.16 Daily, weekly and timed data

The calendar

[Note: The calendar is Gregorian from 15 October 1582 onwards, and Julian before (so there is no year 0: year -1 precedes year 1; day 0 is on Julian date 1 January -4713). ]

index used by OxMetrics is the Julian day number. For example, Julian day 2453402 corresponds to 2005-01-31. An optional fractional part specifies the fraction of the day: 2453402.75 corresponds to 2005-01-01T18:00. If the day number is zero, it is interpreted as a time only, so 0.75 is just 18:00 (6 PM).

[Note: This is similar to how Excel stores dates and times.]

OxMetrics uses the ISO representation yyyy-mm-dd, and the 24 hour clock for time, hh:mm:ss:.hhh. A date with a time are joined by the letter T, as shown above.

In many fields it is possible to enter a date or time, which is then automatically translated to the internal representation. Years with week number are then also recognised, e.g. 1976-W3 returns the calendar index for the Monday of week 3 in 1976. (Week 1 is the first week that contains the first Thursday; or equivalently, the week that contains 4 January.)

OxMetrics uses two methods for dating a database:

Fixed frequency
Denoted by a start year, start period and frequency. From this, the date of any subsequent observation can be worked out. For example, if the start year is 2005, the start period 1, and the frequency 4 (quarterly), then the sixth observations is for 2006(2), the second quarter. This works well for monthly, quarterly and annual data. For undated data we simply set the start year and period to one, and the frequency as well.

Dated
The fixed frequency method does not work for weekly or daily data: not every year has the same numbers of observations. The solution adopted in OxMetrics is as follows: an integer value represents a date. A database variable can be classified as of type date, in which case the date is displayed, rather than the underlying value.

The following criteria must be satisfied for a database to be dated:

Note that the fixed sample period is still available for a dated database, but this is usually set as for an undated database (start year, start period, frequency all set to one).

Also note that the first variable in a dated database (which defines the calendar dates of the observations) is a variable as any other: it can be renamed, transformed, moved, deleted, etc. But some of these will make the database undated again.

References

Davidson, J. E. H., D. F. Hendry, F. Srba, and J. S. Yeo (1978). Econometric modelling of the aggregate time-series relationship between consumers' expenditure and income in the United Kingdom. Economic Journal 88, 661--692. Reprinted in Hendry, D. F., Econometrics: Alchemy or Science? Oxford: Blackwell Publishers, 1993, and Oxford University Press, 2000; and in Campos, J., Ericsson, N.R. and Hendry, D.F. (eds.), General to Specific Modelling. Edward Elgar, 2005.

Doornik, J. A. (2006). The role of simulation in econometrics. In T. Mills and K. Patterson (Eds.), Palgrave Handbook of Econometrics, pp. 787--811. Basingstoke: Palgrave MacMillan.

Doornik, J. A. (2013). Object-Oriented Matrix Programming using Ox (7th ed.). London: Timberlake Consultants Press.

Doornik, J. A. and D. F. Hendry (2013). Interactive Monte Carlo Experimentation in Econometrics Using PcNaive (3rd ed.). London: Timberlake Consultants Press.

Doornik, J. A. and M. Ooms (2005). Outlier detection in GARCH models. Discussion paper 2005-w24, Nuffield College.

Doornik, J. A. and M. Ooms (2008). Multimodality in the GARCH regression model. International Journal of Forecasting 24, 432--448.

Engler, E. and B. Nielsen (2009). The empirical process of autoregressive residuals. Econometrics Journal 12, 367--381.

Golub, G. H. and C. F. Van Loan (1989). Matrix Computations. Baltimore: The Johns Hopkins University Press.

Granger, C. W. J. (1966). The typical spectral shape of an economic variable. Econometrica 34, 150--161.

Granger, C. W. J. and P. Newbold (1986). Forecasting Economic Time Series, (2nd ed.). New York: Academic Press.

Green, P. J. and B. W. Silverman (1994). Nonparametric Regression and Generalized Linear Models. A Roughness Penalty Approach. London: Chapman and Hall.

Hall, B. H. and C. Cummins (2005). Time Series Processor 5.0 User's Guide. Palo Alto, CA: TSP International.

Härdle, W. (1990). Applied Nonparametric Regression. Cambridge: Cambridge University Press.

Harvey, A. C. (1993). Time Series Models, (2nd ed.). Hemel Hempstead: Harvester Wheatsheaf.

Hastie, T. J. and R. J. Tibshirani (1994). Generalized Additive Models. London: Chapman and Hall.

Hendry, D. F. and J. A. Doornik (2013). Empirical Econometric Modelling using PcGive: Volume I (7th ed.). London: Timberlake Consultants Press.

Koopman, S. J., A. C. Harvey, J. A. Doornik, and N. Shephard (2013). Structural Time Series Analysis, Modelling, and Prediction using STAMP (5th ed.). London: Timberlake Consultants Press.

Laurent, S. (2013). G@RCH Professional 7 (5th ed.). London: Timberlake Consultants Press.

Makridakis, S., S. C. Wheelwright, and R. C. Hyndman (1998). Forecasting: Methods and Applications (3rd ed.). New York: John Wiley and Sons.

Nielsen, B. (2006). Correlograms for non-stationary autoregressions. Journal of the Royal Statistical Society B 68, 707--720.

Priestley, M. B. (1981). Spectral Analysis and Time Series. London: Academic Press.

Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. London: Chapman and Hall.