0% found this document useful (0 votes)
898 views238 pages

Oxmetrics Manual

oxmetrics manual by Doornik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
898 views238 pages

Oxmetrics Manual

oxmetrics manual by Doornik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 238

Jurgen A.

Doornik

An Introduction to

OxMetricsTM 7

OxMetrics 7
Published by Timberlake Consultants Ltd
www.timberlake.co.uk
www.timberlake-consultancy.com
www.oxmetrics.net, www.doornik.com

An Introduction to OxMetricsTM 7
A Software System for Data Analysis and Forecasting
c
Copyright 2013
Jurgen A Doornik
First published by Timberlake Consultants in 2005
Revised in 2007, 2009, 2013
All rights reserved. No part of this work, which is copyrighted, may be reproduced
or used in any form or by any means graphic, electronic, or mechanical, including
photocopy, record taping, or information storage and retrieval systems without the
written consent of the Publisher, except in accordance with the provisions of the
Copyright Designs and Patents Act 1988.
Whilst the Publisher has taken all reasonable care in the preparation of this book, the
Publisher makes no representation, express or implied, with regard to the accuracy
of the information contained in this book and cannot accept any legal responsability
or liability for any errors or omissions from the book, or from the software, or the
consequences thereof.

British Library Cataloguing-in-Publication Data


A catalogue record of this book is available from the British Library
Library of Congress Cataloguing-in-Publication Data
A catalogue record of this book is available from the Library of Congress
Jurgen A Doornik
p. cm. (An Introduction to OxMetricsTM 7 A Software System for Data
Analysis and Forecasting)
ISBN 978-0-9571708-0-3

Published by
Timberlake Consultants Ltd
Unit B3, Broomsleigh Business Park
London SE26 5BN, UK
http://www.timberlake.co.uk

842 Greenwich Lane


Union, NJ 07083-7905, U.S.A.
http://www.timberlake-consultancy.com

Trademark notice
All Companies and products referred to in this book are either trademarks or registered trademarks of their associated Companies.

Contents

Front matter

iii

Contents

List of Figures

xiii

List of Tables

xv

Preface
1

Introduction and Overview


1.1
Supported platforms . . . .
1.1.1
Folder structure . .
1.2
What is new? . . . . . . . .
1.3
Availability . . . . . . . . .
1.4
Citation . . . . . . . . . . .
1.5
Help . . . . . . . . . . . . .
1.6
Modular structure . . . . . .
1.7
Registration . . . . . . . . .
1.8
Upgrades . . . . . . . . . .
1.9
Algebra . . . . . . . . . . .
1.10 Batch . . . . . . . . . . . .
1.11 Data storage . . . . . . . . .
1.12 Filenames and extensions . .
1.13 Output storage . . . . . . .
1.14 Sample periods . . . . . . .
1.15 Status bar . . . . . . . . . .
1.16 Tool bars . . . . . . . . . .
1.17 Documentation conventions

xvii

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

3
3
4
4
5
5
5
5
6
6
6
7
7
7
8
8
8
9
10

Getting Started: Windows


2.1
Starting OxMetrics . . . . . . . . . . . . . . . . . . . . . . . . .
2.2
Registering OxMetrics . . . . . . . . . . . . . . . . . . . . . . .

11
12
12

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

vi

CONTENTS
2.3
2.4

2.5
2.6
2.7
3

Loading and viewing the tutorial data set . . .


OxMetrics graphics . . . . . . . . . . . . . . .
2.4.1
A first graph . . . . . . . . . . . . . .
2.4.2
Multiple graphs . . . . . . . . . . . .
2.4.3
Graph saving and printing . . . . . .
2.4.4
Using the clipboard for graph pasting
Calculator . . . . . . . . . . . . . . . . . . . .
Algebra . . . . . . . . . . . . . . . . . . . . .
The workspace . . . . . . . . . . . . . . . . .

Getting Started: OS X
3.1
Starting OxMetrics . . . . . . . . . . . . . . .
3.2
Registering OxMetrics . . . . . . . . . . . . .
3.3
Loading and viewing the tutorial data set . . .
3.4
OxMetrics graphics . . . . . . . . . . . . . . .
3.4.1
A first graph . . . . . . . . . . . . . .
3.4.2
Multiple graphs . . . . . . . . . . . .
3.4.3
Graph saving and printing . . . . . .
3.4.4
Using the clipboard for graph pasting
3.5
Calculator . . . . . . . . . . . . . . . . . . . .
3.6
Algebra . . . . . . . . . . . . . . . . . . . . .
3.7
The workspace . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

13
16
16
19
21
21
22
24
25

.
.
.
.
.
.
.
.
.
.
.

28
29
30
30
34
34
36
38
38
39
41
43

Getting Started: Linux


4.1
Starting OxMetrics . . . . . . . . . . . . . . .
4.2
Registering OxMetrics . . . . . . . . . . . . .
4.3
Loading and viewing the tutorial data set . . .
4.4
OxMetrics graphics . . . . . . . . . . . . . . .
4.4.1
A first graph . . . . . . . . . . . . . .
4.4.2
Multiple graphs . . . . . . . . . . . .
4.4.3
Graph saving and printing . . . . . .
4.4.4
Using the clipboard for graph pasting
4.5
Calculator . . . . . . . . . . . . . . . . . . . .
4.6
Algebra . . . . . . . . . . . . . . . . . . . . .
4.7
The workspace . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

45
46
47
47
51
51
55
56
57
57
60
62

OxMetrics Modules
5.1
OxMetrics Modules . . . . . . . .
5.2
Financial data . . . . . . . . . . .
5.3
Weekly and daily data . . . . . .
5.4
PcGive . . . . . . . . . . . . . .
5.4.1
Formulate a model . . .
5.5
TSP . . . . . . . . . . . . . . . .
5.5.1
TSP in interactive mode .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

64
64
64
67
68
69
73
73

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

vii

CONTENTS
5.5.2
5.5.3
5.5.4
6

TSP Help . . . . . . . . . . . . . . . . . . . . . . . . .
TSP in batch mode . . . . . . . . . . . . . . . . . . . .
Explorer options . . . . . . . . . . . . . . . . . . . . . .

75
76
76

Tutorial on Graphics
6.1
Descriptive graphics . . . . . . . . . . . . . . . . .
6.2
Actual series with optional transformations . . . . .
6.3
Multiple series with optional transformations . . . .
6.4
Scatter plots . . . . . . . . . . . . . . . . . . . . . .
6.5
Distribution . . . . . . . . . . . . . . . . . . . . . .
6.5.1
Density estimation: Histogram and density .
6.5.2
Distribution . . . . . . . . . . . . . . . . .
6.5.3
Frequencies . . . . . . . . . . . . . . . . .
6.5.4
Box plot . . . . . . . . . . . . . . . . . . .
6.6
Time-series: ACF etc. . . . . . . . . . . . . . . . .
6.6.1
Autocorrelation function or correlogram . .
6.6.2
Partial autocorrelation function (PACF) . .
6.6.3
Cross-correlation function . . . . . . . . .
6.6.4
Spectrum and periodogram . . . . . . . . .
6.7
QQ plots . . . . . . . . . . . . . . . . . . . . . . .
6.8
Two series by a third . . . . . . . . . . . . . . . . .
6.9
3-dimensional plots . . . . . . . . . . . . . . . . . .
6.9.1
Surface from scatter . . . . . . . . . . . . .
6.9.2
Surface from table . . . . . . . . . . . . . .
6.10 Conclusions . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

79
79
82
84
84
87
87
87
89
89
90
90
91
91
91
92
94
96
96
98
99

Tutorial on Graph Editing


7.1
Multiple graphs . . . . . . . . . . . .
7.2
Graphics paper: areas and coordinates
7.3
Graphics view . . . . . . . . . . . . .
7.4
New Data Plot Window . . . . . . . .
7.5
Copy and paste . . . . . . . . . . . .
7.6
About line colour and style . . . . . .
7.7
Editing graphs: Graphics properties .
7.8
Graphics setup . . . . . . . . . . . .
7.9
Adding to and removing from a graph
7.10 Drawing . . . . . . . . . . . . . . . .
7.11 Adding text and variables . . . . . . .
7.12 Legends . . . . . . . . . . . . . . . .
7.13 Scaling variables . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

100
100
100
102
102
102
103
103
107
108
109
110
110
111

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

viii
8

CONTENTS
Tutorial on Data Input and Output
8.1
Open Data File and file types . . . . . . . . . . . . . . . .
8.2
From paper to OxMetrics . . . . . . . . . . . . . . . . . .
8.2.1
Directly into the database . . . . . . . . . . . . .
8.2.2
Using the clipboard; using OxMetrics as editor .
8.3
From OxMetrics to disk . . . . . . . . . . . . . . . . . .
8.4
From disk to OxMetrics . . . . . . . . . . . . . . . . . .
8.4.1
Loading OxMetrics files . . . . . . . . . . . . .
8.4.2
Loading spreadsheet files . . . . . . . . . . . . .
8.4.3
Loading a human-readable (text) file . . . . . . .
8.5
Adding variables using the clipboard . . . . . . . . . . . .
8.6
Changing the sample period . . . . . . . . . . . . . . . .
8.6.1
Extending the sample period . . . . . . . . . . .
8.6.2
Reset starting date . . . . . . . . . . . . . . . . .
8.7
Appending data . . . . . . . . . . . . . . . . . . . . . . .
8.8
Working with daily and weekly data . . . . . . . . . . . .
8.8.1
Using Change Sample to create a daily database .
8.8.2
Using Algebra to create a daily database . . . . .
8.9
Working with choice variables . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

113
114
114
114
117
119
119
119
119
120
120
121
121
121
121
122
123
124
125

Tutorial on Data Transformation


9.1
Calculator . . . . . . . . . . . . . . . .
9.2
Advanced algebra . . . . . . . . . . . .
9.2.1
Introduction . . . . . . . . . .
9.2.2
Database for advanced algebra
9.2.3
Statistical distributions . . . .
9.2.4
Random number generators . .
9.2.5
Generating data . . . . . . . .
9.2.6
Smoothing data . . . . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

128
128
130
130
130
130
133
135
137

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 . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

141
141
141
142
142
142
143
143
144
144
145
146
147
148

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

ix

CONTENTS
10.12 Box plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10.13 Exponentially-weighted moving average (EWMA) . . . . . . . .
10.14 Exponentially-weighted moving correlation . . . . . . . . . . . .

149
149
149

11 OxMetrics file formats


11.1 OxMetrics data files (.in7/.bn7) . . . . . . . . . . . . . .
11.1.1 The .in7 file format . . . . . . . . . . . . . . . .
11.1.2 The .bn7 file format . . . . . . . . . . . . . . . .
11.1.3 Limitations . . . . . . . . . . . . . . . . . . . . .
11.1.4 The information and ASCII data files (.in7/.dat)
11.2 Spreadsheet files (.xlsx,.csv) . . . . . . . . . . . . . . .
11.2.1 .xlsx files . . . . . . . . . . . . . . . . . . . . .
11.2.2 .csv files . . . . . . . . . . . . . . . . . . . . . .
11.2.3 Interpreted and uninterpreted .xlsx and .csv files
11.2.4 .xls files . . . . . . . . . . . . . . . . . . . . . .
11.3 Data by observation (.dat) . . . . . . . . . . . . . . . . . .
11.4 Data with load info (.dat) . . . . . . . . . . . . . . . . . .
11.5 Gauss data file (.dht/.dat) . . . . . . . . . . . . . . . . .
11.6 Stata data file (.dta) . . . . . . . . . . . . . . . . . . . . .
11.7 Results file (.out) . . . . . . . . . . . . . . . . . . . . . .
11.8 Batch file (.fl) . . . . . . . . . . . . . . . . . . . . . . . .
11.9 Algebra file (.alg) . . . . . . . . . . . . . . . . . . . . . .
11.10 Ox file (.ox) . . . . . . . . . . . . . . . . . . . . . . . . .
11.11 TSP file (.tsp) . . . . . . . . . . . . . . . . . . . . . . . .
11.12 Matrix file (.mat) . . . . . . . . . . . . . . . . . . . . . . .
11.13 OxMetrics graphics file (.gwg) . . . . . . . . . . . . . . . .
11.14 PDF file (.pdf) . . . . . . . . . . . . . . . . . . . . . . . .
11.15 PostScript file (.eps) . . . . . . . . . . . . . . . . . . . . .
11.16 PostScript file (.ps) . . . . . . . . . . . . . . . . . . . . .
11.17 Enhanced meta file (.emf) . . . . . . . . . . . . . . . . . .
11.18 Windows meta file (.wmf) . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

151
151
151
153
154
154
154
154
157
158
158
159
159
160
160
160
160
160
160
161
161
161
163
163
165
166
166

12 Algebra Language
12.1 Introduction . . . . . . . . . . . . . . . . . . . .
12.2 Executing Algebra code . . . . . . . . . . . . .
12.2.1 Calculator (Alt+c) . . . . . . . . . . . .
12.2.2 Algebra Editor (Alt+a) . . . . . . . . .
12.2.3 Algebra from Results windows (Ctrl+a)
12.2.4 Algebra from a Batch file . . . . . . . .
12.3 Syntax of Algebra language . . . . . . . . . . .
12.3.1 Variables and variable names . . . . . .
12.3.2 Comment . . . . . . . . . . . . . . . .
12.3.3 Constants . . . . . . . . . . . . . . . .
12.3.4 Algebra operators . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

167
167
167
167
168
168
168
168
168
168
169
169

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

CONTENTS
12.3.4.1 Arithmetic operators . . . . . . . . . . . . . .
12.3.4.2 Relational and logical operators . . . . . . . .
12.3.4.3 Algebra operator precedence . . . . . . . . . .
12.3.5 Assignment statements . . . . . . . . . . . . . . . . . .
12.3.6 Conditional assignment statements . . . . . . . . . . . .
12.3.7 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . .
12.3.8 Keywords . . . . . . . . . . . . . . . . . . . . . . . . .
Algebra implementation . . . . . . . . . . . . . . . . . . . . . .
Algebra Functions . . . . . . . . . . . . . . . . . . . . . . . . .
12.5.1 Differencing and lag functions . . . . . . . . . . . . . .
12.5.2 ACF and periodogram functions . . . . . . . . . . . . .
12.5.3 Sorting functions . . . . . . . . . . . . . . . . . . . . .
12.5.4 Smoothing functions . . . . . . . . . . . . . . . . . . .
12.5.4.1 HodrickPrescott filter . . . . . . . . . . . . .
12.5.4.2 Kernel and spline smoothing . . . . . . . . . .
12.5.4.3 Exponentially-weighted moving average and correlation . . . . . . . . . . . . . . . . . . . . .
12.5.4.4 Date and time functions . . . . . . . . . . . .
Algebra function summary . . . . . . . . . . . . . . . . . . . . .

169
169
169
169
170
171
171
172
173
173
173
174
175
175
175

13 Batch Language
13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.2 Executing Batch commands . . . . . . . . . . . . . . . . . . . .
13.2.1 Batch Editor (Alt+b) . . . . . . . . . . . . . . . . . . .
13.2.2 Batch from Results windows (Ctrl+b) . . . . . . . . . .
13.2.3 Batch from the File/Open command . . . . . . . . . . .
13.2.4 Batch from the Windows Explorer . . . . . . . . . . . .
13.2.5 Batch from a Batch file . . . . . . . . . . . . . . . . . .
13.3 Batch files and default folders . . . . . . . . . . . . . . . . . . .
13.4 General Batch command summary . . . . . . . . . . . . . . . . .
13.4.1 Comment . . . . . . . . . . . . . . . . . . . . . . . . .
13.4.2 Command types . . . . . . . . . . . . . . . . . . . . . .
13.4.3 Default arguments . . . . . . . . . . . . . . . . . . . . .
13.5 Batch commands . . . . . . . . . . . . . . . . . . . . . . . . . .
13.5.1 algebra { . . . } . . . . . . . . . . . . . . . . . . . . . .
13.5.2 appenddata("filename", "group"=""); . . . . . . . . .
13.5.3 appresults("filename"); . . . . . . . . . . . . . . . .
13.5.4 break; . . . . . . . . . . . . . . . . . . . . . . . . . .
13.5.5 chdir("path"); . . . . . . . . . . . . . . . . . . . . . .
13.5.6 closedata("databasename"); . . . . . . . . . . . . . .
13.5.7 command("command line"); . . . . . . . . . . . . . . .
13.5.8 database("name", year1, period1, year2, period2, freq);
13.5.9 draw(area, "y", "mode"=""); . . . . . . . . . . . . .
13.5.10 drawf(area, "y", "function", d1=0, d2=0); . . . . . .

180
180
180
180
180
181
181
181
181
181
181
181
182
182
183
183
183
183
183
183
184
184
184
184

12.4
12.5

12.6

176
176
177

xi

CONTENTS

13.6

13.5.11 drawx(area, "y", "x", "mode"=""); . . . . .


13.5.12 drawz(area, "y", "x", "mode"=""); . . . . .
13.5.13 exit; . . . . . . . . . . . . . . . . . . . . . . .
13.5.14 loadalgebra("filename"); . . . . . . . . . . .
13.5.15 loadbatch("filename"); . . . . . . . . . . . . .
13.5.16 loadcommand("filename"); . . . . . . . . . . .
13.5.17 loaddata("filename"); . . . . . . . . . . . . .
13.5.18 loadgraph("filename"); . . . . . . . . . . . . .
13.5.19 module("name"); . . . . . . . . . . . . . . . .
13.5.20 package("packagename", "modeltype"=""); .
13.5.21 print("text"); . . . . . . . . . . . . . . . . . .
13.5.22 println("text"); . . . . . . . . . . . . . . . .
13.5.23 printdate; . . . . . . . . . . . . . . . . . . .
13.5.24 savedata("filename"); . . . . . . . . . . . . .
13.5.25 savedrawwindow("filename", "window"="");
13.5.26 saveresults("filename"); . . . . . . . . . . .
13.5.27 setdraw("option", i1=0, i2=0, i3=0, i4=0, i5=0);
13.5.28 setdrawwindow("name"); . . . . . . . . . . .
13.5.29 show; . . . . . . . . . . . . . . . . . . . . . . .
13.5.30 usedata("databasename", i1=0); . . . . . . . .
Examples . . . . . . . . . . . . . . . . . . . . . . . . . .

14 OxMetrics Graphics
14.1 Graphics paper . . . . . . . . . . . . . . . . . . . . .
14.2 Creating graphs . . . . . . . . . . . . . . . . . . . . .
14.2.1 Actual series with optional transformations .
14.2.2 Multiple series with optional transformations
14.2.3 Scatter plots . . . . . . . . . . . . . . . . . .
14.2.4 Distribution . . . . . . . . . . . . . . . . . .
14.2.5 Time-series: ACF etc. . . . . . . . . . . . . .
14.2.6 QQ plots . . . . . . . . . . . . . . . . . . . .
14.2.7 Two series by a third . . . . . . . . . . . . .
14.2.8 3-dimensional plots . . . . . . . . . . . . . .
14.3 Printing graphs . . . . . . . . . . . . . . . . . . . . .
14.4 Graphics formats . . . . . . . . . . . . . . . . . . . .
14.5 Saving and loading graphs . . . . . . . . . . . . . . .
14.6 Editing graphs . . . . . . . . . . . . . . . . . . . . .
14.6.1 Graph layout . . . . . . . . . . . . . . . . .
14.6.2 Area layout . . . . . . . . . . . . . . . . . .
14.6.3 Variable against time, scatter, or 3D . . . . .
14.6.3.1 Error bars . . . . . . . . . . . . . .
14.6.3.2 Regression, Scale . . . . . . . . . .
14.6.4 Axes . . . . . . . . . . . . . . . . . . . . . .
14.6.4.1 Settings for non-default labelling .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

185
185
185
186
186
186
186
186
186
186
186
186
187
187
187
187
187
188
188
189
189

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

192
192
193
193
194
194
194
195
195
196
196
197
197
198
198
198
199
199
200
200
201
201

xii

CONTENTS

14.7
14.8
14.9

14.6.4.2 Location and transformation


14.6.4.3 Style . . . . . . . . . . . .
14.6.4.4 Label style . . . . . . . . .
14.6.5 Legend style . . . . . . . . . . . . . .
14.6.6 Histogram . . . . . . . . . . . . . . .
14.6.7 Copy properties to other areas . . . .
14.6.8 Text . . . . . . . . . . . . . . . . . .
14.6.9 Lines and symbols . . . . . . . . . .
14.6.10 Adding, moving and deleting objects .
14.6.11 Pointing . . . . . . . . . . . . . . . .
14.6.12 Graphics setup . . . . . . . . . . . .
Copy and paste . . . . . . . . . . . . . . . . .
Graphs and sample selection . . . . . . . . . .
Text formatting . . . . . . . . . . . . . . . . .

15 OxMetrics Data Management


15.1 Creating data . . . . . . . . . . . . . . .
15.2 Database font . . . . . . . . . . . . . . .
15.3 Database description . . . . . . . . . . .
15.4 Printing data . . . . . . . . . . . . . . .
15.5 Data formats . . . . . . . . . . . . . . .
15.6 Summary statistics . . . . . . . . . . . .
15.7 Saving data . . . . . . . . . . . . . . . .
15.8 Navigation and editing . . . . . . . . . .
15.9 Renaming variables . . . . . . . . . . . .
15.10 Deleting variables . . . . . . . . . . . . .
15.11 Reordering variables . . . . . . . . . . .
15.12 Adding variables . . . . . . . . . . . . .
15.13 Extending or reducing the sample period
15.13.1 Changing the sample period . .
15.14 Copy and paste . . . . . . . . . . . . . .
15.15 Appending data . . . . . . . . . . . . . .
15.16 Daily, weekly and timed data . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

201
202
202
202
203
203
203
203
203
203
204
204
204
204

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

207
207
207
207
207
208
208
208
208
209
209
209
209
209
210
210
210
210

References

213

Author Index

215

Subject Index

217

Figures

2.1
2.2

Time plot of CONS and INC . . . . . . . . . . . . . . . . . . . .


Multiple graphs . . . . . . . . . . . . . . . . . . . . . . . . . . .

18
20

3.1
3.2

Time plot of CONS and INC . . . . . . . . . . . . . . . . . . . .


Multiple graphs . . . . . . . . . . . . . . . . . . . . . . . . . . .

35
37

4.1
4.2

Time plot of CONS and INC . . . . . . . . . . . . . . . . . . . .


Multiple graphs . . . . . . . . . . . . . . . . . . . . . . . . . . .

53
55

5.1
5.2

Dow Jones returns, ACF of returns, ACF of squared returns . . .


GARCH(1,1) model for Dow Jones returns . . . . . . . . . . . .

66
72

6.1
6.2
6.3

82
83

6.4
6.5
6.6
6.7
6.8
6.9
6.10
6.11
6.12
6.13
6.14
6.15

Descriptive graphics of CONS and DCONS . . . . . . . . . . . .


Time-series plot of CONS and INC with recession shading . . .
Time-series plot of INFLAT and OUTPUT: maximizing visual correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Sophisticated scatter plotting graphs . . . . . . . . . . . . . . . .
Further descriptive graphics of CONS and DCONS . . . . . . . .
Box plot of INFLAT . . . . . . . . . . . . . . . . . . . . . . . .
Comparison of correlogram and ACF for CONS and DCONS . .
Cross-correlogram of CONS and DCONS . . . . . . . . . . . . .
Frequency domain graphics of CONS and DCONS . . . . . . . .
Densities and distributions of normal and t . . . . . . . . . . . .
QQ plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Cross plotting consumption against income by seasons (DHSY) .
Bubble chart and error bars . . . . . . . . . . . . . . . . . . . . .
3-dimensional graphs: bivariate normal and saddles . . . . . . . .
3-dimensional graphs from tabular data . . . . . . . . . . . . . .

7.1
7.2
7.3
7.4

Descriptive graphics of CONS, INC, DCONS and DINC


Edited and amended descriptive graph . . . . . . . . . .
Drawing on an INFLAT/OUTPUT scatter plot . . . . . .
CONS and OUTPUT with matching mean and range . .
xiii

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

84
86
88
89
90
91
91
92
93
95
95
97
99
101
106
109
111

xiv

LIST OF FIGURES
8.1

Check of Cons and Inflat . . . . . . . . . . . . . . . . . . . . . .

117

9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8

Some important densities . . . . . . . . . . . . . . .


Cumulative distribution functions from 600 points .
Cumulative distribution functions . . . . . . . . . .
Check on CDFs . . . . . . . . . . . . . . . . . . . .
Time series graphs of 6 processes . . . . . . . . . .
Correlograms and spectral densities of six processes
AR(1) with various parameter values . . . . . . . . .
Splines with various bandwidth settings . . . . . . .

.
.
.
.
.
.
.
.

132
133
134
134
135
136
137
138

11.1

A simple graph . . . . . . . . . . . . . . . . . . . . . . . . . . .

162

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

Tables

8.1

OxMetrics data input/output options . . . . . . . . . . . . . . . .

113

11.1

data.in7: information file of artificial data set . . . . . . . . . .

151

12.1
12.2
12.3

Algebra operator precedence . . . . . . . . . . . . . . . . . . . .


Reserved Algebra keywords . . . . . . . . . . . . . . . . . . . .
Algebra functions . . . . . . . . . . . . . . . . . . . . . . . . . .

170
172
178

13.1

Batch command summary . . . . . . . . . . . . . . . . . . . . .

182

14.1
14.2
14.3
14.4
14.5
14.6
14.7
14.8

Greek symbols . . . . . . . . .
Arrows . . . . . . . . . . . . .
Mathematics accents . . . . . .
Foreign and accented characters
Mathematical symbols . . . . .
Log-like symbols . . . . . . . .
Miscellaneous symbols . . . . .
Fonts and sizes . . . . . . . . .

205
205
205
205
206
206
206
206

xv

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

Preface
The OxMetrics front-end binds all the components of the OxMetrics system together.
Versions 7 and 6 follows on from version 5. Version 5 in turn was a thorough rewrite of
its predecessor, GiveWin 2. wxWidgets is used for the interface implementation from
version 4 onwards. This makes it possible for all the interactive software to be available
on Linux and Mac OS-X, as well as Windows. OxMetrics also uses Unicode, thus
supporting most languages. As a consequence Windows NT, 9x and ME are no longer
supported.
OxMetrics builds on many of GiveWins achievements, such as the complete separation of the front-end (for data manipulation and visualization) and the econometric
and statistical modules. However the current version presents a better integrated system
to the user, while maintaining the benefits of being able to develop the many components separately.
Ox, an object-oriented matrix programming language, is one of the modules which
can interface with the OxMetrics front-end. Indeed, almost all modules (such as PcGive) now do their computations in Ox, rather than in lower level C or C++. In many
cases, OxMetrics now also offers to generate Ox code, as a more flexible alternative to
Batch code.
Although OxMetrics 6 represents a new generation, it builds on earlier versions of
GiveWin and PcGive, and we wish to reiterate our thanks to all those who have helped
in its development.

We wish you enjoyable and productive use of

OxMetrics

xvii

Getting Started with OxMetrics

Chapter 1
Introduction and Overview
The OxMetricstm system presents an interactive menu-driven graphics-oriented system for econometric, statistic, and financial analysis. Here we describe the core OxMetrics program, which acts as the front-end to a series of integrated software modules. These modules obtain their data from OxMetrics and return output and graphics
to it. OxMetrics is the component that allows you to load, edit, and save data; transform
that data using the calculator or algebra; create a wide variety of graphs, which can be
edited, amended and saved in various formats; provide the data for other modules to
analyze; receive their text output, results, and graphics; and lets you edit, amend, and
save any or all of these as desired. As such, the OxMetrics front-end can be seen as the
desktop for econometric and statistical modelling.
OxMetrics databases can have a fixed frequency, or dated, which allows for daily
or timed data. Aggregation facilities are provided, e.g. to convert daily data into
monthly. OxMetrics is multilingual, in that names of database variables and text in
reports and graphics can be from a wide range of languages, including Chinese and
Japanese.
This introductory chapter notes the OxMetrics languages (Algebra and Batch), describes the Help system, notes the data storage format and how results (both text and
graphics) are saved, including a brief explanation of the various filenames and extensions used. Finally it explains the conventions of the documentation. The Ox language
is treated in separate books.

1.1

Supported platforms

The OxMetrics suite of programs runs on the following platforms:


Windows
Installation is to \Program Files\OxMetrics7\ by default, but this can be
changed in the installation program.
OS X
Installation is to /Applications/OxMetrics7/.
3

Chapter 1 Introduction and Overview

Linux
Installation is to /usr/share/OxMetrics7/.
A separate installation document describes the supported platforms in more detail,
and shows how to install the software.
OxMetrics 7 operates independently from version 6.
1.1.1

Folder structure

The OxMetrics folder structure is as follows:


OxMetrics7/
algebra/
Algebra files
bin/
binary and related files (32-bit)
bin64/
binary and related files (64-bit)
batch/
Batch files
data/
Data files
doc/
Help system
ox/
Root of Ox installation
bin/
binary files for Ox (32-bit)
bin64/
binary files for Ox (64-bit)
doc/
help files for Ox
include/
Ox header files for Ox code
packages/
Ox packages
samples/
Ox sample code
...
OxEdit/

1.2

What is new?

This documentation refers to OxMetrics 7. OxMetrics 6 users will find much that is
familar. There are a number of small fixes in this version, which are documented on the
online help.
The most important new features in OxMetrics 6 are:
Output handling is faster under Linux, and very much faster under OS X.
Normal QQ plots can now include pointwise asymptotic 95% standard error bands,
as derived in Engler and Nielsen (2009). See Figure 6.11 for an example.
A variable can be used to add Shading to a graph: shading is switched on when the
variable has value 1. This allows for recession shading, and is used in particular for
the output from regime-switching models. See Figure 6.2 for an example.
Legends can be transparent or not. Transparent legends are not transparent to shading or separate symbols. Opaque legends are drawn on top of everything else.
Added context menu (graph, sort, ...) when right-clicking on the variable name in a
database.

1.3 Availability

1.3

Availability

For availability contact Timberlake Consultants: www.timberlake-consultancy.com or


www.timberlake.co.uk.
Consult www.doornik.com or www.oxmetrics.net for pointers to additional information relevant to the current and future versions of OxMetrics. A demonstration version is also available from these web sites.
For TSP go to www.tspintl.com.
The Help/Support menu lists some contact addresses for OxMetrics, as well as web
sources of information.

1.4

Citation

To facilitate replication and validation of empirical findings, the module used to generate the results should be cited in all reports and publications involving its application.

1.5

Help

OxMetrics incorporates an extensive cross-referenced help system which offers advice


about crucial decisions and can be accessed at any time. This is based on HTML files,
and requires that a browser such as Chrome, Firefox or Internet Explorer is installed.
OxMetrics help is available from the Help menu or the Help pane in the workspace.
The Help pane lists the contents of all the modules that have been installed within
OxMetrics. Double clicking on an entry will start your default browser with the Help
contents.
Context-dependent help, where available, can be obtained either by pressing the F1
key, or from the Help menu. For example, when writing an Ox program, put the caret
on println, and press F1. OxMetrics will search the html index files for a reference to
that word. If there is only one, it will jump there immediately. Otherwise it will offer a
list of choices in a dialog.

1.6

Modular structure

OxMetrics maintains the modular structure that was introduced in previous generations
of the software. An increasing number of modules interacts with OxMetrics. In that
case, the OxMetrics front-end is the server, while the modules (TSP, STAMP, etc.)
are the clients. The communication is implemented via DDE.
While it is possible to write clients that interface directly with the server (such as
TSP, OxPack, and OxRun), it is much easier to develop Ox packages which do this. This
requires the use of the Modelbase class, which provides the necessary functionality.
Examples of this are PcGets, PcGive, G@rch, etc.

Chapter 1 Introduction and Overview

Ox is a powerful object-oriented matrix programming language with an extensive


statistical library. Ox allows you to write your own programs using high level matrix operations, and provides easy facilities to read the same data files as OxMetrics
can load. When the preprogrammed options in other modules do not provide a required estimator or test, and you have some basic programming skills, Ox could be
used instead. Ox also has preprogrammed classes (a class is a term in object-oriented
programming) to facilitate writing Monte Carlo experiments. Ox tends to be faster
than other popular matrix languages. Please consult the separate Ox documentation
for further information. The OxRun dialog application allows running Ox programs
with OxMetrics as the destination of text and graphical output. An interesting example
which shows densities and QQ plots while a Monte Carlo experiment is in progress
is provided in \ox\samples\simula\simnor.ox. The OxPack module provides an
interactive front-end to several Ox packages.

1.7

Registration

A licensing code is required for the software to work properly. This code will have been
supplied with your copy, and, under normal circumstances, the licence that is entered
during installation is automatically used by the software.
Additional licences can be entered under the Help/Registration menu option (a dialog will automatically appear when OxMetrics is not registered). In the subsequent
dialog you can enter your code as well as your name and affiliation. Help/Registration
can be also used to check the available licences for using client modules.

1.8

Upgrades

Minor upgrades can be downloaded from www.doornik.com/products.html.

1.9

Algebra

The Algebra language enables you to transform database variables by writing mathematical formulae. Algebra code can be written interactively in the Calculator, or directly in the Algebra editor. Such algebra code can be saved, reloaded, and edited.
The Calculator writes its operations as algebra code to the Results window, from
where it can be cut and pasted into the algebra editor. Algebra can also be run directly
from the results window, by highlighting the block of algebra code, and then pressing
Ctrl+A.
Algebra is a simple vector language, operating on the variables in the database. The
operation is applied to each observation in turn, although it is possible to limit access to
a subsample. The syntax is described in Chapter 12.

1.10 Batch

1.10

Batch

OxMetrics is a menu-driven program for ease of use, but some operations can be implemented by entering commands. These commands are parts of simple computer
language which allow some control of OxMetrics through Batch operations. A Batch
program may contain sections of Algebra code.
Batch files allow you to load data, append results, implement algebra and save current PcGive (or STAMP etc.) models. Later, these can be run from the Model/Batch
menu or by clicking on the OxMetrics icon on the toolbar. Thus, when a complicated
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. Like Algebra, batch code can be run directly by highlighting the block of text, and
then pressing Ctrl+B.
Once saved to disk, a batch file can also be run directly using File/Open, or even
by double clicking on the batch file in the Windows Explorer. Batch files have the
.fl extension, which originally stood for Fiml Language. The syntax is described in
Chapter 13.

1.11

Data storage

The primary mode of data storage is a pair of files with extensions .in7 and .bn7. The
latter is a binary file containing the actual data, whereas the former 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. One artificial data set is supplied in the OxMetrics7\data folder, in
the files called data.in7 and data.bn7. The tutorials use this data set. If you want to
load your own data, you must begin by inputting the observations; however, follow the
relevant tutorial first.
OxMetrics checks for potential overwriting of files and if such is likely to occur,
allows selecting another file name. The data options facilitate easy archiving of data.
Please be careful not to overwrite precious data sets. It is always wise to make regular
backups of important files: hard disks may break down, accidental deletion occur or
viruses could strike.
OxMetrics can read and write human-readable files and Excel spreadsheet files.
OxMetrics can also read comma-separated, GAUSS and Stata files. See Chapter 11 for
detailed lists on the file formats supported by OxMetrics.

1.12

Filenames and extensions

All file names have automatic default extensions which need not be input: a detailed
discussion is provided in Chapter 11. Say the basic data set is called m1ukq, then the
information file might be m1ukq.in7, the associated binary file (of actual data) will

Chapter 1 Introduction and Overview

be m1ukq.bn7, the OxMetrics Results window storage file could be m1ukq.out, the
algebra storage file m1ukq.alg, and batch files m1ukq.fl. A human-readable base
data file generally uses the .dat extension. Graph files allow saving in encapsulated
PostScript (.eps), PDF (.pdf), PostScript (.ps), Windows metafiles (.wmf), enhanced
metafiles (.emf), and OxMetrics graphics (.gwg, for GiveWin graphics), of which the
last can be re-read by OxMetrics for further editing.
Note that by default Windows does not show the file extension in the Explorer window only the icon shows what the file type is. If you wish, you can switch the display
of file extensions on in the Folder Options entry in the Explorer.

1.13

Output storage

All text output are shown in the Results window as calculations proceed but are not
stored on disk or diskette unless specifically requested. On long runs, a large amount
of information can be generated. This can be edited to eliminate redundant records: the
Edit menu allows copying, cutting and pasting, deleting, finding and replacing.
The storage facility allows rapid interactive modelling to proceed while any useful
results can be printed as a batch job when the computer is otherwise idle.
Since much of the output is graphical, graphs can be easily edited. Graphs can be
saved in a variety of formats as noted in the next section.

1.14

Sample periods

For data samples, reference is by the absolute date in the form Year(Period) to
Year(Period), for example: 1965(1) to 1985(3). Whenever a sample choice has to be
made, OxMetrics will show the maximum available and will not allow choices outside
that range.
When the data is dated, for example consisting of daily data, the choice is made
by entering dates in ISO format of yyyy-mm-dd. The year is always four digits, the
month one or two digits (1=January) and the date also one or two digits. For example:
1965-1-31 to 1985-9-5.
Time is written as hh:mm:ss.uuu where hour is two digits on the 24-hour clock
(so 22:00 is 10 PM), mm is minutes, the seconds and hundreds are optional. When
combined with a date, the ISO standard uses a T to glue the parts together: 1980-11T12:05:05.

1.15

Status bar

The status bar is displayed at the bottom of the OxMetrics window and consists of four
areas:
1. The left area of the status bar describes actions of menu items as you use the arrow
keys to navigate through menus. This area similarly shows messages that describe

1.16 Tool bars

the actions of toolbar buttons as you depress them, before releasing them. If after
viewing the description of the toolbar button command you wish not to execute the
command, then release the mouse button while the pointer is off the toolbar button.
2. If a tool is running, this is indicated on a yellow background in the second panel.
3. The third panel shows the location of the current document. The content is different
for text, data and graphics.
For text it is the position in the document of the caret.
For example: L 113 C 14 indicates that the caret is at Line 113, Column 14. In
binary/hexadecimal viewing mode this shows the position of the caret in decimal
(the first character of the document is at byte 0). This field will also indicate if
the document is read-only, or when the editor is in overwrite mode.
For data it is the position in the database of the caret. If there is an active
selection, it shows the selected variables.
For graphics it is the X coordinate of the mouse cursor.
4. The right area of the status bar also depends on the document type:
For text it indicates the document encoding properties:
End-of-line marker
One of: Win, Lnx, Mac for Windows (\r\n), Linux (\n) or Mac (\r).
Multilingual file format
If the file format is different from the default (ASCII) encoding, this is indicated by one of UTF8, UTF16, or UTF32. The can be followed by BE or
LE to indicated big-endian or little-endian encoding.
These properties can be changed using Edit/Text properties.
For data it is the value of the observation which has the caret. If there is an
active selection, it shows the selected sample.
For graphics it is the Y coordinate of the mouse cursor.

1.16

Tool bars

Three tool bars are displayed across the top of OxMetrics, below the menu bar. The tool
bars can be customized from a right click on the bar. Customization allows adding or
removing icons, and choosing small medium or large icon size (medium is the default).
The Find/Replace tool bar, by default on the second row, replicates most commands
of the Find/Replace dialog. The two are actively linked, and the Find/Replace bar is
often a convenient way to quickly search for text or execute search/replace actions. The
default layout consists of:
Find text Specify the text to search for. The drop down list box holds previously used
search texts. You can use a context menu (right click) to insert text from the clipboard.
Find down Finds the next occurrence of the search text downwards from the current
location of the caret.
Find up Finds the next occurrence of the search text upwards from the current location
of the caret.

10

Chapter 1 Introduction and Overview

Case sensitive Toggle case sensitive searching on or off (if the button is down, the
search is case sensitive).
Whole word Toggle word matching on or off (if the button is down, the search will only
find whole words).
Goto next instance Finds the next instance of the currently selected text downwards
from the current location. The selected text will become the default for subsequent
searches.
Goto previous instance Finds the previous instance of the currently selected text upwards from the current location. The selected text will become the default for subsequent searches.
Show Find dialog Open the Find dialog.
Show Replace dialog Open the Find/Replace dialog.
Find in Files Open a dialog that allows searching for text strings in disk files.

1.17

Documentation conventions

The convention for instructions that you should type is that they are shown in
Typewriter font. Capitals and lower case are only distinguished as the names of
variables in the program and the mathematical formulae you type. Once OxMetrics
has started, then from the keyboard, the Alt key accesses line menus (at the top of the
screen); from a mouse, click on the item to be selected using the left button. Common
commands have a shortcut on the toolbar, the purpose of which can be ascertained by
placing the mouse on the relevant icon. Icons that can currently operate are highlighted.
Commands on menus, toolbar buttons, and dialog items (buttons, checkboxes etc.) are
shown in the text in a Sans Serif font.
We assume that you have the basic skills to operate programs under the Windows
operating system. Generally, we assume a mouse is used for operations: substitute
Alt+key otherwise.
Equations are numbered as (chapter.number); for example, (8.1) refers to equation
8.1, which is the first equation in Chapter 8. References to sections have the form
chapter.section, for example, 8.1 is Section 8.1 in Chapter 8. Tables and Figures are
shown as Figure chapter.number such as Figure 5.2 for the second figure in Chapter 5.
Multiple graphs are numbered from left to right and top to bottom, so b is the top-right
graph of four, and c the bottom left.

Chapter 2
Getting Started: Windows

This chapter discusses some of the basic skills required to get started with OxMetrics on Windowstm . Since OxMetrics provides the data which other modules analyze,
and receives all the text output and graphics which you create in (say) PcGive, you
should begin by briefly learning how OxMetrics works.
Once OxMetrics has started, you will be able to load data, create graphs, and transform data using the OxMetrics calculator or algebra. Then, use the Model command
on the Model menu to start econometric modelling using, for example, PcGive. When
you exit OxMetrics it will automatically close all active modules which depend on it.
In some of the coming tutorials we shall be using OxMetrics as a stand-alone program.
There are many interesting things to be done even without using additional modules!
11

12

2.1

Chapter 2 Getting Started: Windows

Starting OxMetrics

Start OxMetrics from the OxMetrics group on the Windows Start menu, or from a
desktop icon. If this is the first time you use the new OxMetrics, you may wish to reset
the size of the various windows. Catch the edge of the relevant window with the mouse
pointer which should change form to a double arrow, and expand or contract as desired.
Your initial screen could look like the capture shown on the previous page (we could
only fit part of OxMetrics on the page).
Clicking on a menu item (e.g., File, Edit etc.) drops down the menu as shown on
page 13 for File. Then moving the arrow keys drops down each menu in turn. For
example, clicking on Window shows the open windows, and clicking on the desired
choice makes it the focus; if part of that window shows on screen, directly clicking on
it with the mouse also works.

2.2

Registering OxMetrics

If you install OxMetrics normally, it will already be registered, and you can start
working immediately. An unregistered version will show the registration dialog on
screen, as displayed above.
Enter the licensing code and your name in the respective fields (you must enter the
code provided by your distributor).
An OxMetrics Enterprise licensing code enables most modules. Otherwise, many
modules have their own additional licence code, which can be entered in the dialog.
Once OxMetrics has the first registration code, the above dialog will not appear automatically anymore. To enter additional codes, activate the Help/Registration menu.

2.3 Loading and viewing the tutorial data set

13

We trust that you use a legal copy of OxMetrics and client modules. That will allow
us to keep developing the programs.

2.3

Loading and viewing the tutorial data set

Without data, there is not much that can be done, so the first step is to load data. Many
tutorials use a data set called data.in7.
We shall load this tutorial data set here. Access the File menu in OxMetrics, and
choose Open:

If you installed in the default directory structure, the data will be in the directory
\Program Files\OxMetrics7\data, so locate that directory and select the Data file:

By default, all files are displayed, but you can refine the files listed from the Files of

14

Chapter 2 Getting Started: Windows

type drop-down box:

The data file contions artificial data on consumption, income, inflation and output,
denoted by CONS, INC, INFLAT, and OUTPUT respectively. The in7 extension indicates a OxMetrics data file (a format which has remained the same for versions 7 and 8
of PcGive, then GiveWin, and is now used for OxMetrics, with some minor extensions
in the file format). The in7 file is a human-readable file, describing the data (variable
names, frequency, sample period, documentation etc.). There is a companion bn7 file,
which holds the actual numbers (in binary format, so this file cannot be edited directly).
OxMetrics can handle a wide range of data files, among them Excel files. You can also
cut and paste data series directly from a spreadsheet (but not formulae).
Tip By default, Windows does not show extensions of registered file types. Those registered
by OxMetrics extensions are displayed, however, to facilitate discrimination between the different types. If you wish to see the all your registered extension, start the Windows Explorer.
Deselect the option labelled: Hide extensions for known file types, which is listed under
Model/Folder Options/View.
It is also possible to do this for individual files only: in Folder Options/File Types locate the
relevant extension. Then click on Advanced and mark Always show extension.

The data file will be loaded, and become the currently active database for plotting and
transformations. More than one database can be loaded, and the name of the currently
active database is shown in the the toolbar:

If more than one database is open, this toolbar box can be used to switch active database:

A notification of the loaded file is written to the Results window, so the loaded database
does not acquire the focus. To see the database, click on it in the workspace. Although
data values are stored internally with about 15 to 16 digit accuracy (8 byte floating point
values), the data are displayed with 6 digits only in the spreadsheet:

2.3 Loading and viewing the tutorial data set

15

On the bottom right of the OxMetrics window, in the status bar, the observation
under the cursor is shown with full accuracy:

Double clicking on the variable name shows the name and documentation of the
variable, both of which can be changed. For the CONS variable:

The data can be manipulated, much like in a spreadsheet program. Pressing the left
mouse button, and keeping it depressed, then dragging the mouse highlights a block of
data which can be copied to the clipboard for insertion in another part of the database
(click on the two-pages icon for copy, or the Ctrl+C key; paste is the clipboard icon or
the Ctrl+V key).

16

Chapter 2 Getting Started: Windows

Right-clicking on the variable name brings up a context menu related to that variable, e.g. to quickly graph it. Here it is shown for INC:

Double clicking on an observation brings up a revision box, where corrected values


can be entered (or missing values set to an observed outcome):

While two separate clicks will bring up the inline editor:

2.4

OxMetrics graphics

The graphics facilities of OxMetrics are powerful yet easy to use. This section will show
you how to make time plots and scatter plots of variables in the database. OxMetrics
offers automatic selections of scaling etc., but you will be able to edit these graphs, and
change the default layout such as line colours and line types. Graphs can also be saved
in a variety of formats for later use in a word processor, or for reloading into OxMetrics.
2.4.1

A first graph

Graphics is the first entry on the Model menu. Alternatively, click on the graphics icon
on the toolbar:

2.4 OxMetrics graphics

17

Either way brings up the following dialog box. This is an example of a dialog with
a multiple selection list control. In such a list, you mark as many items as you want.
Here we mark all the variables we wish to graph. With the keyboard, you can only mark
a single variable (by using the arrow up and down keys), or range of variables (hold the
shift key down while using the arrow up or down keys).
With the mouse there is more flexibility:
single click to select one variable;
hold the Ctrl key down and click to select additional variables;
hold the Shift key down and click to extend the selection range.

Here we select CONS and INC and then press the << button. This moves the
variables from the database list to the selection list, activating the buttons at the bottom:

Press Actual series. Now the graph appears, which looks very much like Figure 2.1.
The only difference is the position of the legend. You can pick that up with the mouse,

18

Chapter 2 Getting Started: Windows

and move it to another position in the graph as desired.


910

CONS

INC

900

890

880

870

860

1955

1960

1965

Figure 2.1

1970

1975

1980

1985

1990

Time plot of CONS and INC

Most graphs in this book are boxed in. You can change the default, for the current
graph only, by double clicking on the graph (or selecting Edit/Edit Graph), then clicking
on Graph layout in the left-hand column, and activating Box all areas, as shown here:

2.4 OxMetrics graphics

19

Alternatively, choose Graphics from the Model/Preferences menu, and activate Box
all areas:

This will change the default for all future graphs that are made with OxMetrics.
Note that, when the graph is active, and the mouse is moved over the graph, the
status bar at the foot of the OxMetrics window displays the graph coordinates. Inside a
graph these are the real-world coordinates (X,Y), the actual data values. Outside these
are pixel coordinates (pX,pY): a graphics window in OxMetrics runs from (0,0) in the
bottom left, to (15000,10000) in the top right (further explanation is in Chapter 14).

2.4.2

Multiple graphs

One of the powerful features of OxMetrics is the ability to draw multiple graphs simultaneously on-screen within one graphics window (and you are not restricted to just one
graphics window). We shall now get two graphs on screen, with the second a cross-plot
of CONS and INC. Click on the Graphics toolbar button, note that CONS and INC are
still selected (you can also variables to the opposing listbox by double clicking on them,
or empty the selection by pressing Clear). The first variable in the selected list, CONS
here, will be the Y variable (if CONS is not on top you can select it, and press the Move
up button). Click on Scatter plot (YX) to create the plot.
If you accidentally did it wrong, click in the new sub plot (or plot area, as we tend
to call it), selecting the entire second area, then press delete to remove it again.
A useful aspect of OxMetrics is that graphs can be edited and features added while
they are on screen, and after adding other graphs if desired. Double click on the scatter
plot graph, select Regression in the Edit Graphics dialog, and add one regression line
as shown:

20

Chapter 2 Getting Started: Windows

CONS

INC

900

880

860
1955
900

1960

1965

1970

1975

1980

1985

1990

CONS INC

890
880
870
860
870

875

880

885

Figure 2.2

890

895

900

905

910

Multiple graphs

The final result is in Figure 2.2. The editing possibilities are manifold: Chapter 7
provides a detailed discussion, but you can always play around with graphs at your
leisure.
Finally, you can undo and redo the changes that were made. In this case, Undo

2.4 OxMetrics graphics

21

will remove the graphics line again. Graph saving clears the undo/redo buffer, to avoid
excessive memory use.

2.4.3

Graph saving and printing

To print a graph directly to the printer when the graphics window has the focus, click on
the printer icon in the toolbar. You can preview the result first using the Print Preview
command from the File menu. If you have a PostScript printer, you can save the graph
to disk as PostScript, and then print it from the command line.
Graphs can be saved to disk in various formats:
Enhanced metafile (.emf); These can easily be inserted into Microsoft Word or
newer using Insert/Picture/From File.
Encapsulated PostScript (.eps), which is the format used to produce all the graphs
in this book;
OxMetrics Graphics File (.gwg);
PostScript (.ps), this is like EPS, but defaulting to a full page print.
Portable Network Graphics (.png), which is a bitmap format that may be useful for
insertion in web pages;
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.

2.4.4

Using the clipboard for graph pasting

There is an important distinction between copying graphs for use in internal OxMetrics
graphs, or for external use.
To paste the graph into Word, for example, you can use Edit/Copy Metafile to
Clipboard, and then paste it into Word. A metafile stores the actual Windows commands
that were used to draw the graph, and thus scales well. The alternative is to copy the
bitmap to the clipboard.1
The standard copy command is used for internal paste. If no area is selected, the
whole graph is copied, otherwise the selected area only.
Try this by clicking on the second area in the current graph. Once selected (shown
by a hatched boundary) copy the area to the clipboard. Then first deselect the area by
clicking somewhere in the margin of the graph. A subsequent paste will add a copy as
the third area. Next, select the first area and paste again: this inserts the cross-plot into
the time-series plot (not a useful graph).
1

We use LATEX for our typesetting system, and save all graphs as .eps files.

22

2.5

Chapter 2 Getting Started: Windows

Calculator

Two options are available for transforming data: by algebra or by a dialog approach,
which mimics the operation of a pocket calculator. We begin with the latter, as it is the
simplest.
Please note that OxMetrics and client modules are sensitive to the case of the variable names so that cons, Cons, and CONS are treated as different variables. This
can be useful for distinguishing real (lower case) from nominal (capitals) variables, or
logs from levels, etc.
In several cases OxMetrics will offer a default name for a newly created variable:
prefixes of D for differences, e.g. DCONS;
prefixes of L for logarithms, e.g. LCONS;
suffix n for n-period lags, e.g. CONS 1.
So can you guess what DLCONS 1 is likely to be?
The aim is to build up an algebraic expression for the transformation (which is valid
Algebra code: see 2.6). Press on the Calculator button leading to the capture shown
below (or via the Model menu and Calculator choice).

The first transformation is to take the first difference of CONS. Click on the CONS
variable just to highlight it (dont double click), and then on the diff button, accept a lag
length of one, to see in the top part of the dialog:

Click on the large button with the = sign, and accept the default name of DCONS,
which will be created in the database, and added to the list of variables. A two-period
difference is just as easy to compute: select CONS, press the diff button and change the
length of the differencing period.

2.5 Calculator

23

Another transformation to try: INCCONS. Double click on INC, click on the


minus button, and then double click on CONS. The expression now reads INCCONS,
press on = to evaluate. Name the variable SAVING (you could use a name like INC
CONS, but must enclose such a name in double quotes when using it in expressions).
Finally, we create a step dummy (or indicator variable), where the step lasts from
1979(2) to 1980(4). We need zeros outside that period, ones inside. Click on the dummy
button, and enter:

Click on OK, and then on = to create the dummy. Give it an informative name, such as
s792t804.
Tip We deliberately gave no examples involving lags. For estimation in modules such
as TSP or PcGive, lags are best created at the model formulation stage, where the
programs will keep track of their presence for dynamic analysis.
Three additional operations can be performed on variables inside the listbox in the
Calculator:
Delete a variable: select and press the button labelled Del, or the Delete key; you
will have to confirm the deletion as the variable is eliminated from the database.
Move variables: use the < or > button to move (groups of) variables up or down.
This changes the order in the database.
Rename a variable: select and press the Ren button; you will be prompted for a new
name.
All changes to the database can be undone from the Edit menu.
Exit the calculator (Esc or click on the x button), and graph some of the variables
to check whether the transformations are correct. All transformations are logged to the
Results window:
Algebra code for data.in7:
DCONS = diff(CONS,1);
SAVING = INC-CONS;
s792t804 = dummy(1979,2, 1980,4);

This leads us to the next topic.

24

2.6

Chapter 2 Getting Started: Windows

Algebra

Algebra enables us to do transformations by typing the expressions directly into an


editor. It also allows saving and loading from disk of a whole chunk of statements.
As an example, we rerun the transformations of the previous section. To verify if
that will work, activate the database, and press Undo until the database is back in its
original state. Now set focus to the Results window. Locate the logged Algebra code in
the Results window. There are two ways to quickly run this code:
select the block of Algebra code, and type Ctrl+A to execute it;
using the Algebra editor.
Because the former is straightforward, we now discuss the latter method.
Highlight the three algebra lines, and copy them to the clipboard (Ctrl+C). From
the Model menu, select Algebra, and paste the code (Ctrl+V) to see:

Now press Run. The variables have been recreated. We can inspect the database to see
what happened. The algebra code is again logged to the Results window.
Tip The bottom part of the Algebra editor is there to save typing. For example, to
insert the code LCONS=log(CONS);, select CONS in the Database box of the Algebra editor. Next, selext log(VAR) under Functions, and click on Write Algebra
Code.
Tip As in the Calculater, database variables can be deleted, moved and renamed.
The only variable names allowed in Algebra are those that would be valid names in
computer languages like Ox or C: the first character must be a letter or an underscore,

2.7 The workspace

25

the rest a letter, underscore or digit. Names which do not follow this convention must
be enclosed in double quotes.
Algebra uses database variables as follows: if a left-hand variable is already in the
database it will be overwritten, otherwise it will be created. Variables on the right must
exist, possibly because of preceding lines of algebra code. Algebra is case-sensitive,
meaning that LCONS, LCons and lcons refer to three different variables.
As a more advanced example, we explain how it is possible to create the same
dummy using the insample function and a conditional assignment. The insample
function has four arguments: startyear, startperiod, endyear, endperiod. It returns 1 (or
TRUE: everything which is not 0 is TRUE) if the observation under consideration falls
within the sample, otherwise it returns 0 (FALSE). The conditional assignment works
as follows: the conditional statement (the if part) is followed by a question mark and
the then part, which is followed by a colon and the else part. Read:
i1980p1 = insample(1980, 1, 1980, 1) ? 1 : 0;
as: i1980p1 takes on the value 1 for the observations which are in the specified sample,
and the value 0 for the other observations. In this case, the same result can be obtained
by writing:
i1980p1 = insample(1980, 1, 1980, 1);.
An error message pops up if you make a mistake. The error can be corrected on
returning to the algebra editor. The text at the top of the Algebra error shows the text of
the last error (if one occurred).
Tip A sensible strategy is to store algebra code and basic data only, and recompute
transforms during each run: this economizes on storage and facilitates updating
analyses when data are revised or corrected.
Tip If you load a database, text file, or graph from disk, and make a change to it, this
is shown by a star before the name. When the document is saved, the star disappears
again.
Do not save the modified data set. Either undo the changes, or quit the data set, and
reload the original data.in7/data.bn7. Algebra is documented in Chapter 12.
This completes the getting-started chapter. Before giving some examples on modelling with OxMetrics, we briefly discuss the workspace window. The remainder of the
tutorial are more detailed examples on graph editing, graphics, data loading and saving,
and data transformations.

2.7

The workspace

Often, after working in OxMetrics for a while, there are many open windows, with
graphs, data and results. The workspace helps navigating between these, by showing
which documents are open in OxMetrics, as shown in the example on the next page.
Here there is one data file open, data.in7, which has been modified (as indicated
by the * in front of the name). There is one save graph (also modified), and the default
Data Plot window. In addition, there is simnor.ox (bold, so the active document) under Code, and the finally the Results window. The available modules are listed under

26

Chapter 2 Getting Started: Windows

Modules (with all interactive modelling packages such as PcGive, STAMP, etc. now
grouped under the Model header).
The Help pane is also shown, here with the Ox help index. Double-clicking on acf()
would open the Ox documentation at the acf function.

Right clicking on the document category (Data, Graphics, Code, or Text) gives a
context menu. For Data it is:

while right clicking on the document name gives:

2.7 The workspace

27

Chapter 5, which is the next in line, introduces the OxMetrics modules. This includes an example on estimating a GARCH(1,1) model using PcGive. Because OxMetrics behaves very similarly on Windows, OS X and Linux, we shall not explicitly
distinguish anymore in the remainder.

Chapter 3
Getting Started: OS X

This chapter discusses some of the basic skills required to get started with OxMetrics on OS Xtm , the operating system for Apple Macs. Since OxMetrics provides the
data which other modules analyze, and receives all the text output and graphics which
you create in (say) PcGive, you should begin by briefly learning how OxMetrics works.
Once OxMetrics has started, you will be able to load data, create graphs, and transform data using the OxMetrics calculator or algebra. Then, use the Model command
on the Model menu to start econometric modelling using, for example, PcGive. When
28

3.1 Starting OxMetrics

29

you exit OxMetrics it will automatically close all active modules which depend on it.
In some of the coming tutorials we shall be using OxMetrics as a stand-alone program.
There are many interesting things to be done even without using additional modules!

3.1

Starting OxMetrics

OxMetrics is installed in the Applications folder, to a subfolder called OxMetrics7


for version 7 of OxMetrics. The main applications, OxMetrics and OxEdit are in the
root of that folder:

Start OxMetrics by double clicking on it (you can also drag it to the dock for more
convenient startup). If this is the first time you use the new OxMetrics, you may wish
to reset the size of the various windows. Catch the edge of the relevant window with
the mouse pointer which should change form to a double arrow, and expand or contract
as desired. Your initial screen could look like the capture shown on the previous page.
Clicking on a menu item (e.g., File, Edit etc.) at the top of the screen drops down
the menu as shown on page 31 for File. You can select a different document window by
clicking on the relevant entry in the left panel (the workspace), for example Results
for the default results windows of the modelling packages. Alternatively, you can use
the row of tabs just below the toolbars.

30

3.2

Chapter 3 Getting Started: OS X

Registering OxMetrics

If you install OxMetrics normally, it will already be registered, and you can start
working immediately. A licence code entered during installation is available to all
users of the computer (which would require a multiple-user licence). To add more
shared licences, rerun the installer.
An unregistered version of OxMetrics will show the registration dialog on screen,
as displayed above. Note that a licensing code entered when running the program as
the current user is only available to that user. Enter the licensing code and your name
in the respective fields (you must enter the code provided by your distributor).
An OxMetrics Enterprise licensing code enables most modules. Otherwise, many
modules have their own additional licence code, which can be entered in the registration
dialog. Once OxMetrics has the first registration code, the above dialog will not appear
automatically anymore. To enter additional codes, activate the Help/Registration menu
(current user only), or rerun the installer package (shared licence).
We trust that you use a legal copy of OxMetrics and client modules. That will allow
us to keep developing the programs.

3.3

Loading and viewing the tutorial data set

Without data, there is not much that can be done, so the first step is to load data. Many
tutorials use a data set called data.in7.

3.3 Loading and viewing the tutorial data set

31

We shall load this tutorial data set here. Access the File menu in OxMetrics, and
choose Open:

If you installed in the default directory structure, the data will be in the directory
/Applications/OxMetrics7/data, so locate that directory and select the Data file:

By default, all files are displayed, but you can refine the files listed from the Enable
pop-up list:

32

Chapter 3 Getting Started: OS X

The data file contions artificial data on consumption, income, inflation and output,
denoted by CONS, INC, INFLAT, and OUTPUT respectively. The in7 extension indicates a OxMetrics data file (a format which has remained the same for versions 7 and 8
of PcGive, then GiveWin, and is now used for OxMetrics, with some minor extensions
in the file format). The in7 file is a human-readable file, describing the data (variable
names, frequency, sample period, documentation etc.). There is a companion bn7 file,
which holds the actual numbers (in binary format, so this file cannot be edited directly).
OxMetrics can handle a wide range of data files, among them Excel files. You can also
cut and paste data series directly from a spreadsheet (but not formulae).
The data file will be loaded, and become the currently active database for plotting
and transformations. More than one database can be loaded, and the name of the currently active database is shown in the the toolbar. If more than one database is loaded,
this toolbar box can be used to switch active database:

A notification of the loaded file is written to the Results window, so the loaded
database does not acquire the focus. To see the database, click on it in the workspace.
Although data values are stored internally with about 15 to 16 digit accuracy (8 byte
floating point values), the data are displayed with 6 digits only in the spreadsheet:

On the bottom right of the OxMetrics window, in the status bar, the observation
under the cursor is shown with full accuracy:

Double clicking on the variable name shows the name and documentation of the
variable, both of which can be changed. For the CONS variable:

3.3 Loading and viewing the tutorial data set

33

Right-clicking on the variable name brings up a context menu related to that variable, e.g. to quickly graph it. Here it is shown for INC:

The data can be manipulated, much like in a spreadsheet program. Pressing the left
mouse button, and keeping it depressed, then dragging the mouse highlights a block of
data which can be copied to the clipboard for insertion in another part of the database
(click on the two-pages icon for copy, or the Cmd+C key; paste is the clipboard icon or
the Cmd+V key).
Double clicking on an observation brings up a revision box, where corrected values
can be entered (or missing values set to an observed outcome):

While two separate clicks will bring up the inline editor:

34

3.4

Chapter 3 Getting Started: OS X

OxMetrics graphics

The graphics facilities of OxMetrics are powerful yet easy to use. This section will show
you how to make time plots and scatter plots of variables in the database. OxMetrics
offers automatic selections of scaling etc., but you will be able to edit these graphs, and
change the default layout such as line colours and line types. Graphs can also be saved
in a variety of formats for later use in a word processor, or for reloading into OxMetrics.

3.4.1

A first graph

Graphics is the first entry on the Model menu. Alternatively, click on the graphics icon
on the toolbar. Either way brings up the following dialog box:

This is an example of a dialog with a multiple selection list control. In such a list,
you mark as many items as you want. Here we mark all the variables we wish to graph.
With the keyboard, you can only mark a single variable (by using the arrow up and
down keys), or range of variables (hold the shift key down while using the arrow up or
down keys).
With the mouse there is more flexibility:
single click to select one variable;
hold the Cmd key down and click to select additional variables;
hold the Shift key down and click to extend the selection range.
Here we select CONS and INC and then press the << button. This moves the
variables from the database list to the selection list, activating the buttons at the bottom,
as shown on the next page.
Press Actual series. Now the graph appears, which looks very much like Figure 3.1.
The only difference is the position of the legend. You can pick that up with the mouse,
and move it to another position in the graph as desired.

35

3.4 OxMetrics graphics

910

CONS

INC

900

890

880

870

860

1955

1960

1965

Figure 3.1

1970

1975

1980

1985

1990

Time plot of CONS and INC

Note that, when the graph is active, and the mouse is moved over the graph, the
status bar at the foot of the OxMetrics window displays the graph coordinates. Inside a
graph these are the real-world coordinates (X,Y), the actual data values. Outside these
are pixel coordinates (pX,pY): a graphics window in OxMetrics runs from (0,0) in the
bottom left, to (15000,10000) in the top right (further explanation is in Chapter 14).
Most graphs in this book are boxed in. You can change the default, for the current
graph only, by double clicking on the graph (or selecting Edit/Edit Graph), then clicking
on Graph layout in the left-hand column, and activating Box all areas:

36

Chapter 3 Getting Started: OS X

Alternatively, choose Graphics from the OxMetrics/Preferences menu, and activate


Box all areas, as shown on the nect page. This will change the default for all future
graphs that are made with OxMetrics.

3.4.2

Multiple graphs

One of the powerful features of OxMetrics is the ability to draw multiple graphs simultaneously on-screen within one graphics window (and you are not restricted to just one
graphics window). We shall now get two graphs on screen, with the second a cross-plot
of CONS and INC. Click on the Graphics toolbar button, note that CONS and INC are
still selected (you can also variables to the opposing listbox by double clicking on them,
or empty the selection by pressing Clear). The first variable in the selected list, CONS
here, will be the Y variable (if CONS is not on top you can select it, and press the Move
up button). Click on Scatter plot (YX) to create the plot.

37

3.4 OxMetrics graphics

If you accidentally did it wrong, click in the new sub plot (or plot area, as we tend
to call it), selecting the entire second area, then press delete to remove it again.
CONS

INC

900

880

860
1955
900

1960

1965

1970

1975

1980

1985

1990

CONS INC

890
880
870
860
870

875

880

885

Figure 3.2

890

895

900

905

910

Multiple graphs

A useful aspect of OxMetrics is that graphs can be edited and features added while
they are on screen, and after adding other graphs if desired. Double click on the scatter
plot graph, select Regression in the Edit Graphics dialog, and add one regression line
as shown:

The final result is in Figure 3.2. The editing possibilities are manifold: Chapter 7
provides a detailed discussion, but you can always play around with graphs at your
leisure.
Finally, you can undo and redo the changes that were made. In this case, Undo

38

Chapter 3 Getting Started: OS X

will remove the graphics line again. Graph saving clears the undo/redo buffer, to avoid
excessive memory use.
3.4.3

Graph saving and printing

To print a graph directly to the printer when the graphics window has the focus, click on
the printer icon in the toolbar. You can preview the result first using the Print Preview
command from the File menu. If you have a PostScript printer, you can save the graph
to disk as PostScript, and then print it from the command line.
Graphs can be saved to disk in various formats (note that you can extend the view
of this dialog by clicking on the buttom next to the suggested filename):

Encapsulated PostScript (.eps), which is the vector format used to produce all the
graphs in this book;
OxMetrics Graphics File (.gwg);
PostScript (.ps), this is like EPS, but defaulting to a full page print.
Portable Network Graphics (.png), which is a bitmap format that may be useful for
insertion in web pages;
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.
3.4.4

Using the clipboard for graph pasting

There is an important distinction between copying graphs for use in internal OxMetrics
graphs, or for external use. When copying to the clipboard, the whole graphs is copied,
and two formats are available:
Copy Metafile to Clipboard
This is a vector format, so better quality.
Copy Bitmap to Clipboard
This is a bitmap format, so does not scale as well.
To paste the graph into Word, for example, you can use Edit/Copy Metafile to
Clipboard, and then paste it into Word. A metafile stores the actual vector graphics

3.5 Calculator

39

commands that were used to draw the graph, and thus scales well. The alternative is to
copy the bitmap to the clipboard.1
The standard copy command is used for internal paste. If no area is selected, the
whole graph is copied, otherwise the selected area only.
Try this by clicking on the second area in the current graph. Once selected (shown
by a hatched boundary) copy the area to the clipboard. Then first deselect the area by
clicking somewhere in the margin of the graph. A subsequent paste will add a copy as
the third area. Next, select the first area and paste again: this inserts the cross-plot into
the time-series plot (not a useful graph).

3.5

Calculator

Please note that OxMetrics and client modules are sensitive to the case of the variable
names so that cons, Cons, and CONS are treated as different variables. This can
be useful for distinguishing real (lower case) from nominal (capitals) variables, or logs
from levels, etc.
Two options are available for transforming data: by algebra or by a dialog approach,
which mimics the operation of a pocket calculator. We begin with the latter, as it is the
simplest. Press on the Calculator button leading to the capture shown below (or via the
Model menu and Calculator choice).

In several cases OxMetrics will offer a default name for a newly created variable:
prefixes of D for differences, e.g. DCONS;
prefixes of L for logarithms, e.g. LCONS;
suffix n for n-period lags, e.g. CONS 1.
So can you guess what DLCONS 1 is likely to be?
The aim is to build up an algebraic expression for the transformation (which is valid
Algebra code: see 2.6). The first transformation is to take the first difference of CONS.
Click on the CONS variable just to highlight it (dont double click), and then on the diff
button, accept a lag length of one, to see in the top part of the dialog:
1

We use LATEX for our typesetting system, and save all graphs as .eps files.

40

Chapter 3 Getting Started: OS X

Click on the large button with the = sign, and accept the default name of DCONS,
which will be created in the database, and added to the list of variables. A two-period
difference is just as easy to compute: select CONS, press the diff button and change the
length of the differencing period.
Another transformation to try: INCCONS. Double click on INC, click on the
minus button, and then double click on CONS. The expression now reads INCCONS,
press on = to evaluate. Name the variable SAVING (you could use a name like INC
CONS, but must enclose such a name in double quotes when using it in expressions).
Finally, we create a step dummy (or indicator variable), where the step lasts from
1979(2) to 1980(4). We need zeros outside that period, ones inside. Click on the dummy
button, and enter:

Click on OK, and then on = to create the dummy. Give it an informative name, such as
s792t804.
Tip We deliberately gave no examples involving lags. For estimation in modules such
as TSP or PcGive, lags are best created at the model formulation stage, where the
programs will keep track of their presence for dynamic analysis.
Three additional operations can be performed on variables inside the listbox in the
Calculator:
Delete a variable: select and press the button labelled Del, or the Delete key; you
will have to confirm the deletion as the variable is eliminated from the database.
Move variables: use the < or > button to move (groups of) variables up or down.
This changes the order in the database.

3.6 Algebra

41

Rename a variable: select and press the Ren button; you will be prompted for a new
name.
All changes to the database can be undone from the Edit menu.
Exit the calculator (Esc or click on the x button), and graph some of the variables
to check whether the transformations are correct. All transformations are logged to the
Results window:
Algebra code for data.in7:
DCONS = diff(CONS,1);
SAVING = INC - CONS;
dumm1979 = dummy(1979,2, 1980,4);

This leads us to the next topic.

3.6

Algebra

Algebra enables us to do transformations by typing the expressions directly into an


editor. It also allows saving and loading from disk of a whole chunk of statements.
The only variable names allowed in Algebra are those that would be valid names in
computer languages like Ox or C: the first character must be a letter or an underscore,
the rest a letter, underscore or digit. Names which do not follow this convention must
be enclosed in double quotes.
Algebra uses database variables as follows: if a left-hand variable is already in the
database it will be overwritten, otherwise it will be created. Variables on the right must
exist, possibly because of preceding lines of algebra code. Algebra is case-sensitive,
meaning that LCONS, LCons and lcons refer to three different variables.
As an example, we rerun the transformations of the previous section. To verify if
that will work, activate the database, and press Undo until the database is back in its
original state. Now set focus to the Results window. Locate the logged Algebra code in
the Results window. There are two ways to quickly run this code:
select the block of Algebra code, and type Ctrl+A to execute it;
using the Algebra editor.
Because the former is straightforward, we now discuss the latter method.
Highlight the three algebra lines, and copy them to the clipboard (Cmd+C). From the
Model menu, select Algebra, and paste the code (Cmd+V) to see the dialog on the next
page.
Now press Run. The variables have been recreated. We can inspect the database to
see what happened. The algebra code is again logged to the Results window.
Tip The bottom part of the Algebra editor is there to save typing. For example, to
insert the code LCONS=log(CONS);, select CONS in the Database box of the Algebra editor. Next, selext log(VAR) under Functions, and click on Write Algebra
Code.
Tip As in the Calculater, database variables can be deleted, moved and renamed.

42

Chapter 3 Getting Started: OS X

As a more advanced example, we explain how it is possible to create the same


dummy using the insample function and a conditional assignment. The insample
function has four arguments: startyear, startperiod, endyear, endperiod. It returns 1 (or
TRUE: everything which is not 0 is TRUE) if the observation under consideration falls
within the sample, otherwise it returns 0 (FALSE). The conditional assignment works
as follows: the conditional statement (the if part) is followed by a question mark and
the then part, which is followed by a colon and the else part. Read:
i1980p1 = insample(1980, 1, 1980, 1) ?

1 :

0;

as: i1980p1 takes on the value 1 for the observations which are in the specified sample,
and the value 0 for the other observations. In this case, the same result can be obtained
by writing:
i1980p1 = insample(1980, 1, 1980, 1);.
An error message pops up if you make a mistake. The error can be corrected on
returning to the algebra editor. The text at the top of the Algebra error shows the text of
the last error (if one occurred).
Tip A sensible strategy is to store algebra code and basic data only, and recompute
transforms during each run: this economizes on storage and facilitates updating
analyses when data are revised or corrected.
Tip If you load a database, text file, or graph from disk, and make a change to it, this
is shown by a star before the name. When the document is saved, the star disappears
again.
Do not save the modified data set. Either undo the changes, or quit the data set, and
reload the original data.in7/data.bn7. Algebra is documented in Chapter 12.
This completes the getting-started chapter. Before giving some examples on modelling with OxMetrics, we briefly discuss the workspace window. The remainder of the
tutorial are more detailed examples on graph editing, graphics, data loading and saving,
and data transformations.

3.7 The workspace

3.7

43

The workspace

Often, after working in OxMetrics for a while, there are many open windows, with
graphs, data and results. The workspace helps navigating between these, by showing
which documents are open in OxMetrics, as shown here:

Here there are two data file open, data.in7, which has been modified (as indicated
by the * in front of the name), and dowjones.xls. There is one save graph (also modified), and the default Data Plot window. In addition, there is the Results window. The
available modules are listed under Modules (with all interactive modelling packages
such as PcGive, STAMP, etc. now grouped under the Model header).
The Help pane is also shown, here with the Ox help index. Double-clicking on acf()
would open the Ox documentation at the acf function in trhe default web browser.
Cmd+clicking on the document category (Data, Graphics, Code, or Text) gives a
context menu. For Data it is:

while Cmd+clicking on the document name gives:

44

Chapter 3 Getting Started: OS X

Chapter 5, which is the next in line, introduces the OxMetrics modules. This includes an example on estimating a GARCH(1,1) model using PcGive. Because OxMetrics behaves very similarly on Windows, OS X and Linux, we shall not explicitly
distinguish anymore in the remainder.

Chapter 4
Getting Started: Linux

This chapter discusses some of the basic skills required to get started with OxMetrics on Linux. Since OxMetrics provides the data which other modules analyze, and
receives all the text output and graphics which you create in (say) PcGive, you should
begin by briefly learning how OxMetrics works.
45

46

Chapter 4 Getting Started: Linux

Once OxMetrics has started, you will be able to load data, create graphs, and transform data using the OxMetrics calculator or algebra. Then, use the Model command
on the Model menu to start econometric modelling using, for example, PcGive. When
you exit OxMetrics it will automatically close all active modules which depend on it.
In some of the coming tutorials we shall be using OxMetrics as a stand-alone program.
There are many interesting things to be done even without using additional modules!

4.1

Starting OxMetrics

OxMetrics is installed in the /usr/share folder, to a subfolder called OxMetrics7 for


version 7 of OxMetrics. Shortcuts to the main applications OxMetrics and OxEdit are
also installed under Education and Programming:

All the screen captures in this chapter were taken under Fedora 7 (x86 64) running
GNOME 2.18.3. Start OxMetrics by double clicking on the menu entry. If this is the
first time you use the new OxMetrics, you may wish to reset the size of the various
windows. Catch the edge of the relevant window with the mouse pointer which should
change form to a double arrow, and expand or contract as desired. Your initial screen
could look like the capture shown on the previous page.
Clicking on a menu item (e.g., File, Edit etc.) at the top of the screen drops down
the menu as shown on page 48 for File. You can select a different document window by
clicking on the relevant entry in the left panel (the workspace), for example Results
for the default results windows of the modelling packages. Alternatively, you can use
the row of tabs just below the toolbars.

4.2 Registering OxMetrics

4.2

47

Registering OxMetrics

Installation of OxMetrics does not automatically prompt for a licensing code (unlike Windows or OS X) because this is against the RPM guidelines. When running
OxMetrics for the first time, it will be unregistered and show the registration dialog on
screen, as displayed above. Enter the licensing code and your name in the respective
fields (you must enter the code provided by your distributor).
You can enter your code this way, but note that it will only be available to the current
user. That should be sufficient if you have a single licence. A multi-user licence may
need to be shared and requires the registration to be run as superuser. To do this, run
the /usr/share/OxMetrics7/register script from a terminal as superuser.
An OxMetrics Enterprise licensing code enables most modules. Otherwise, many
modules have their own additional licence code, which can be entered in the dialog.
Once OxMetrics has the first registration code, the above dialog will not appear automatically anymore. To enter additional codes, activate the Help/Registration menu, or
rerun the register script as superuser.
We trust that you use a legal copy of OxMetrics and client modules. That will allow
us to keep developing the programs.

4.3

Loading and viewing the tutorial data set

Without data, there is not much that can be done, so the first step is to load data. Many
tutorials use a data set called data.in7.
The data file contains artificial data on consumption, income, inflation and output,
denoted by CONS, INC, INFLAT, and OUTPUT respectively. The in7 extension indi-

48

Chapter 4 Getting Started: Linux

cates a OxMetrics data file (a format which has remained the same for versions 7 and 8
of PcGive, then GiveWin, and is now used for OxMetrics, with some minor extensions
in the file format). The in7 file is a human-readable file, describing the data (variable
names, frequency, sample period, documentation etc.). There is a companion bn7 file,
which holds the actual numbers (in binary format, so this file cannot be edited directly).
OxMetrics can handle a wide range of data files, among them Excel files. You can also
cut and paste data series directly from a spreadsheet (but not formulae).
We shall load this tutorial data set here. Access the File menu in OxMetrics, and
choose Open:

If you installed in the default directory structure, the data will be in the directory
/usr/share/OxMetrics7/data, so locate that directory and select the Data file, as
shown here:

By default, all files are displayed, but you can refine the files listed from the All files
pop-up list:

4.3 Loading and viewing the tutorial data set

49

The data file will be loaded, and become the currently active database for plotting
and transformations. More than one database can be loaded, and the name of the currently active database is shown in the the toolbar. If more than one database is loaded,
this toolbar box can be used to switch active database:

A notification of the loaded file is written to the Results window, so the loaded
database does not acquire the focus. To see the database, click on it in the workspace.
Although data values are stored internally with about 15 to 16 digit accuracy (8 byte
floating point values), the data are displayed with 6 digits only in the spreadsheet:

On the bottom right of the OxMetrics window, in the status bar, the observation
under the cursor is shown with full accuracy:

Double clicking on the variable name shows the name and documentation of the
variable, both of which can be changed. For the CONS variable:

50

Chapter 4 Getting Started: Linux

Right-clicking on the variable name brings up a context menu related to that variable, e.g. to quickly graph it. Here it is shown for INC:

The data can be manipulated, much like in a spreadsheet program. Pressing the left

4.4 OxMetrics graphics

51

mouse button, and keeping it depressed, then dragging the mouse highlights a block of
data which can be copied to the clipboard for insertion in another part of the database
(click on the two-pages icon for copy, or the Ctrl+C key; paste is the clipboard icon or
the Ctrl+V key).
Double clicking on an observation brings up a revision box, where corrected values
can be entered (or missing values set to an observed outcome):

While two separate clicks will bring up the inline editor:

4.4

OxMetrics graphics

The graphics facilities of OxMetrics are powerful yet easy to use. This section will show
you how to make time plots and scatter plots of variables in the database. OxMetrics
offers automatic selections of scaling etc., but you will be able to edit these graphs, and
change the default layout such as line colours and line types. Graphs can also be saved
in a variety of formats for later use in a word processor, or for reloading into OxMetrics.
4.4.1

A first graph

Graphics is the first entry on the Model menu. Alternatively, click on the graphics icon
on the toolbar. Either way brings up the following dialog box as shown on the next
page.
This is an example of a dialog with a multiple selection list control. In such a list,
you mark as many items as you want. Here we mark all the variables we wish to graph.
With the keyboard, you can only mark a single variable (by using the arrow up and
down keys), or range of variables (hold the shift key down while using the arrow up or
down keys).
With the mouse there is more flexibility:
single click to select one variable;
hold the Ctrl key down and click to select additional variables;
hold the Shift key down and click to extend the selection range.

52

Chapter 4 Getting Started: Linux

Here we select CONS and INC and then press the << button. This moves the
variables from the database list to the selection list, activating the buttons at the bottom:

Press Actual series. Now the graph appears, which looks very much like Figure 4.1.
The only difference is the position of the legend. You can pick that up with the mouse,

53

4.4 OxMetrics graphics


and move it to another position in the graph as desired.

910

CONS

INC

900

890

880

870

860

1955

1960

1965

Figure 4.1

1970

1975

1980

1985

1990

Time plot of CONS and INC

Note that, when the graph is active, and the mouse is moved over the graph, the
status bar at the foot of the OxMetrics window displays the graph coordinates. Inside a
graph these are the real-world coordinates (X,Y), the actual data values. Outside these
are pixel coordinates (pX,pY): a graphics window in OxMetrics runs from (0,0) in the
bottom left, to (15000,10000) in the top right (further explanation is in Chapter 14).

Most graphs in this book are boxed in. You can change the default, for the current
graph only, by double clicking on the graph (or selecting Edit/Edit Graph), then clicking
on Graph layout in the left-hand column, and activating Box all areas, as shown on the
next page.
Alternatively, choose Graphics from the Model/Preferences menu, and activate Box
all areas, as shown in the second capture on the next page.

54

Chapter 4 Getting Started: Linux

The second method will change the default for all future graphs that are made with
OxMetrics.

55

4.4 OxMetrics graphics


4.4.2

Multiple graphs

One of the powerful features of OxMetrics is the ability to draw multiple graphs simultaneously on-screen within one graphics window (and you are not restricted to just one
graphics window). We shall now get two graphs on screen, with the second a cross-plot
of CONS and INC. Click on the Graphics toolbar button, note that CONS and INC are
still selected (you can also variables to the opposing listbox by double clicking on them,
or empty the selection by pressing Clear). The first variable in the selected list, CONS
here, will be the Y variable (if CONS is not on top you can select it, and press the Move
up button). Click on Scatter plot (YX) to create the plot.
If you accidentally did it wrong, click in the new sub plot (or plot area, as we tend
to call it), selecting the entire second area, then press delete to remove it again.

CONS

INC

900

880

860
1955
900

1960

1965

1970

1975

1980

1985

1990

CONS INC

890
880
870
860
870

875

880

885

Figure 4.2

890

895

900

905

910

Multiple graphs

A useful aspect of OxMetrics is that graphs can be edited and features added while
they are on screen, and after adding other graphs if desired. Double click on the scatter
plot graph, select Regression in the Edit Graphics dialog, and add one regression line
as shown:

56

Chapter 4 Getting Started: Linux

The final result is in Figure 4.2. The editing possibilities are manifold: Chapter 7
provides a detailed discussion, but you can always play around with graphs at your
leisure.
Finally, you can undo and redo the changes that were made. In this case, Undo
will remove the graphics line again. Graph saving clears the undo/redo buffer, to avoid
excessive memory use.
4.4.3

Graph saving and printing

To print a graph directly to the printer when the graphics window has the focus, click on
the printer icon in the toolbar. You can preview the result first using the Print Preview
command from the File menu. If you have a PostScript printer, you can save the graph
to disk as PostScript, and then print it from the command line.
Graphs can be saved to disk in various formats (note that you can extend the view
of this dialog by clicking on the buttom next to the suggested filename):
Encapsulated PostScript (.eps), which is the vector format used to produce all the
graphs in this book;
OxMetrics Graphics File (.gwg);
PostScript (.ps), this is like EPS, but defaulting to a full page print.
Portable Network Graphics (.png), which is a bitmap format that may be useful for
insertion in web pages;
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

4.5 Calculator

57

saved alongside it. Then, when loading a previously saved EPS file (say), OxMetrics
can use the GWG file to reload the graph.

4.4.4

Using the clipboard for graph pasting

There is an important distinction between copying graphs for use in internal OxMetrics
graphs, or for external use. When copying to the clipboard, the whole graphs is copied,
and only one the Copy Bitmap to Clipboard option is available. This means that the
graph is copied as a bitmap, which is less desirable for insertion in documents than a
vector format.
The standard copy command is used for internal paste. If no area is selected, the
whole graph is copied, otherwise the selected area only.
Try this by clicking on the second area in the current graph. Once selected (shown
by a hatched boundary) copy the area to the clipboard. Then first deselect the area by
clicking somewhere in the margin of the graph. A subsequent paste will add a copy as
the third area. Next, select the first area and paste again: this inserts the cross-plot into
the time-series plot (not a useful graph).

4.5

Calculator

Please note that OxMetrics and client modules are sensitive to the case of the variable
names so that cons, Cons, and CONS are treated as different variables. This can
be useful for distinguishing real (lower case) from nominal (capitals) variables, or logs
from levels, etc.
Two options are available for transforming data: by algebra or by a dialog approach,
which mimics the operation of a pocket calculator. We begin with the latter, as it is the
simplest. Press on the Calculator button leading to the capture shown below (or via the
Model menu and Calculator choice).
In several cases OxMetrics will offer a default name for a newly created variable:
prefixes of D for differences, e.g. DCONS;
prefixes of L for logarithms, e.g. LCONS;
suffix n for n-period lags, e.g. CONS 1.
So can you guess what DLCONS 1 is likely to be?

58

Chapter 4 Getting Started: Linux

The aim is to build up an algebraic expression for the transformation (which is valid
Algebra code: see 2.6). The first transformation is to take the first difference of CONS.
Click on the CONS variable just to highlight it (dont double click), and then on the diff
button, accept a lag length of one, to see in the top part of the dialog:

4.5 Calculator

59

Click on the large button with the = sign, and accept the default name of DCONS,
which will be created in the database, and added to the list of variables. A two-period
difference is just as easy to compute: select CONS, press the diff button and change the
length of the differencing period.
Another transformation to try: INCCONS. Double click on INC, click on the
minus button, and then double click on CONS. The expression now reads INCCONS,
press on = to evaluate. Name the variable SAVING (you could use a name like INC
CONS, but must enclose such a name in double quotes when using it in expressions).
Tip We deliberately give no examples involving lags. For estimation in modules such
as TSP or PcGive, lags are best created at the model formulation stage, where the
programs will keep track of their presence for dynamic analysis.
Three additional operations can be performed on variables inside the listbox in the
Calculator:
Delete a variable: select and press the button labelled Del, or the Delete key; you
will have to confirm the deletion as the variable is eliminated from the database.
Move variables: use the < or > button to move (groups of) variables up or down.
This changes the order in the database.
Rename a variable: select and press the Ren button; you will be prompted for a new
name.
All changes to the database can be undone from the Edit menu.
Finally, we create a step dummy (or indicator variable), where the step lasts from
1979(2) to 1980(4). We need zeros outside that period, ones inside. Click on the dummy
button, and enter:

60

Chapter 4 Getting Started: Linux

Click on OK, and then on = to create the dummy. Give it an informative name, such as
s792t804.
Exit the calculator (Esc or click on the x button), and graph some of the variables
to check whether the transformations are correct. All transformations are logged to the
Results window:
Algebra code for data.in7:
DCONS = diff(CONS,1);
SAVING = INC - CONS;
dumm1979 = dummy(1979,2, 1980,4);

This leads us to the next topic.

4.6

Algebra

Algebra enables us to do transformations by typing the expressions directly into an


editor. It also allows saving and loading from disk of a whole chunk of statements.
The only variable names allowed in Algebra are those that would be valid names in
computer languages like Ox or C: the first character must be a letter or an underscore,
the rest a letter, underscore or digit. Names which do not follow this convention must
be enclosed in double quotes.
Algebra uses database variables as follows: if a left-hand variable is already in the
database it will be overwritten, otherwise it will be created. Variables on the right must
exist, possibly because of preceding lines of algebra code. Algebra is case-sensitive,
meaning that LCONS, LCons and lcons refer to three different variables.
As an example, we rerun the transformations of the previous section. To verify if
that will work, activate the database, and press Undo until the database is back in its
original state. Now set focus to the Results window. Locate the logged Algebra code in
the Results window. There are two ways to quickly run this code:
select the block of Algebra code, and type Ctrl+A to execute it;
using the Algebra editor.
Because the former is straightforward, we now discuss the latter method.
Highlight the three algebra lines, and copy them to the clipboard (Ctrl+C). From
the Model menu, select Algebra, and paste the code (Ctrl+V) to see the dialog on the
next page.
Now press Run. The variables have been recreated. We can inspect the database to
see what happened. The algebra code is again logged to the Results window.
Tip The bottom part of the Algebra editor is there to save typing. For example, to
insert the code LCONS=log(CONS);, select CONS in the Database box of the Algebra editor. Next, selext log(VAR) under Functions, and click on Write Algebra
Code.
Tip As in the Calculater, database variables can be deleted, moved and renamed.

4.6 Algebra

61

As a more advanced example, we explain how it is possible to create the same


dummy using the insample function and a conditional assignment. The insample
function has four arguments: startyear, startperiod, endyear, endperiod. It returns 1 (or
TRUE: everything which is not 0 is TRUE) if the observation under consideration falls
within the sample, otherwise it returns 0 (FALSE). The conditional assignment works
as follows: the conditional statement (the if part) is followed by a question mark and
the then part, which is followed by a colon and the else part. Read:
i1980p1 = insample(1980, 1, 1980, 1) ? 1 : 0;
as: i1980p1 takes on the value 1 for the observations which are in the specified sample,
and the value 0 for the other observations. In this case, the same result can be obtained
by writing:
i1980p1 = insample(1980, 1, 1980, 1);.
An error message pops up if you make a mistake. The error can be corrected on
returning to the algebra editor. The text at the top of the Algebra error shows the text of
the last error (if one occurred).
Tip A sensible strategy is to store algebra code and basic data only, and recompute
transforms during each run: this economizes on storage and facilitates updating
analyses when data are revised or corrected.
Tip If you load a database, text file, or graph from disk, and make a change to it, this is
shown by a star before the name. When the document is saved, the star disappears.

62

Chapter 4 Getting Started: Linux

Do not save the modified data set. Either undo the changes, or quit the data set, and
reload the original data.in7/data.bn7. Algebra is documented in Chapter 12.
This completes the getting-started chapter. Before giving some examples on modelling with OxMetrics, we briefly discuss the workspace window. The remainder of the
tutorial are more detailed examples on graph editing, graphics, data loading and saving,
and data transformations.

4.7

The workspace

Often, after working in OxMetrics for a while, there are many open windows, with
graphs, data and results. The workspace helps navigating between these, by showing
which documents are open in OxMetrics, as shown here:

Here there are two data file open, data.in7, which has been modified (as indicated
by the * in front of the name), and dowjones.xls. There is one save graph (also modified), and the default Data Plot window. In addition, there is the Results window. The
available modules are listed under Modules (with all interactive modelling packages
such as PcGive, STAMP, etc. now grouped under the Model header).
The Help pane is also shown, here with the Ox help index. Double-clicking on acf()
would open the Ox documentation at the acf function in trhe default web browser.
Right clicking on the document category (Data, Graphics, Code, or Text) gives a
context menu. For Data it is:

4.7 The workspace

63

while right clicking on the document name gives:

Chapter 5, which is the next in line, introduces the OxMetrics modules. This includes an example on estimating a GARCH(1,1) model using PcGive. Because OxMetrics behaves very similarly on Windows, OS X and Linux, we shall not explicitly
distinguish anymore in the remainder.

Chapter 5
OxMetrics Modules
5.1

OxMetrics Modules

There is an increasing number of computer programs which cooperate with OxMetrics to deliver an easy-to-use yet powerful user experience. Such modules implement
different services, and may use OxMetrics:
to receive the data for analysis;
to store the text output from the analysis;
to display the graphical output.
At the time of writing, the OxMetrics compatible modules include:
G@RCH (Laurent, 2013)
Ox Professional: OxRun and OxPack (Doornik, 2013)
PcGive (Hendry and Doornik, 2013), including PcNaive (Doornik and Hendry,
2013)
STAMP (Koopman, Harvey, Doornik, and Shephard, 2013)
TSP (Hall and Cummins, 2005)
The above modules (except for TSP) are all accessed via the Model command. In
addition, there are interactive packages written in Ox which can be run via OxPack.
It is possible that only a subset of the modules are installed. The remainder of this
chapter gives a brief introduction on how to use PcGive. Even if PcGive is not one of
the modules you plan to use, it will still be useful to read it: most modules work in a
similar way. Before we start, we load another database, and digress by talking about
financial data.

5.2

Financial data

Load the dowjones.xls data set from the OxMetrics7\data folder.


The
DOWJONES variable holds the weekly DowJones index (Dow Jones Industrial
Average): close at midweek1 from Janary 1980 to September 1994, 770 observations
in total.
1

The figures are for Wednesday, or Tuesday if the stock market was closed on Wednesday.
The data are from www.djindexes.com.

64

5.2 Financial data

65

We are interested in the returns, log Yt log Yt1 , already in the database as
DLDOWJONES. First, we illustrate the the returns can also be plotted directly from
the levels. Make sure dowjones.xls is the active database. Click on Graphics, select
DOWJONES, and click on All plot types>. Then select transformation Growth rates:

The outcomes are given in the top panel of Figure 5.1. The large negative return of
17.4% corresponds to the Black Monday crash of 19 October 1987. The data show
behaviour that is typical of financial time-series: clustering of volatility and so-called
thick tails: there are more observations in the tail than can be expected from a normal
distribution.
Next, activate Graphics again, using the same variable. Select time-series properties
and note that the transformation is still set to growth rates. Click on ACF, and set the
lag length to 50 as shown on the next page.
The outcomes are in the second panel of top panel of Figure 5.1, indicating that
there does not seem to be much memory, if any, in the returns. This should be expected.
Next, use the calculator, and create the squared returns. The ACF of the squared returns
are in the final panel of Figure 5.1 (remember to reset the transformation back to none).
This plot suggests that there is indeed some persistence in volatility.

66

Chapter 5 OxMetrics Modules

DLDOWJONES

0.0
-0.1
1980
1

1982

1984

1986

1988

1990

1992

1994

ACF-DLDOWJONES

0
1

10

15

20

25

30

35

40

45

50

15

20

25

30

35

40

45

50

ACF-sqrReturns

Figure 5.1

10

Dow Jones returns, ACF of returns, ACF of squared returns

5.3 Weekly and daily data

5.3

67

Weekly and daily data

When moving the cursor over the graph of the actual returns, the status bar at the bottom
can be seen to display the date in the plot. There are too many observations for an
accurate reading, but the large negative shock can be pinpointed in October 1987.
Inspection of the database reveals that the first variable is called Date, and shows
the same dates as in the row labels:

Double-clicking on the variable name reveals that it is of type Date. Changing it


to Default changes the labelling to an undated dataset, and the Date values to large
numbers:

These are the numbers that OxMetrics and Ox use to represent dates. Any fractional
value represents fractional time (so 0.5 is 12:00 and 0.75 18:00 on the 24-hour clock).
Undo the changes to get back to the dated database. With weekly data, there are
some years that have 52 weeks, and others with 53. Therefore, the method of using a
fixed frequency, as used for annual, quarterly and monthly databases, does not work.
Instead, a database can now be dated:
the first column must be of type Date,
the first column holds date values (there are several Algebra functions to help creating these),
the optional fractional part of this indicates time,
the first and last observation must be valid, i.e. cannot be missing.
These criteria are satisfied in dowjones.xls, and the Excel dates are translated in Ox
dates when reading the file (and the other way round when saving). Database! with
dates
Next, to illustrate the modelling sequence in OxMetrics, we estimate a GARCH
model without paying too much attention to the actual outcomes.

68

5.4

Chapter 5 OxMetrics Modules

PcGive

PcGive is an interactive program for dynamic econometric modelling. Like other interactive modelling packages, it can be started in three ways:
By clicking on the Model entry under Modules in the workspace on the left-hand
side:

Via Model on the Model menu:

Using the Model toolbar button:

The modelling dialog gives access to all the modelling features of the OxMetrics
modules. In this case, only STAMP and PcGive are listed, but you may have more. The
module will use one of the databases loaded in OxMetrics.
The first step is to select a model category, and for the category a model type. The
images at the top allow you to see the choices for all available modules, or to restrict it
to a specific module. In your case, it is likely that Module is set to all (if not, click on
the OxMetrics item for All, or on PcGive).
Change the Category to financial data and the model to GARCH.

5.4 PcGive

5.4.1

69

Formulate a model

Click on the large Formulate button, to see the standard formulation dialog. On the
right-hand side is the list with the database content, while the box on the left, empty as
yet, is for the model.
This dialog is used by most modules to formulate the linear part of the model. Other
actions that can be taken are:
Change the default lag length when selecting. The choices are: lag 0 to a specified
lag, just the specified lag, or none.
Empty the entire model formulation by pressing Clear>>.
The box immediately below the database contains the so-called special variables.
These are made available even when not present in the database, and may be treated
in a special way.
Below that, still on the database side, is the option to change databases, if more than
one are open in OxMetrics. But the model only works on one database.
On the left-hand side, below the selection (the model formulation), is a drop-down
box to change the status of selected variables. It currently reads Use default status,

70

Chapter 5 OxMetrics Modules

which means that variables are added to the model as such: the first addition to an
empty model is the dependent variable, the rest are regressors in the mean.
For the GARCH model there are three types:
Y the endogenous (dependent) variable, by default the first,
X regressor, the default for all other variables,
H a regressor that enters the conditional variance equation.
If another status is selected in the drop down box, that will be used for the added
variables instead of the default (but lagged variables can never be the dependent
variable).
To change status of variables that are already in the model: highlight the variables
in the selection box, choose a status, and press the Set button. Note that it is also
possible to change status by right-clicking on a variable.
Finally, the last drop-down box below the selection allows the recall of a previously
formulated model.

Double click on the DLDOWJONES variable:

Press on OK to set the GARCH model properties. There are quite a few options,
but the default of a GARCH(1,1) model suffices:

5.4 PcGive

71

The final step is the estimation period, where we can accept the default again:

Click on OK and the output appears in the results window. To end this section, click
on the Test button:

Check Graphic analysis:

72

Chapter 5 OxMetrics Modules

and accept the default choice. The figure is as in Figure 5.2. Note that in the middle
panel (the standardized residuals), we zoomed in on the crash and changed the style
to index lines. It is quite likely that this large outlier affects the quality of this model
(Doornik and Ooms, 2008 and Doornik and Ooms, 2005).
DLDOWJONES

Fitted

1982

1984

0.0
-0.1
1980
2.5

1986

1988

1990

1992

1994

r:DLDOWJONES (scaled)

-2.5

1987-7
0.075

1982

1984

10

11

12

1988-1

CondSD

0.050
0.025
1980

Figure 5.2

1986

1988

1990

1992

GARCH(1,1) model for Dow Jones returns

1994

5.5 TSP

5.5

73

TSP

TSPtm is a complete language for the estimation and simulation of econometric models.
It works in two modes:
TSP Session Interactive mode
Commands are entered and executed directly.
TSP Batch mode
A complete program is executed.
Both modes can be used in OxMetrics. As an example, we start by entering a small
program interactively, which is then saved an run in batch mode.
5.5.1

TSP in interactive mode

Start TSP from the Modules menu:

This starts the TSP launcher, which allows for the selection of a default working folder
(here still shown in its OxMetrics 5 implementation):

Press the Start TSP Session button to start:


If there is a database open in OxMetrics, TSP will offer to load it. Press N to skip.
If you press enter you may see (here we accepted loading AIRLINE.in7):
Read OxMetrics database "AIRLINE.IN7"? [Yes]/No/All/nOne
Current sample:

1949:1 to 1960:12

74

Chapter 5 OxMetrics Modules


*** NOTE: If you update or open new OxMetrics databases,
use the RELOAD command to read them into TSP.
Enter TSP statements:
1 ?

Otherwise youll be taken directly to the TSP prompt.


Then enter the commands given in bold below, pressing the Enter key at the end of
every command line.
Make sure there is no database loaded, if necessary use the Clear command to start
from scratch.
Enter TSP statements:
1 ? smpl 1 100
2 ? random eps
3 ? random(uniform) x
4 ? y = 1 + 2 * x + eps
5 ? graph y x
6 ? olsq y c x
These commands set the frequency to annual, the sample to 1100, generate a variable eps from the standard normal distribution, and x from the uniform distribution.
Then y is created as a linear combination of these. The graph command creates a scatter plot with x on the horizontal axis, and y on the vertical axis. The final command
regresses y on a constant and x.
Afterwards, the screen could look like the capture shown below.

5.5 TSP

75

The following may be noticed:


The TSP console window is entitled TSP Session. The marker at the margin shows
the command entry line.
To stop TSP type quit at the command line.
The command line is after the last question mark. A quick way to go there is with
Ctrl+End.
Commands can only be entered at the command line.
When on the command line, use arrow up/down to recall previous commands, which
can then be edited for re-execution.
Text above the command line can be edited and deleted as normal, including the
standard copy and paste facilities.
Only part of a text line can be pasted at the command prompt: a block which contains a return is not allowed.
A command wizard assists in formulating TSP commands. For example, type olsq
at the command prompt, and press Ctrl+W (or click on the wizard icon):

A useful feature is that commands can be sent to TSP (the active module) from
any window, by selecting the block of text, and typing Ctrl+I. As an example, try the
following: type plot @res in the Results window, then select it and press Ctrl+I. The
TSP Plot window will pop up to show the residuals from the regression. (If the TSP
Plot window is hidden behind another window, you can locate it through the Windows
menu.)
Finally, type quit to stop the interactive session.
5.5.2

TSP Help

TSP Help is available from the OxMetrics Help menu

76

Chapter 5 OxMetrics Modules

5.5.3

TSP in batch mode

It is possible to create a TSP input file from an interactive session. The easiest way is
as follows:
1. Active the TSP Session window, right-click in the window and select Copy Commands. This copies all commands you entered to the clipboard (with a maximum
of 50). This option is available even after the interactive session has terminated.
2. Create a new text window using File/New/TSP, and paste the text into that window.
3. Add semicolons at the end of each line.
4. Use File/Save As to save the file as a .tsp file, e.g. tutreg.tsp.
With comments added, the file could be:
1
2
3
4
5
6

smpl 1 100;
random eps;
random(uniform) x;
y = 1 + 2 * x + eps;
graph y x;
olsq y c x;

?
?
?
?
?
?

Specify the range of data as 1-100.


Standard normal disturbances.
Uniform x.
Generate y.
Cross plot of x and y.
Regress y on x and a constant.

Now, when tutreg.tsp as the active window, the file can be run directly using one of
the following:
Modules/Run Default Module,
Ctrl+R,
click on the Run button on the toolbar,
right click on the file name in the workspace, and select TSP.
All are equivalent, and will create a window entitled tuttsp.out for the text output, as
well as a TSP Graph window.
5.5.4

Explorer options

When clicking the right mouse button on a TSP file in the Windows Explorer, there are
two related options on the context menu:
Open opens the TSP file in OxMetrics; this is the default action when double clicking on a TSP file.
Run runs the TSP file in OxMetrics.

OxMetrics Tutorials

Chapter 6
Tutorial on Graphics
This chapter discusses the various types of graphs which are available for (exploratory)
data analysis. Chapter 5 already gave some examples using weekly Dow Jones data;
Ch. 7 is mainly concerned with the mechanics of changing the appearance of graphs.
If youre not inside OxMetrics at the moment, restart and load the tutorial data set
data.in7/data.bn7. Note that recently loaded files are listed at on the File menu. Recent data files can also be accessed by right clicking on the Data folder in the workspace.
Create DCONS as the first difference of CONS, as shown in the Getting Started chapters
for your platform (the remaining screen captures are all made under Windows).

6.1

Descriptive graphics

79

80

Chapter 6 Tutorial on Graphics

Activate the Graphics choice on the Model menu, select CONS and DCONS, by
marking them in the Database list box (remember: to select two (or more) variables,
click on CONS, then hold the Ctrl key down and click on DCONS), then press the <<
button to move them into the selection list (the list on the left-hand side). The screen
capture is shown on the previous page.
Next press All plot types >. Select Actual series at the top, and at the left, and tick
the Create separate plots box on the right:

Then press Plot, to create the graph, and Cancel to exit the dialog. The output
should correspond to the top two graphs of Figure 6.1.
To add some graphs of the time-series properties, restart Graphics (note that CONS
and DCONS are still selected), press All plot types >, and choose Time-series properties as the graph type.
Click Next to choose both ACF for the sample autocorrelation function (or covariogram; you can also choose to plot the correlogram instead, which uses running means
and variances, see 10.5) and PACF for the partial autocorrelation function. You can
also change the length of the ACF and PACF if you wish. Tick both ACF and PACF. If
necessary, mark Create separate plots and set the lag length to 20:

6.1 Descriptive graphics

Click on Plot, now selecting Distribution as the plot type. Mark Normal:

and plot again.

81

82

Chapter 6 Tutorial on Graphics

The options we used for each variable correspond to a time-plot showing its historical behaviour, a correlogram and partial correlogram which reflect its autocorrelation,
and a histogram, with estimated density and the normal distribution for reference to
evaluate the distributional shape. This generates six graphs in total: see Figure 6.1. A
detailed description of the formulae underlying these graphs is given in Chapter 10.
900

CONS

880

860

-5
1960

1970

1980

1990

1960

0
ACF-CONS

5
CONS

10

15

20

0
5
Density
0.2

N(s=13.5)

DCONS

1980

1990

15

20

PACF-DCONS

10
N(s=2.2)

0.1

0.02

850

860

870

880

Figure 6.1

6.2

1970

ACF-DCONS

PACF-CONS

Density
0.04

DCONS

890

900

910

-7.5

-5.0

-2.5

0.0

2.5

5.0

7.5

Descriptive graphics of CONS and DCONS

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.
Create separate Plots
This creates as many graphs as there are series.
Style
Lines
Symbols
Lines and symbols
Index line: plot first series as index
Index line and symbols: plot first series as index
Bars: plot all series as bars
Shading: use shading where this variable is 1, no shading otherwise
First as bar: plot only the first as bar chart
Transformation:

83

6.2 Actual series with optional transformations

Logarithms: natural logs of the series: log(yt )


Growth rates: log(yt yt1 )
First differences: yt = yt yt1
Seasonal growth rates: log(yt yts ), s = 4 for quarterly data, s = 12 for
monthly data,
Seasonal differences: s yt = yt yts
Use log scale: assumes the data are in natural logs and powers up the axis to reflect
the log scale.
We now give an example of a plot that uses recession shading based on INC. Create
DINC as the first difference of INC. Then create a recession variable which is one
when the current and previous change in INC is negative. The Calculator expression is:

Next, starting from a new Data Plot window (closing the existing one first), select CONS
and INC in the Graphics dialog, and press Actual series. Then, right-click on the graph,
choosing Add Graph from the context menu (also see 7.9). This brings up the Graphics
dialog again, now with title Graphics - data.in7 - Add to area 1. Remove CONS and
INC from the selection, and add the just created recession variable. Next, click on All
plot types, select Actual series, and change the style to shading:

Click on Plot, then cancel the Graphics dialog. The shading is done in the next available
color, and a lighter would be better (see 7.7), see Figure 6.2.

CONS
recession

900

INC

875

1955

Figure 6.2

1960

1965

1970

1975

1980

1985

1990

Time-series plot of CONS and INC with recession shading

84

Chapter 6 Tutorial on Graphics

6.3

Multiple series with optional transformations

Match series by
None: no matching is done
Mean & range matched to first series
Second series on right scale
Start = 100
Style: as above
Transformation: as above
Use log scale
You can try to replicate Figure 6.3 (make sure that Shading is changed back to
Line). The first graph shows that graphing INFLAT and OUTPUT together is not very
informative. To maximize the visual correlation between them, we can match the mean
and range of OUTPUT to that of INFLAT, as shown in the middle graph. This has the
same effect of plotting each on their own scale, also see 7.13.
1250

No matching

Mean and range


INFLAT

INFLAT

Output on right scale

OUTPUT

INFLAT

OUTPUT

OUTPUT

1000

5.0

5.0

2.5

2.5

0.0

0.0

750

1200

500
250

1175
0
1960

Figure 6.3

6.4

1980

1960

1980

1960

1980

Time-series plot of INFLAT and OUTPUT: maximizing visual correlation

Scatter plots

The available scatter-plot types are:


Y against X
Y against X, labels along the axes
Scatter plot with regression line
With cubic spline smooth, automatic bandwidth
All scatter plots
The Style, Regression and Smoothing sections allow additional options and combinations.
If you wish to keep the current graph as it is, click on File/New Data Plot Window.
This will rename the current Data Plot window to Data Plot 1 (or the relevant next
sequence number), and open a new Data Plot window. Otherwise OxMetrics will keep
on adding to the existing window.

6.4 Scatter plots

85

If DINC is not yet in your database, create it as the first difference of INC, using
Algebra or the Calculator. Then click on the graph icon and select DCONS as the first
(Y ) and DINC as the second (X) variable, then on All plot types >, Scatter plots/Add
regression line, expanding the Regression section:

Mark With projections, and Reverse regression, as shown in the previous capture. Click
Finish to see the graph, shown in Figure 6.4a (we changed the symbols from the default
plus symbol to a box). It shows the lines of best fit, minimizing vertical squared deviations of points from the line for the normal regression, and horizontal for the reverse
regression. The steeper line corresponds to horizontal minimization: can you see
why? To check, double click on the graph and expand the Regression, Scale sections:

Remove the regression by setting the number of lines to zero. This just leaves
the reverse regression line. Click on Undo to restore the normal regression line, as in
Figure 6.4a below.
Return to the Scatter plot dialog, keep the selection of DCONS as Y and DINC as
X, but now select Add smoothed line. Deselect the regression options, and expand the

86
5.0

Chapter 6 Tutorial on Graphics


5.0

DCONS DINC

2.5

2.5

0.0

0.0

-2.5

-2.5

-5.0

Spline k=12.00

-5.0
-7.5

5.0

DCONS DINC

-5.0

-2.5

DCONS DINC
Spline k=12.00

0.0

2.5

5.0

7.5

-7.5
5.0

Kernel k=12.00

2.5

2.5

0.0

0.0

-2.5

-2.5

-5.0

-5.0

-2.5

DCONS DINC
Spline k=12.00

0.0

2.5

5.0

7.5

5.0

7.5

Kernel k=12.00

-5.0
-7.5

-5.0

-2.5

0.0

Figure 6.4

2.5

5.0

7.5

-7.5

-5.0

-2.5

0.0

2.5

Sophisticated scatter plotting graphs

Smoothing section:

Set the Bandwidth method to Parameters and create the plot as in Figure 6.4b.
The cubic spline is one of two ways of fitting smoothed lines that nevertheless
track the general movements in scatter plots; the other is Kernel smooth so draw
another plot withe both the ernel and spline smooths (Figure 6.4b).
These are actually quite close to a straight line. You can fit a straight line as well
for comparison, or be more enterprising as follows. Click on the scatter plot with both
kernel and spline lines (then shown by the fuzzy outline) and copy it to the clipboard
(two pages icon); next, click outside any graph area ensure that there is no selection,

6.5 Distribution

87

then paste to make a block of four graphs. Note that if an area is selected when pasting,
the paste will be added to the selected graph. Then add a regression line to this graph.
The direct comparison is clear: they are close approximations. And for all their wiggles, both are nearly straight lines. Setting the number of parameters to (say) 3 will
produce a fairly smooth fit.
All scatter plots involving the selected variables, each in a separate graph. If CONS,
INC, INFLAT and OUTPUT are marked, for example, the scatter plots are: CONS
on INC, on INFLAT and on OUTPUT; INC on INFLAT and OUTPUT; and finally
INFLAT on OUTPUT. If there are missing values, these are omitted from the graphs.

6.5

Distribution

Estimated density and histogram, optionally with normal reference


Estimated distribution against normal: a QQ plot
Frequencies and/or cumulative frequencies
QQ plot against Uniform, normal, t, F, or 2 distribution
Box plot

6.5.1

Density estimation: Histogram and density

The histogram is a simple graph: the range of xt is divided into intervals, and the
number of observations in each interval is counted. The height of each bar records the
number of entries in that interval. In OxMetrics, these are divided by the total number
of observations to show the relative frequency (use bar to keep the count). OxMetrics
sets a default number of intervals dependent on the sample size, but this can be changed
by the user by clicking on Smoothing and Use custom bar count to set a different
value.
The bimodal curved line in Figure 6.1 is a smoothed version of the histogram. Because we divided the histogram by T , the heights of the bars add up to unity. Correspondingly, the area underneath the smoothed histogram is unity, and the curve is called
a (non-parametric) density estimate. The familiar bell shape of the normal distribution is added for comparison. It is clear that CONS does not look very normal. DCONS
is much closer to a normal distribution: at least it is symmetric, but could still be too
narrow, or too wide (i.e., have excess kurtosis relative to the normal).
Tip If you want to test for normality, use Data/Descriptive Statistics in PcGive and
select the Normality option. Or regress on a constant in either PcGive or TSP, and
get the residual tests.
6.5.2

Distribution

Start with an empty Data Plot window, and return to Graphics, select CONS and
DCONS, and use the Destribution option, this time marking Distribution, Frequency
and Cumulative frequencies, and Box plot:

88

Chapter 6 Tutorial on Graphics

We obtain eight graphs for CONS and DCONS, as shown in Figure 6.5.

Distribution

40
30
20
10

CONS

900
850
850
CONS

860

870

880

890

900

950

150

850
860
CONS

870

880

890

900

900

100

850

50

10
5
0
-5

910

CONS

850
860
Distribution

-7.5

870

880

890

900
30

DCONS

DCONS

20
10
-5.0
DCONS

-2.5

0.0

2.5

5.0

150

-5.0
DCONS

-2.5

0.0

2.5

5.0

100

50

-5
-5.0

-2.5

Figure 6.5

0.0

2.5

5.0

Further descriptive graphics of CONS and DCONS

Figure 6.5a shows the cumulative distribution of the variable, integrating the estimated density. The result is presented in the form of a QQ plot against the normal
distribution, see 6.7.
If you double click on a graph with a histogram, you can fill the histogram bars in
any desired colour. By default, the inside colour is white, here we made it grey:

89

6.5 Distribution

6.5.3

Frequencies

Figure 6.5b,f are just unscaled histograms, and the cumulative versions (Figure 6.5c,g)
literally add up the total numbers below or inside the current interval (CONS has 159
observations, DCONS 158).
6.5.4

Box plot

A box plot shows the distribution of a variable in a more condensed form. Refer to
Figure 6.6, which shows the total range of a variable and the concentration in a central
region, using the quartiles of the distribution, and the inter-quartile range (IQR).
Box plot of INFLAT
6

points outside range

IQR = 1.5 (Q3 - Q1)

Q3 + IQR
maximum inside (Q1 - IQR, Q3 + IQR)
4

Q3

Third quartile

Q2

Median

Q1

First quartile

minimum inside (Q1 - IQR, Q3 + IQR)


Q1 - IQR

Figure 6.6

Box plot of INFLAT

90

Chapter 6 Tutorial on Graphics

6.6

Time-series: ACF etc.

Autocorrelation function or correlogram


Partial autocorrelation function
Cross-correlation function
Spectral density
Periodogram
Seasonal sub-plot
In a seasonal sub-plot, the data are displayed by season. For example, for quarterly
data, first the quarter 1 data are graphed, then quarter 2, etc. This helps detecting
changing seasonal patterns. Examples are in Figure 6.12.

6.6.1

Autocorrelation function or correlogram

The sample autocorrelation function (ACF), or covariogram, plots the correlations rj


between xt and successive xtj , in Figure 6.1 for j = 1, . . . , 12. Also see 10.3.
The length of the ACF can be set by the user. Since the correlation between xt and
xt is always unity, it is not drawn in the graphs. We see that CONS remains strongly
(positively) correlated with its own lags, even after 12 periods (3 years). This suggests
some form of long memory or non-stationarity. DCONS on the other hand shows little
autocorrelation.
Tip If you want the know the exact values of the ACF, you can use Algebra code
as described in 12.5.2. You can also regress DCONS on a constant in PcGive,
and use Test/Residual autocorrelations and Portmanteau statistic. In TSP use the
BJIDENT command.
The ACF (or covariogram) uses the full sample mean and variance to compute the
autocorrelations. This is the version presented in most textbooks. The correlogram
uses the running mean and variance instead, see 10.5. As argued in Nielsen (2006),
the correlogram provides a better discrimination between stationary and non-stationary
variables.
To plot the correlogram (or the PACF derived from the correlogram), mark Using
correlogram in the dialog. Figure 6.7 compares the two versions.
1.0

ACF-CONS

Correlogram-CONS

0.5

1
ACF-DCONS

Correlogram-DCONS

Figure 6.7

10

15

20

10

15

20

Comparison of correlogram and ACF for CONS and DCONS

91

6.6 Time-series: ACF etc.


6.6.2

Partial autocorrelation function (PACF)

The partial autocorrelation coefficients correct the autocorrelation for the effects of previous lags. So the first partial autocorrelation coefficient equals the first normal autocorrelation coefficient. The sample PACF of CONS shows that after the first, the remaining
partial autocorrelations are close to zero.
6.6.3

Cross-correlation function

The sample cross-correlation function (CCF) graphs the correlation between a series
and the lags of another series. Figure 6.8 shows that the CCF between CONS and
DCONS is different between that of DCONS and CONS.
1

CCF-CONS x DCONS

CCF-DCONS x CONS

Figure 6.8

6.6.4

10

15

Cross-correlogram of CONS and DCONS

Spectrum and periodogram

The periodogram and the spectrum (or more accurately here: spectral density) graph the
series in the frequency domain. The sample periodogram is based on the coefficients
of the Fourier decomposition of the sample autocorrelations (that is, the correlations
{rj } in 6.6.1 between xt and xtj ). Figure 6.9 graphs the periodograms of CONS and
DCONS using a lag length of 20.
Spectral density

Periodogram

CONS

Spectral density

Periodogram

DCONS

CONS

1500

0.3

1000

0.2

500

0.1

DCONS

0.0

0.5

1.0

Figure 6.9

0.0

0.5

1.0

0.0

0.5

1.0

0.0

0.5

1.0

Frequency domain graphics of CONS and DCONS

The sample spectral density is a smoothed (and scaled) function of the periodogram.
It is symmetric between and , and so is only graphed for [0, ]; 1 on the horizontal
axis stands for , 0.5 for 0.5, etc. Peaks at certain frequencies can indicate regular

92

Chapter 6 Tutorial on Graphics

(cyclical or seasonal) behaviour in the series. The spectrum of CONS shows the typical spectral shape (a term introduced by Granger, 1966), which many macroeconomic
variables appear to have: a pronounced peak at the lowest frequencies. Like the correlogram, this indicates that successive values of CONS are strongly correlated. Figure 6.9
shows that spectrum of DCONS is much flatter, indicating a series which is closer to
white noise. More information is in 10.8.
Tip You may wonder how graphs such as Figure 6.8 are made smaller. In this case,
that is done using Graph layout/Aspect ratio (Y scale)/Half size (50%):

6.7

QQ plots

The next graph type to be considered in this chapter concern QQ (quantile-quantile), or


cross-probability, plots:
Quantile plot: against uniform
QQ plot against normal (same mean, variance)
QQ plot with choice of distribution
density

1.00

0.4

distribution

normal
0.75

0.3
0.50

0.2

t(3)

0.1

0.25

t(3)
-5.0

-2.5

0.0

Figure 6.10

2.5

5.0

-5.0

-2.5

normal
0.0

Densities and distributions of normal and t

2.5

5.0

93

6.7 QQ 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, butR 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. Figure 6.10 shows a normal and
a t density together with their cumulative distributions.
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.
Figure 6.11 illustrates for CONS and INC and their differences against the normal
as a reference. The normal QQ plots include a 95% pointwise confidence interval, see
10.11. Clearly, there is a vast range of graphics options to suit your needs.
QQ plot

QQ plot

CONS normal

920

INC normal

900
900
875
880
850
860
850
860
QQ plot

870

880

890

900

910

DCONS normal

870
QQ plot
10

880

890

900

910

920

DINC normal

5
5
0

0
-5

-5
-10
-5.0

-2.5

0.0

2.5

5.0

Figure 6.11

-7.5

-5.0

QQ plots

-2.5

0.0

2.5

5.0

7.5

94

6.8

Chapter 6 Tutorial on Graphics

Two series by a third

The following types of graphs can be created as two series by a third:


Error bars
Error bands
Error fans
High-low
Show Z values
As symbol size: Bubble chart
To illustrate 3-way cross plotting, we use the data on the levels and first differences
of UK log consumption and disposable income from Davidson, Hendry, Srba, and Yeo
(1978) (the data set is supplied with OxMetrics, and will be in the data folder).
Load the DHSY data if you have it. Next, in Algebra (or the Calculator), set
seas=period(); and create DLC and DLY. Activate the Graphics dialog, selecting
LC as first, LY as second, and seas as third variable. Choose as graph type Two series
by a third/Show values:

The result is in panel a of Figure 6.12, with a similar graph for the first differences in
panel b. Note that we also choose to have the labels along the axes, instead of a legend.
In the top-left panel (levels), the fourth (Christmas) quarter is uniformly highest, and
the first lowest; in the lower panel (first differences), the first-quarter points are grouped
far below all other quarters, the second are scattered along the X-axis, and the last two
quarters are bunched together. Thus, plotting reveals distinct patterns in this instance.
The remaining panels show the seasonal sub-plots, which essentially reveal the same
information.
There are more cross-plot options. One is a so-called bubble chart. It consists of
a scatter plot, where the symbols are circles, and the size of the circle indicates a third
dimension (e.g. market share). Return to the data.in7 tutorial data set, and use Algebra

95

8.7

8.8

8.9

9.0

9.1

9.2

0.1
DLC

0.05

LC

44 4
43 3
3
4 4 32 21212 1
1
4 4233
4
423233 2 1
4323324 211 1
4 32 1 1
434 2 1
4 3 223 1
21
44 32 11
3 232 1
1
11
LY

-0.1 -0.05

8.6

8.8

9.0

6.8 Two series by a third

9.3

11

2
24 442442 2424 2 2 2 22
2
2
2 22 24 4 4444444 2
3 3334 43
3
3 3 333 3 33 3333

1 1

11 1 111 1
11 1 1
11 1 1

DLY

-0.050 -0.025 0.000

0.025

0.050

0.075

0.10
9.25
0.05
0.00

9.00

-0.05
8.75
-0.10
LC

Figure 6.12

DLC

DLY

LY

860

CONS
880

900

Cross plotting consumption against income by seasons (DHSY)

870
1250

875

880

885

890
INC

895

900

905

910

CONS seas2

750

1955
1250

1960

1965

1970

1975

1980

1985

1990

1965

1970

1975

1980

1985

1990

CONS seas2

750

1955

1960

Figure 6.13

Bubble chart and error bars

to create seas2 = period()*40 + 40;. Create a Scatter Plot of CONS on INC by


seas2. Select Two series by a third/Bubble chart. Double click on the graph to set the
symbol to a circle. The result is in Figure 6.13a.

96

Chapter 6 Tutorial on Graphics

The final graph of this section illustrates error bars/bands. Select CONS as the first
variable, and seas2 as the second, and choose Two series by a third/Error bars at the
second stage. Note that, when only two variables are selected, the horizontal (X) axis
is automatically set to time. See Figure 6.13b.
Afterwards, the colour and size of the error bars can be changed in the section
related to the error bars, see the capture on the next page. It is also possible to switch
between bars and bands. For example, changing to error fans as shown in Figure 6.13c.

6.9

3-dimensional plots

Surface from scatter: X,Y,Z are vectors


Triangulation from scatter: X,Y,Z are vectors
Surface from table: Z,Y columns match
Surface from table: Z,X columns match
3D points
2D contour from 3D scatter surface

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.
6.9.1

Surface from scatter

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. To
illustrate this, create a new database with 1000 observations. Create a random X and
Y value, uniformly distributed between 3 and 3. Create Z as the independent normal
density (without the normalizing constant):

97

6.9 3-dimensional plots


X = 6 * (ranu() - 0.5);
Y = 6 * (ranu() - 0.5);
Z = exp(-0.5*(X^2+Y^2));
Z1 = X^2 - Y^2;
Z2 = fabs(X) - fabs(Y);

The first five observations for graphing are:


X
Y
Z
.386658 2.74759 0.0109402
1.61961 2.53591 0.509611
.501558
1.1585 0.0975157
2.0472 .54874 0.323749
2.41075 2.90015
0.292631

1.0
Z
0.5

Z
0.5

1.0

Select Y , X and Z in the graphics dialog (in that order), select Triangulation from
scatter. Repeat this, but selecting Surface from scatter. The result can be seen in the
first two panels of Figure 6.14.

0.0
Y

-2.5

0.0
X

-2.5

-2.5

0.0
X

-2.5

0.0
Y

2.5

2.5

0.0
X

-2.5

-2.5

0.0
Y

0.0
X

-2.5

-2.5

0.0
Y

2.5

-2.5

-5

Z1
0

Z2
0.0

2.5

10

2.5

2.5

Figure 6.14

2.5

2.5

2.5

3-dimensional graphs: bivariate normal and saddles

There are a few additional edit actions available for 3-dimensional graphs:
Rotation
The Edit menu has an entry for rotation: left/right (azimuth, keyboard short-cuts
are left-arrow, right-arrow), up/down (elevation, keyboard short-cuts are up-arrow,
down-arrow) and side ways (twist). This can be done from the menu for the currently selected 3-d area, or for all graphs. The keyboard short-cuts only work when
a 3D area is selected.
Palette
The Style entry for the 3D graph on Edit Graphs allows for a choice of palette:

98

Chapter 6 Tutorial on Graphics

For example, Figure 6.10d is shown with a wireframe.


Contour lines
The same page allows for the addition of contour lines to a surface (but not a triangulation).
6.9.2

Surface from table

Tables are harder to work with, because OxMetrics essentially only recognizes vectors,
not matrices (unlike Ox).
Create a new database with only seven observations. Let X be 3, 2, . . . , 3, and
Y the same. The Algebra code then defines Z1 = f (X1 , Y ), Z2 = f (X2 , Y ), etc.:
X = trend() - 4;
Y = X;
Z1 = exp(-0.5*(X[1(1)]^2+Y^2));
Z2 = exp(-0.5*(X[2(1)]^2+Y^2));
Z3 = exp(-0.5*(X[3(1)]^2+Y^2));
Z4 = exp(-0.5*(X[4(1)]^2+Y^2));
Z5 = exp(-0.5*(X[5(1)]^2+Y^2));
Z6 = exp(-0.5*(X[6(1)]^2+Y^2));
Z7 = exp(-0.5*(X[7(1)]^2+Y^2));

Note the indexing of the form year[period], which is explained in 12.3.7. The
dataset looks like:
X
3
2
1
0
1
2
3

Y
3
2
1
0
1
2
3

Z1
Z2
0.00012341 0.00150344
0.00150344
0.0183156
0.00673795
0.082085
0.011109
0.135335
0.00673795
0.082085
0.00150344
0.018315
0.00012341 0.00150344

...
...
...
...
...
...
...
...

Z7
0.00012341
0.00150344
0.00673795
0.011109
0.00673795
0.00150344
0.00012341

Select X, Y, Z1, . . . Z7, and 3-dimensional plots/Surface from table (because of


the symmetry Z,Y columns match and Z,X columns match will give the same result),
to see Figure 6.15a.
The difference in storage can be illustrated by increasing the number of points in
Y , while keeping X fixed. To do this, create a new database with 20 observations.

99

1.0
Z1
0.5

Z1
0.5

1.0

6.10 Conclusions

2.5

0.0
Y

-2.5

-2.5

Figure 6.15

0.0
X

2.5

2.5

0.0
Y

-2.5

-2.5

0.0
X

2.5

3-dimensional graphs from tabular data

Paste X from the previous database, so X is 3, 2, . . . , 3, with missing values for the
remaining observations. Create Y as:
Y = (trend()/20 - 0.5) * 6;

and Z as before. Select X, Y, Z1, . . . Z7, and 3-dimensional plots/Surface from table:
Z,Y columns match to see Figure 6.15b.

6.10

Conclusions

Many different types of plots are available. New ones can be derived by editing or
copying and pasting, as discussed in the next chapter.
For a quick example of the plotting capabilities, open the batch file plots.fl (in
the OxMetrics7\batch folder) and run it.

Chapter 7
Tutorial on Graph Editing
The prologue introduced the basics of using OxMetrics, accessing its menus and dialogs, loading, saving and transforming data, using graphics, including saving, printing and pasting them, and described the Calculator and Algebra. Chapter 6 gave an
overview of the many different types of graphs. Now we consider the facilities for
editing graphs in more detail. Chapter 14 discusses various graphics options more systematically.
If youre not inside OxMetrics at the moment, restart and load the tutorial data set
data.in7/data.bn7.

7.1

Multiple graphs

Create DCONS and DINC as the first differences of CONS and INC, then activate the
Graphics choice on tools which defaults to the Variables options as shown in Chapter 2.
Select CONS and INC, then click Actual series, at which point the graph will appear;
restart the graphics dialog, mark and select CONS and INC again, but now click on the
YX (Scatter plot) button, then Apply; and repeat both of these operations for the pairs
DCONS and DINC, clicking OK after the fourth, to see Figure 7.1. We number the four
graphs from left to right and top to bottom as:
a
c

7.2

b
d

Graphics paper: areas and coordinates

To understand the editing facilities, it is easiest to see the graphics window as a piece
of graphics paper, consisting of 15 000 pixels along the x-axis, and 10 000 along the
y-axis (this is very much higher than the actual screen resolution). The four graphs in
Figure 7.1 all have an area attached to them. By default, these areas are evenly spread
100

101

INC

890

CONS

900

7.2 Graphics paper: areas and coordinates

INC
870 880

900

860

880

860

DCONS

1970

1980

1990

1980

1990

870

880

5.0

1960

DINC

900

910

DINC
0.0

2.5

890
CONS

-2.5

-5.0

-5

1960

Figure 7.1

1970

-7.5

-5.0

-2.5
0.0
DCONS

2.5

5.0

7.5

Descriptive graphics of CONS, INC, DCONS and DINC

out on the paper. An area has pixel coordinates to fix it on the paper, and real world
coordinates to draw variables, axes, etc. inside the area.

An area can be selected with the mouse by clicking on it. Then it is shown selected
(in a fuzzy rectangle), and you can pick it up and move it around on the paper, or

102

Chapter 7 Tutorial on Graph Editing

resize it. Once moved around, the pixel coordinates switch from automatic to manual.
To see this, click on the first area to select it, then move it with the mouse. Next, use
a double click on the area (or use Edit/Edit Graph) to activate the Edit Gaphics dialog
and select the Area Layout page for Area 1.
Expand the Pixel coordinates section, and uncheck Set to reset to the default paper
location. Similarly, it is possible to redefine the world coordinates of the area (e.g.
to zoom in on a part of the graph). This is done by deselecting the Set check box in
the World coordinates section. To apply the new settings to all areas, use the Copy
properties to other areas section on the page.
The Graph Layout entry in the left-hand column gives access to the properties that
apply to the whole graph. For example, there is a drop-down box that allows for changing the area matrix. With four graphs on paper, various ways of layout can be chosen.
Select Box all areas to get the graphs boxed as in Figure 7.1.

7.3

Graphics view

When resizing a Graphics window, the content automatically grows or shrinks accordingly. However the aspect ratio of the graph paper (the size along the x-axis relative
to that along the y-axis) remains constant. To change this, see 14.6.1.

7.4

New Data Plot Window

The default graphics window is called Data Plot. By default, OxMetrics keeps on
adding graphs to this window. If you wish to keep the current window, and start with a
clean piece of paper, use New Data Plot Window on the File menu.
To restart with a clean sheet: close the graphics window; a new one will be opened
automatically when required.

7.5

Copy and paste

The use of the clipboard works at two levels:


an area can be copied into another area, or added to the page;

7.6 About line colour and style

103

a whole page can be copied to another program.


As an example of the first mode, select the last area, and copy it to the clipboard
(two pages icon). To add it to the page, make sure that nothing is selected by clicking
on the page outside any area. Now you can paste the graph which will appear as the
fifth area.
Then select the third area, and paste again. Now the scatter plot of DINC and
DCONS is added to the time plot. Since the axes are automatically adjusted to accomodate the new data, this rather messes up the graph.
The use of the clipboard is also discussed in 14.7.

7.6

About line colour and style

Lines in a graph can have different colours and styles (solid, dotted, dashed, etc.). This
is implemented in two levels:
There is a palette of 16 line types, defining colour, style and symbol type.
Each line is defined through an index in that palette.
So, for example, when a line has type 3, it is drawn in whatever colour and style is
defined for that type. When editing a graph on screen, it is possible to change its line
type (see 7.7). In addition, and separately, the global palette settings can be modified
(7.8).
Line type 0 refers to the background colour (white), and type 1 to the foreground
(normally black). Therefore, the first index used in drawing variables is 2.

7.7

Editing graphs: Graphics properties

By default, all graphs use the automatic selections offered by OxMetrics: these are
usually fine for immediate usage, but are open to many possible amendments depending
on their purpose. We begin with Figure 7.1a. Double click on it to bring up the Edit
Graphics dialog (a single click makes it become the focus, shown by the fuzzy boxed
outline mentioned before). Almost any aspect can be changed in the Edit Graphics
dialog.
Lines are chosen from a set of predefined line types, which define colour, pattern,
width and default symbol type. Model/Preferences/Graphics Setup defines the line
definitions. Here we start by changing the line type to index line (as shown below in
Figure 7.2 on page 106) after double clicking on the first area:

104

Chapter 7 Tutorial on Graph Editing

Next, select the INC x (time) section, and under Regression, Scale, and set the
number of regression line to one (as in 2.4.2), as well as Seq. with projections:

Selecting Area 2 (Figure 7.1b), change the Style:

to a solid box, and alter its size to 100:

7.7 Editing graphs: Graphics properties

105

Click on Regression, and mark 4 lines, and Seq. with projections. This page also
allows for renaming the labels of variables in graphs by clicking on Y or X label, in this
case to income:

For graph c, select X-axis on Edit Graphics, and click Grid, as shown in the next
capture. Repeat for the Y-axis, then close: on the graph, grab the legend and move it
to a more convenient location (click with the mouse and holding the button, drag it to
the place required) as shown. Changing Style alters the line colour or style: we have
done that for DCONS in c to a thicker line as explained in the next section.

106

Chapter 7 Tutorial on Graph Editing

Finally for graph d, mark 20 (sequential) regression lines. The final result is in
Figure 7.2. This is a very different picture from our first figure, and such facilities can
be used to reveal hidden features of data.

CONS

900

INC

900

CONS income

890
880

880

870
860

860
1960

1970

1980

1990

870
5.0

880

890

900

910

DCONS DINC

2.5

0.0
-2.5

-5
DCONS

1960

1970

Figure 7.2

DINC

1980

1990

-5.0
-7.5

-5.0

-2.5

0.0

Edited and amended descriptive graph

2.5

5.0

7.5

7.8 Graphics setup

7.8

107

Graphics setup

There are many default graphics settings that can be generically controlled by the user,
and are persistent between runs of OxMetrics.
Lines (Tools/Graphics Setup):
define the default line attributes;
Layout:
define defaults for margins, boxing and font size;
Axes:
define defaults for axes, grids, axis labels and grids;
Legend style
Histogram
Cross-plot style
Palettes (Tools/Graphics Setup):
for three-dimensional surfaces and error fans;
Display style for color mode:
Line colours, types, symbol style, palettes, etc.
Display style for black, white & gray mode:
Line colours, types, symbol style, palettes, etc.
Click on Model, Preferences, Graphics Setup to bring up the dialog shown below.

The colours, types and thickness of all lines can be set as wished: for example,
much thicker lines are more useful for live demonstrations than printed graphs; some

108

Chapter 7 Tutorial on Graph Editing

colours show much better than others, etc.


Any changes made via Preferences are permanent: they will still apply to subsequent runs of OxMetrics, or when displaying graphs from Ox. If only temporary
changes are needed, or different settings for each graph, these can be implemented
from the Edit Graphics dialog after double clicking on a graph. The operating principles are the same throughout the OxMetrics system, so it is easy to develop a setup as
desired and change it quickly if needed.
All these settings can also be controlled from the OxMetrics batch language. The
easiest modus operandi is perhaps to design the layout using the dialogs shown in this
section. Then use the Write batch command 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. The batch command used to control the graphics
settings is setdraw.

7.9

Adding to and removing from a graph

Close the current graphics windows, and create a scatter plot of INFLAT against OUTPUT. It is possible to add further graphs to this area. The default graphics command
will always create new areas, but the Add Graph command from the Edit menu or the
context menu:

adds to a selected area. You can try this by adding a scatter of INFLAT against INC
to the graph. Similar results can be achieved by copying one area to the clipboard,
selecting another, and pasting into that area.
The simplest way to remove it again is to use Undo. An alternative is to delete the
second scatter. Select Delete From Graph:

mark INFLAT x INC and press Delete.

109

7.10 Drawing

7.10

Drawing

Change the line type of the INFLAT x OUTPUT scatter plot to symbol and line to link
the points. Next, access Draw on the context menu (right click):

Use Draw a Filled Rectangle to highlight the two clusters on the graph. Click on Draw
Symbol/Draw Filled Rectangle the mouse point becomes like a pencil, as indeed
it can now draw a rectangle. Put the mouse down near the top left of the first cluster.
while holding the mouse down, continue the expansion till the cluster of points around
the low OUTPUT equilibrium is highlighted as in Figure 7.3a. Next double click on
the rectangle and a Lines and symbols section will appear:

Use Style to change the colour to 12 (for example).


If you now add another box to highlight the second equilibrium we get the final
graph in as Figure 7.3b.
INFLAT OUTPUT

5.0

2.5

0.0
1165

1170

1175

Figure 7.3

1180

1185

1190

1195

1200

1205

Drawing on an INFLAT/OUTPUT scatter plot

1210

110

7.11

Chapter 7 Tutorial on Graph Editing

Adding text and variables

To add text, proceed as in the previous section: use the edit menu or click with the right
button, and select Add text. The mouse cursor becomes a letter. Now click where you
wish the text to appear. A dialog pops up in which the text is entered:

You may note from the dialog that graphics text can use a LATEX-style of formatting,
more information is given in 14.9.
Another simple way to add text is to start typing a letter, which will become the first
letter in the dialog box. The text will be added at the location of the mouse (but can be
picked up and moved). When adding text just above the graph, it becomes the title.

7.12

Legends

Legends are created for all the variables in each graph, located in the top left corner of
the graph. The legend can be picked up with the mouse and moved around the graph.
They are automatically resized as the graph gets smaller. When the graph is very small
(usually with more than sixteen graphs in one window) the legend is omitted altogether.
Another way of removing the legend is by hiding it. The Legend style section on
the Edit Graphics dialog allows hiding and unhiding the legend:

Legends are transparent by default. In that case, they are drawn below data plots,

111

7.13 Scaling variables

with the exception of shading and separately drawn symbols. Opaque legends, on the
other hand, are drawn on top of everything else.

7.13

Scaling variables

Often it is useful to draw two or more variables in the same graph to allow easy comparison. However, when the variables have widely differing magnitude, all visual information will disappear. For example, graph CONS and OUTPUT (after closing the
existing graph). They appear as two nearly straight lines, one at the top and one at the
bottom of the graph: most visual information is lost.
900

CONS

OUTPUT

matched by means and ranges


880

860
1955

1960

1965

1970

1975

1980

1985

1990

900
OUTPUT

1200

CONS

880

1180

CONS on left scale, OUTPUT on right scale


860
1955

1960

Figure 7.4

1965

1970

1975

1980

1985

1990

CONS and OUTPUT with matching mean and range

Two methods are available to enhance the visual correlation:


scale OUTPUT, adjusting it to the CONS values;
draw them separately, and then put the areas on top of each other. (This can also be
done directly, by choosing Multiple series/ Second series on right scale as graph
style.)
The first method is easiest to implement: select Scaling under CONS x (time), in
Edit Graphics, and set Match by to Means and ranges, as shown below.
CONS is the selected variable, and all other variables (OUTPUT here), will be
adjusted to it. With Means and ranges, the mean of OUTPUT is changed to that of
CONS, then the scale factor is set to give OUTPUT the same minimum and maximum:
OUTPUT =

OUTPUT 233.52
.
1.093

112

Chapter 7 Tutorial on Graph Editing

The second method involves more extensive editing. Add separate graphs of CONS
and OUTPUT (there are three areas now). Both already have the same time axis, but
when put on top of each other, the y axes will clash. Double click on the OUTPUT
graph, and select the X-axis section. Check Hide:

Then expand the Y-axis section, and, under location and (log)scale or dates, set the
Anchor to Maximum. To get the labels and tick marks on the other side, select Labels
above.
Change the line type of OUTPUT to number 3. Figure 7.4b shows the result. Note
that the labels along the y-axis have been rotated using Rotate labels on each y-axis.
To put the areas exactly on top of each other, it is necessary to set the pixel coordinates of the areas.

Chapter 8
Tutorial on Data Input and Output
In this tutorial, we turn to what can be one of the more tedious operations: inputting
new data. Fortunately, OxMetrics can load a wide range of formats to allow for easy
exchange with other programs; and can do so from disk files or by copy and paste.
Table 8.1 summarizes the available options.
Table 8.1 OxMetrics data input/output options

Disk OxMetrics

OxMetrics disk

OxMetrics paper
Paper OxMetrics
OxMetrics clipboard
clipboard OxMetrics

OxMetrics data files (.in7+.bn7)


Excel spreadsheets (.xlsx,.xls)
Comma separated files (.csv)
Text files with load info (.dat)
Text files by observation (.dat)
Gauss data files (.dht/.dat)
Stata data files (.dta)
OxMetrics data files (.in7+.bn7)
Excel spreadsheets (.xlsx,.xls)
Comma separated files (.csv)
Text files with load info (.dat)
Text files by observation (.dat)
Stata data files (.dta)
Print
Directly into database
Using OxMetrics as editor
e.g. from OxMetrics to Excel
or vice versa

8.4.1
8.4.2
8.4.3
8.4.3

8.3
8.3
8.3
8.2.2

8.2.1
8.2.2
8.2.2
p.120

Many other formats can be loaded, after conversion to any of the supported formats at
source.
The order in the tutorials below is somewhat different from the table: first we enter
a small data set into OxMetrics (16 observations from the tutorial data set variables
113

114

Chapter 8 Tutorial on Data Input and Output

CONS and INFLAT, from the first quarter of 1955 up to the last quarter of 1958). Next
we save this in various formats, which we shall reload. After all, we do not want to
spend too much time typing in data.
From now on, we will abbreviate menu selections; e.g., File/Save as/Data (*.in7)
will mean: select the File menu, then select Save as, and then the file type data (*.in7).

8.1

Open Data File and file types

The file type entry on the dialog when using File/Open specifies which types of file
OxMetrics can load:

8.2

From paper to OxMetrics

OxMetrics allows you to type data directly into a database, or to enter the data into a
file, and then load the file. Remember: this is for tutorial practice modern scanners
offer a fast route from paper to disk.
8.2.1

Directly into the database

Start OxMetrics without loading any database yet. One of the available options on the
File menu is New: click on it then select OxMetrics (Data: *.in7):

In the current situation, this brings up the Create a new database dialog to ask you for
the information needed to create the database. Fill in the information as shown in the

8.2 From paper to OxMetrics

115

screen capture: Quarterly frequency, start date 19551, add 6 observations (the database
already has 10:

Press OK to accept the dialog: the empty database appears on screen. It could be
convenient here to maximize the database window.
To add variables to the database, keep the focus on it and click on Edit, New variable
and type Cons; repeat to create Inflat so there are two variables in the database.
Alternatively, double click on the empty grey box at the column head, then enter the
name of the variable to be created in the Variable description dialog:

All the observations of Cons and Inflat are set to missing. (NaN, not a number, is
used internally on computers for the missing value). OxMetrics takes account of this
when determining sample sizes for operations, but just leaves gaps when graphing.
There are three ways of entering a value:
1. double click to get a pop-up editor to enter values:

116

Chapter 8 Tutorial on Data Input and Output

2. type a first digit, and the inline editor for the current field is entered.
3. click to select and single click (or press the Enter key) to get the inline editor:

Type 887 as shown, and press Enter to go to the next field.


Change the next observations to 890, 891, 894, 897, 895, 894, 892, 890, 889, 890,
887, 887, 888, 889, 897. Then for Inflat: 0.46, 0.38, 0.2, 0.2, 0.5, 1.7, 2.3, 2.1,
2.1, 2.0, 1.8, 1.2, 0.7, 0.4, 0.26, 0.57. Repeat this until you have entered all observations, as in:

To document each variable, position the cursor on the variable name and press -, or
double-click on the variable name. To return to the Results window, click on Windows
and select Results: you may wish to minimize the database window first.
Tip After conversion or entering new data, it is useful to do a graphic inspection
which can help to find mistakes. See Figure 8.1 for the two variables created in this
tutorial.
The next important task is to save the database to disk. Losing data can be disastrous, and it is best to save it as soon as possible (and make backup copies!). But before

117

8.2 From paper to OxMetrics

Cons

Inflat

2
895
1
890
0
1955

1956

1957

1958

Figure 8.1

1959

1955

1956

1957

1958

1959

Check of Cons and Inflat

moving to 8.3 to see how to save the results of your efforts, we consider data entry by
another way. We suggest that you read the next section, but there is no need at this stage
to enter the numbers again: you can highlight them in the database and use Edit/copy
to put them on the clipboard, then paste to the results window if you wish: the next
section explains.
8.2.2

Using the clipboard; using OxMetrics as editor

To get data into a human-readable file we need the services of an editor: the Results
window will do that job. First change the 1956(3) value for Cons to a missing value.
To avoid typing the data again, select all observations in the database: put the mouse
down on the first observation of Cons, then, while keeping the left mouse button down,
move to the last observation of Inflat. Or more quickly: select all by starting selection
on the first variable label, finishing on the last. Quicker still: click on the top-left empty
cell. The screen should look like the capture below.

The bottom left of the status bar gives the current selection. The right panel still
gives the data value under the cursor. Click on the copy icon (shown as two pages on
the toolbar) to copy the data to the clipboard.

118

Chapter 8 Tutorial on Data Input and Output

Next, set focus to the Results window, and click on the paste icon, as shown here
with some comment (this capture was made after saving to testobs.dat):

Note that we kept the names, and that the data is ordered by observation (the variables
are in columns), with the assumption of one observation per line.
Note that, while we entered 0.46 in the database, the pasted value is actually .46000000000000002. This no mistake, but a consequence of the finite
precision with which the computer hardware works. Some experimentation of
entering values in the database and pasting into Results, shows that the next
number up is .45999999999999996. So .46000000000000002 is as close to
0.46 as we can get. In general, there are about 15 to 16 significant digits available. However, because internal storage is in binary format, the exact numbers
tend not to be the ones ending in lots of zeros.
Precisely the same copy and paste operations would have worked between Excel
and OxMetrics. Of course it is also possible to copy and paste directly between an
Excel spreadsheet and a OxMetrics database.
See the note regarding copying from Excel on page 120.
Comment can be added to the data by putting double forward slashes (//) at the start
of each comment line. When reading a human-readable data file, OxMetrics skips all
the lines starting with // or a semicolon. Here we commented out the variable names,
and removed all previous text from the Results window.
The next step is to save the contents of the Results window. Type Alt+f and
then a to execute Save as on the File menu using the Text (*.out) file type. Enter
testobs.dat for the filename. If the file already exists you can choose between renaming or overwriting. The human-readable data file has been created. Loading the
created file is considered in 8.4.3, after we have learned how to save the database.

8.3 From OxMetrics to disk

8.3

119

From OxMetrics to disk

With new data entered as in 8.2.1, it is most convenient to save the database in the
OxMetrics format. OxMetrics uses two files for its data storage. The first is an information file, which has the .in7 extension. The second holds the data in binary (not
human-readable) form, and has the .bn7 extension.
Activate the database, currently called something like new08.in7, but not corresponding to a disk file. Select File/Save As/Default (*.in7). Enter test in the Save
File dialog. This results in the disk files test.in7 and test.bn7 being created. The
OxMetrics format preserves data documentation entered in the database, and the file
documentation. These can be modified in a later run of OxMetrics.
For completeness, we also save the data in the Excel spreadsheet format, and in
plain ASCII (text) format. Select File/Save As/Data (*.xlsx); type test in the Save
File dialog, the remainder is the same. This creates test.xlsx.
Next repeat the process for File/Save as/Data (*.dat) creating test.dat. This is a
text file with load information: a line is added for each variable giving the name, sample
period and frequency, very similar to the information that is contained in an .in7 file:
>Cons 1955 1 1958 4 4
887
890
891
894
897
895
894
892
...
This is different from testobs.dat created before: now the data is ordered by
variable.

8.4

From disk to OxMetrics

This section discusses the three main types of file which can be loaded directly into OxMetrics. Consult Chapter 11 for additional information on the file formats and further
examples.
8.4.1

Loading OxMetrics files

This is the simplest way of getting data into OxMetrics. So once you have your data
from another format loaded into OxMetrics, you might wish to save it in the OxMetrics
format, and use that from then onwards. An example was given in the first tutorial,
where we loaded the tutorial data file data.in7/data.bn7. Try loading the test.in7
file which was created earlier.
8.4.2

Loading spreadsheet files

A test file called test.xlsx was created above. To load it in OxMetrics, select
File/Open, and select the file. The spreadsheet is loaded directly into OxMetrics.
This is what test.xlsx looks like in Excel (try to load it if you own a copy), for
the first few observations:

120

Chapter 8 Tutorial on Data Input and Output

Note that the missing value is encoded as #N/A in Excel.


This illustrates what OxMetrics expects when reading a spreadsheet file:
ordered by observation (that is, variables are in columns);
columns with variables are labelled;
there is an unlabelled column with the dates (as a text field), in the form yearperiod,
for example, 19801 (or: 1980Q1 1980P1 1980:1 etc.); Excel dates can be read as
well, see below.
the data form a contiguous sample; non-numeric fields are interpreted as missing
values.
More details are in Chapter 11. However, switching between programs using Windows facilities with copying and pasting is usually the easiest approach to entering data
that already exist in another program, provided that all significant digits are retained.
This is a problem with Excel: for example, when copying an Excel cell with the value
908.212280273437 on to the clipboard, it is put there as 908.2122803, thus losing five
significant digits.
8.4.3

Loading a human-readable (text) file

Two human-readable data files were created in this chapter, one by copying to the results
window, and saving as testobs.dat (ordered by observations), and test.dat at the
end of 8.3 (ordered by variable, with load info).
To load test.dat into OxMetrics, use File/Open/Human readable. After selecting
the correct file (test.dat), we note that the file is loaded automatically as desired (with
the help of the load info that is embedded in the file). View the database or graph the
data to check the results.
Finally, load testobs.dat. This is read with variable names, but there is no sample
information. Activate the database and use Edit/Change Sample to set the frequency to
quarterly and the start date to 19551.

8.5

Adding variables using the clipboard

Often one wishes to lift variables out of other data files, and add them to the current
database. OxMetrics supports this operation through copy and paste. You can select
individual variables from an .in7/.bn7 data set, or add them from a human-readable
file. Once created, the frequency of the database is fixed, but the sample period will be

8.6 Changing the sample period

121

extended automatically if required, or can be extended explicitly as shown in the next


section.
Let us try to append the INC variable from the tutorial data set to our database.
Select File/Open, choose data.in7 on the file open dialog, and press Enter to accept.
Highlight the observations on INC from 1955(1) to 1958(4) only, and then press the
two-pages icon to copy to the clipboard. Now set focus to the test database, put the
cursor on the empty field at 1955(1), next to Inflat, and press the paste icon. This copies
the data, and the new variable gets the name Var3, which is easily changed.
When a whole variable is copied onto the clipboard, the name is also included.
When pasted into a database as a new variable, the name will be used for the new
variable (unless a variable with that name already exists).

8.6

Changing the sample period

8.6.1

Extending the sample period

It is possible to add observations prior to the current sample start, or after the sample
end. Such an operation is required when new data are collected, or ex-ante forecasts
are to be stored for further analysis. When storing forecasts, or pasting data, the sample
end is extended automatically.
Suppose we wish to add a year of data at the beginning of the test data created
in 8.3. Remember that the data in test.in7 (and corresponding test.bn7) have a
sample period of 1955 (1) to 1958 (4). Focus on the database and select Edit/Change
Sample. Fill this in as shown: 4 observations at the start, then press OK to accept:

The same procedure can be used to add observations, but a simpler way is just to
double click beyond the end of the database: the editor pops up, and the database is
automatically extended.
8.6.2

Reset starting date

This was done in 8.4.3: the number of observations remained unchanged, and no data
will be lost or changed.

8.7

Appending data

It is possible to append a database from disk to an open database, using Append Data
File on the context menu in the workspace:

122

Chapter 8 Tutorial on Data Input and Output

Append will only work if the frequencies match. OxMetrics will make additional
adjustments when these are required:
the sample of the open database will be extended to encompass that of the appended
database;
if a variable from the appended database already exists in the open database (remember that this requires the names to be identical, including upper/lower case),
then the existing variable is updated, except where the appended variable has missing values (for those observations the existing variable is not changed).
In this case, a message will warn you about the update: Found duplicate variables
in appended database: existing variables adjusted.
For example:
existing
Cons
887
890
891
894
897

8.8

appended
Cons
880
missing
900
missing
910

resulting
Cons
880
890
900
894
910

Working with daily and weekly data

In 5.3 we gave an introduction to dated data, loading the weekly Dow Jones index. In
this section we illustrate how an undated database can be converted to a dated database.
First we contrast the two methods for dating observations:
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

8.8 Working with daily and weekly data

123

as of type date, in which case the date is displayed, rather than the underlying value.
For example 2005-1-1 (1st January 2005 OxMetrics uses the ISO representation
year-month-day) corresponds to 2453372. To check this, just enter 2005-1-1 as an
observation value in a database: this is automatically translated to 2453372. It is
not necessary to work with these large numbers directly, there are several Algebra
functions to help.
The following criteria must be satisfied for a database to be dated:
1. the first column must be of type Date,
2. the first column holds date values,
3. the optional fractional part of this indicates time as a fraction of 24 hours; e.g.
2453372.75 is 18:00 on 2005-1-1 (2005-1-1T18:00 in ISO notation),
4. the first and last observation must be valid, i.e. cannot be missing.
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).
8.8.1

Using Change Sample to create a daily database

Our next step is to create a database that is dated. We continue with the Cons, Inflat test
database that was constructed, but any will do.
The simplest way is to use the Change Sample command, set a daily frequency with
5 days per week and set the start date to 2005-1-3 (the first Monday in January, as can
be seen from the dialog:

Accepting this inserts a variable called Date as the first column:

This is a variable as any other: it can be renamed, transformed, moved, deleted, etc.
Although some of these will make the database undated again. Double clicking on the

124

Chapter 8 Tutorial on Data Input and Output

Date label, and changing the variable type to Default:

will make the database undated:

Click on Undo to reset the database. Renaming the variable does not make the database
undated, because the name is not really used elsewhere.
8.8.2

Using Algebra to create a daily database

The following Algebra code creates separate variables with the year, month and day:
If we now delete the Date variable, the database becomes undated:

This is the format in which some data sets come. To make it dated, use makedate to
create a date variable:
date = makedate(y, m, d);
Then move the variable to the first position in the database using the Move Up button
in the Algebra editor (or in the Calculator):

8.9 Working with choice variables

125

Finally, double click on the new date variable, and change the type to Date. And
the database is dated again.

8.9

Working with choice variables

A third type of variable is that called Choice, which has text labels attached to values.
Normally the values of such a variable are integers, ranging from zero upwards. Then
each zero has the same label, each one etc. An example would be a country panel,
where we find labels such as UK, USA etc. more informative than 14, 15 (say). Another
example is tick-by-tick data, where it can denote a stock exchange. Within OxMetrics,
there is fairly limited benefit of this variable type. Ox programs, however, can also
access this aspect in the Database class, which can make output more readable.
To illustrate the creation of a choice variable, continue with one of the small test
databases, say test.in7. (It doesnt matter if it is dated or undated.) Add a variable
called Var4 which at first is all missing values. Then set the first third of obesrvations
to zero (select the block, right-click on the selection, choose Edit Value, and set it to
0). Set the second block to one, and the final block to two:

126

Chapter 8 Tutorial on Data Input and Output

Double click on the variable name, and change the type to Choice:

Now add the first label, aaa, in the edit field:

Then press Add to add the next value, label pair. Finally, also add cc:

Now the Var4 variable is displayed with labels instead of numbers. It is still a
numerical variable though, which can be used in modelling as any other variable.

8.9 Working with choice variables

127

Not all file types can preserve the choice labels correctly. For saving you can use
.in7/.bn7, .xlsx or .dta. Other formats will either loose the labels completely, or
are unable to guarantee that the labelvalue association stays intact.
This completes our treatment of data input and output. The remainder of the tutorials will use either data that is provided with OxMetrics, or artificial data created inside
OxMetrics. After that you will have your own data to analyze; we hope that OxMetricss ample facilities allow you to enter, edit, save and document your data easily and
quickly.

Chapter 9
Tutorial on Data Transformation
We briefly described the Calculator and Algebra in Chapter 2. Here we explore the
transformation and data generation possibilities. Along the way, we round off the options in the Model menu by looking at the Tail probabilities dialog.
If you are not inside OxMetrics at the moment, restart and load the tutorial data set
data.in7/data.bn7.

9.1

Calculator

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, from where they can be cut and pasted into an algebra
file for later use if desired. Advanced algebra is discussed in the next section, whereas
Chapter 12 has a more formal description of the language.
Suppose, for example, that you have selected the variable called CONS (we use
the artificial data set again), and then pressed the log button. Then the expression will
read log(CONS). When pressing evaluate (the = sign), the logarithm of CONS will
be computed. Now you have to assign the new variable a name, with LCONS as the
suggestion made by OxMetrics. If you accept this suggestion, LCONS will be added
to the database. If LCONS already exists, OxMetrics will ask whether you wish to
overwrite the existing variable.
If you have ticked the Sub-sample evaluation check box, you can also select a
sample period over which you wish to compute log(CONS). If you create a new variable
in this way, it will be set to the missing value outside the sample. If you overwrite an
existing variable, it will be left untouched outside the sample period.
Examples using the calculator were given in Chapter 2. Some additional examples
follow here.
128

129

9.1 Calculator

First, creating a lag: select CONS, click on lag, specify 4 (to create a four-period
lag) in the lag length dialog, OK to accept, and click on the button with the = symbol at
which point a suggested name (CONS 4) appears in a small window, to accept and the
created variable is added to the database. In general, lags for modelling should not be
created this way, although it can be useful for (e.g.) graphing.
Next, to create a step dummy of the 0-1 variety for the oil crisis: click on dummy,
then enter 1973 3 in the Sample start part (leave the Sample end edit field unchanged,
so the 1 extends to the end of the sample; a capture of the dialog was shown on page 23),
press OK and click on = (or C to clear the expression) and specify the name s1973p3.
Third, a complex example: to create the five-period moving average of CONS:
4

1X
CONSti .
5 i=0
Select CONS in the database, locate movingavg in the function list, double click on
it to see movingavg(CONS, LAG, LEAD). Replace LAG by 4 and LEAD by 0. Click
on =, and specify the name MA40CONS. To create the moving average centred around
the current observation (i.e. using two lags, the current value and two leads), specify
movingavg(CONS, 2, 2). Note that this variable lagged two periods is the same as
MA40CONS.
Other operations are equally simple. To create an Almon polynomial in INC of 2nd
order over eight lags (producing three terms): Click on INC, and then double click on
almon, to get the expression almon(INC, LAG, POWER). Change this to almon(INC,
8, 0) to create the first Almon variable. Call this A0INC. Repeat this to create A1INC
as almon(INC, 8, 1) and A2INC as almon(INC, 8, 2). They are computed using
8
8
X
X
(9 i)j x(t i)/
(9 i)j
i=0

for j = 0, 1, 2,

i=0

and eight initial observations are lost. Graph these to see how collinear they are.
To create the price level from INFLAT as our final example, we need to integrate
(cumulate) INFLAT. This is easily done using the cum or stock function. First highlight
INFLAT, then double click on the cum function to cumulate. Press = to accept the
expression cum(INFLAT), call it P, so that Pt = Pt1 +INFLAT is created (graph it and
see). Another way to create this is selecting INFLAT, but clicking on the stock function
instead. Replace ARVAL (one minus the autoregressive coefficient) by 0, and INIT (the
initial value) by 0. Call this SINFLAT, and check that P and SINFLAT are identical.
If you wanted P equal to 100 in 1970(1), say, when it is 86.28879985, select the same
options but replace the INIT argument of stock with 13.71120015, which will set
P = 100 in 1970(1). Alternatively, return to the Results window where SINFLAT =
stock(INFLAT,0,0); is shown, copy the observation for P in 1970(1) to the clip board
and paste to the Results window, create c=100-86.2887998521328; and SINFLAT =
stock(INFLAT,0,c);, highlight these two algebra statements and press Ctrl+A to
execute.

130

Chapter 9 Tutorial on Data Transformation

9.2

Advanced algebra

9.2.1

Introduction

Algebra allows us to do transformations by typing formulae as described in Chapter 2.


These are then executed by OxMetrics. A wide range of functions is available and
algebra formulae can be saved and reused. In this section we will only give examples;
algebra is documented in Chapter 12.
All the code written by the calculator makes up valid algebra code as just noted.
The algebra editor is activated by selecting Tools/Algebra (Alt+t,a), the short-cut
key Alt+a, or the algebra toolbar button.
Algebra uses database variables as follows: if a left-hand variable is already in the
database it will be overwritten, otherwise it will be created. Variables on the right
must exist, possibly because of preceding lines of algebra code. As noted, algebra is
case-sensitive, meaning that LCONS, LCons and lcons refer to three different variables.
Algebra code is logged to the Results window.
Tip Select a function in the function list or variable in the variable list to paste it into
the editor. This saves typing.
Tip Algebra can also be run directly from the results window: highlight the block of
algebra code, and press Ctrl+A to run the code.
Consider the insample function, which has four arguments: startyear, startperiod,
endyear, endperiod. It returns 1 (or TRUE: everything which is not 0 is TRUE) if the
observation under consideration falls within the sample, otherwise it returns 0 (FALSE).
The conditional assignment works as follows: the conditional statement (the if part)
is followed by a question mark and the then part, which is followed by a colon and
the else part. Read:
i1980p1 = insample(1980, 1, 1980, 1) ? 1 : 0;
as: i1980p1 takes on the value 1 for the observations which are in the specified sample,
and the value 0 for the other observations. Note that exactly the same result can be
obtained by writing i1980p1 = insample(1980, 1, 1980, 1);.
An error message pops up if you make a mistake. The error can be corrected on
returning to the algebra editor.
9.2.2

Database for advanced algebra

Select File/New to create a database with 600 observations, using frequency one.
9.2.3

Statistical distributions

We shall first look at some graphs of densities and corresponding distribution functions.
Most often we work with continuous density functions, and it is assumed that you are
familiar with the basic principles (Volume I of the PcGive books discusses statistical
theory). For example, the standard normal density is defined as:
1 2
1
fx (x) = e 2 x ,
2

9.2 Advanced algebra

131

with (cumulative) distribution function (CDF):


Z x
Fx (x) =
fx (u) du.

This integral cannot be written explicitly for the normal distribution. F is a nondecreasing function and:
Fx () = 0, Fx () = 1.
If X has a continuous distribution, then the expectation of X is:
Z
E [X] =
ufx (u) du.

We write X N(0, 1) to say that the random variable X follows a standard normal
distribution. Three other distributions of interest are the student-t, the F and the 2
distribution:
k/21/2

x2
1
k = 1, 2, . . .
1
+
t(k)
fx = (k/2+1/2)
(k/2)
k
k
F(m, n) fx =

(m/2+n/2)
(m/2)(n/2)

2 (k)

1
(k/2)

fx =


1 k/2
2


m m/2
n

xm/21 1 +

m/2n/2
m
nx

xk/21 ex/2

x > 0,
m, n = 1, . . .
x > 0,
k = 1, 2, . . .

() is the gamma function:


Z
(u) =

xu1 ex dx

for u > 0.

For integer arguments n: (n + 1) = n! = n(n 1)(n 2) 1. Most test statistics in


PcGive or TSP have one of these distributions (but often only approximately or in large
samples).
We compute 600 values from N(0, 1), t(2), 2 (3) and F(3, 2), over a range of 6 to
6, in steps of .02. This is the variable called i in the first line of algebra. The algebra
code is in the file tutdist.alg in the OxMetrics7\algebra folder; the section for
the densities is:
i = (trend() - (NOBS/2)) / (NOBS/12);
normal = densn(i);
chi = (i > 0) ? denschi(i,3);
student = denst(i,2);
F = (i > 0) ? densf(i,3,2);

Run the code from tutdist.alg, and do a scatter plot of each of the four variables
against i, as in Figure 9.1. This shows the four densities.
It is also possible to evaluate the densities directly, instead of using the built-in
functions. Note in the second line that we write -(i^2); -i^2 would be equivalent

132

Chapter 9 Tutorial on Data Transformation

0.4

0.25

normal

0.3

0.20

0.2

0.15

0.1

0.10

chi

0.05
0

100

200

300

400

500

600

student

100

200

300

400

500

600

400

450

500

550

600

0.6

0.3

0.2

0.4

0.1

0.2

100

200

300

400

Figure 9.1

500

600

300

350

Some important densities

to (-i)^2, as the unary minus operator has a higher precedence than power (see Table 12.1 on page 170). The () function is not available in the algebra, but the log ()
is and we use the fact that () = exp(log ()).
normal = exp(-(i^2) / 2) / sqrt(2 * PI);
chi = (i > 0) ? 1 / exp(loggamma(1.5)) * 0.5 ^ 1.5
* i ^ 0.5 * exp(-i / 2);
student = exp(loggamma(1.5) - loggamma(1)) /
(sqrt(2 * PI) * (1 + i^2 / 2) ^ 1.5);
F = (i > 0) ? exp(loggamma(2.5) - loggamma(1.5)
- loggamma(1)) * 1.5 ^ 1.5 * i ^ 0.5
/ (1 + 1.5 * i) ^ 2.5;

To translate the densities into approximate CDFs, the following code is used in
tutdist.alg to cumulate and scale the outcomes (which are in increasing order given
our choice of i for the densities):
cnormal = cum(normal) / (NOBS/12);
cchi = cum(chi) / (NOBS/12);
cstudent = cum(student) / (NOBS/12);
cF = cum(F) / (NOBS/12);

We have actually performed a numerical integration of the densities! At each point


we computed the height of the function, and added these up. Since the width of each
bar is only 1/50, we have to divide by 50 (the surface of a bar equals height width).
The CDFs are graphed in Figure 9.2.
It can be noted from Figure 9.1 that the F(3, 2) distribution does not have a finite
variance: it approaches 1 very slowly. The same holds for the t(2) distribution.

133

9.2 Advanced algebra


1.0

cnormal
cstudent

normal

cchi
cF

t(2)
F(3,2)
2(3)

0.5

50

100

150

Figure 9.2

200

250

300

350

400

450

500

550

600

Cumulative distribution functions from 600 points

The approximate 75% critical values as read from the database are:
N(0, 1) .66
t(2)
.86
2 (3)
4.1
F(3, 2) 3.16
The accuracy turns out to be quite good. If we compute the p-values using Tools/Tail
probability we find:
N(0,1,1-sided)
t(2,1-sided)
Chi^2(3)
F(3, 2)

=
=
=
=

0.66
0.86
4.1
3.16

[0.2546]
[0.2402]
[0.2509]
[0.2496]

This dialog gives P (X > x) when 2-sided is not marked, in which case we would
ideally get p-values of 25%.
9.2.4

Random number generators

The random number generators in OxMetrics can be used to illustrate statistical concepts, and to give examples of a wide range of commonly used processes. The main
generators are for the uniform distribution (all other distributions can be derived from
this), and the standard normal distribution. In addition, OxMetrics provides functions
to draw from the t, 2 , and F distributions. Other distributions could be derived if desired. An alternative way to draw from a 2 (k), for example, is to compute the sum of k
squared standard normals. Doornik (2006) discusses recent aspects of random number
generation.
The following experiments use 10 000 observations, but you could keep on using
the database with 600 observations. Otherwise create a new database with 10 thousand
annual observations. Draw from the N(0, 1), t(100), 2 (3), and F(3, 100) distributions,
and compute the probabilities (using the correct distributions) to get a value less than
the observed numbers:
phi
stu
chi
fdi

=
=
=
=

rann();
rant(100);
ranchi(3);
ranf(3, 100);

134

Chapter 9 Tutorial on Data Transformation

1.0

1.0

p_phi phi

0.5

0.5

-3
1.0

p_chi chi

-2

-1

p_stu stu

0.5

0
1.0

10

15

20

0.5
p_fdi fdi

-2

Figure 9.3

p_phi
p_stu
p_chi
p_fdi

=
=
=
=

1
1
1
1

Cumulative distribution functions

tailn(phi);
tailt(stu, 100);
tailchi(chi, 3);
tailf(fdi, 3, 100);

The algebra code is in the file tutran1.alg. When using 10 000 observations, the
computations may take a little while.
Using these data, we can draw the cumulative distribution functions, see Figure 9.3,
and compare with Figure 9.2. In this case we used a t and F distribution with finite
variance. You could try the distributions of 9.2.3: there will be some large outliers,
extending the scale of the graphs.
A check of the random number generators can be based on the probabilities. Sort
each vector of probabilities, and corresponding random numbers with it:
_sortby(p_phi,
_sortby(p_stu,
_sortby(p_chi,
_sortby(p_fdi,

phi);
stu);
chi);
fdi);

Figure 9.4 shows that the probabilities form a straight line. A plot of the sorted random
numbers look like a mirror image of Figure 9.3. Alternatively, graph the histogram and
densities of phi, stu, chi and fdi to see sample analogues of the distributions.
1.0

p_phi
p_chi

p_stu
p_fdi

20

0.5

phi
chi

stu
fdi

1450

2900

10

0
0

1450

2900

4350

5800

7250

8700

Figure 9.4

Check on CDFs

4350

5800

7250

8700

135

9.2 Advanced algebra


9.2.5

Generating data

Finally, we shall generate data on various autoregressive and related processes. The
database is assumed to consist of 600 annual observations, as in 9.2.3. The file
tutran2.alg contains the algebra code used in this section.
Consider the following examples (note that the roots in the MA(2) process are
0.87 and 0.23):
white noise
AR(1)
AR(2)
MA(2)
ARMA(2, 2)
ARCH

5.0

t N(0, 1),
yt = 0.6yt1 + t ,
yt = 0.4yt1 0.7yt2 + t ,
yt = t + 1.1t1 + 0.2t2 ,
yt = 1.4yt1 0.5yt2 + t 0.2t1 0.1t2 ,
2
yt = t t , t2 = 1 + 0.6yt1
.

eps

ar1

2.5
0

0.0
-2.5
0
5

100

200

300

400

500

600

0
5

ar2

100

200

300

400

500

600

200

300

400

500

600

200

300

400

500

600

ma2

-5
0
10

100

200

300

400

500

600

arma22

arch

10

5
0

100

-5

-10
0

100

200

300

400

Figure 9.5

500

600

100

Time series graphs of 6 processes

The middle four processes are used as examples in Priestley (1981). For the
ARCH (autoregressive conditional heteroscedasticity) process, see, for example, Harvey (1993). The following algebra code generates a sample from the six processes:
ranseed(-1);
eps = rann();
ar1 = year() >= 3 ? .6 * lag(ar1,1) + eps : 0;
ar2 = year() >= 3 ? .4 * lag(ar2,1) - .7*lag(ar2,2) + eps : 0;
ma2 = eps + 1.1 * lag(eps,1) + .2 * lag(eps,2);
arma22 = year() >= 3 ? -1.4 * lag(arma22,1)
- .5 * lag(arma22,2) + eps
- .2 * lag(eps,1) - .1 * lag(eps,2) : 0;
arch = year() >= 3 ? sqrt(1 + 0.6 * lag(arch,1)^2) * eps : 0;

136

Chapter 9 Tutorial on Data Transformation

The ranseed() function sets the seed of the random number generator, an argument of 1 resets the seed to the default value. The variable eps is N(0, 1) and is
reused in each process. The autoregressive parts use conditional statements. If the
year is 3 (we use annual data, so this corresponds to an observation index 3), the
part following the ? is executed. For the first two observations the value zero is used.
In this way a variable can be integrated safely (without the conditional statement all
observations would have the missing value). The test year() >= 3 could also be written as insample(3,1,600,1) or lag(eps,2) != MISSING. Try to understand and
compare these alternatives.
Figure 9.5 graphs the results, after adjusting the axes to give the same vertical range.
The correlograms and spectral densities are given in Figure 9.6.
1

ACF-eps

0
1

10

20

0
1

ACF-ma2

0
0.2

10
Spectral density

20

eps

0.50

0.4

10

20

0
1

ACF-arma22

1.0

ma2

0.0
1.0

10
Spectral density

20

ar1

0.50

0.0

0.5

1.0

Figure 9.6

0.0

20

10
Spectral density

20

ar2

0.25
0.5
Spectral density

1.0

arma22

0.0
0.2

0.5

0.2

10
ACF-arch

0.25
0.5
Spectral density

ACF-ar2

0.1
0.0

ACF-ar1

0.5
Spectral density

1.0

arch

0.1
0.5

1.0

0.0

0.5

1.0

Correlograms and spectral densities of six processes

The remaining examples correspond to the equation:


yt = + yt1 + t + t ,

t N(0, 1),

using parameter values:


z1: = 0, = 1, = 0
m1: = .1, = 1, = 0
t1: = .1, = 1, = .001

z2: = 0, = .9, = 0
m2: = .1, = .9, = 0
t2: = .1, = .9, = .001

z3: = 0, = .5, = 0
m3: = .1, = .5, = 0
t3: = .1, = .5, = .001

The algebra code uses the eps variable created above.


z1
z2
z3
m1

=
=
=
=

year()
year()
year()
year()

>=
>=
>=
>=

3
3
3
3

? 1 * lag(z1,1) + eps
? .9 * lag(z2,1) + eps
? .5 * lag(z3,1) + eps
? .1 + 1 * lag(m1,1) +

: 0;
: 0;
: 0;
eps : 0;

137

9.2 Advanced algebra


m2
m3
t1
t2
t3
10

=
=
=
=
=

year()
year()
year()
year()
year()

>=
>=
>=
>=
>=

3
3
3
3
3

?
?
?
?
?

z1

.1
.1
.1
.1
.1

+.9 * lag(m2,1) + eps : 0;


+.5 * lag(m3,1) + eps : 0;
+.001*trend() + 1*lag(t1,1) + eps : 0;
+.001*trend() +.9*lag(t2,1) + eps : 0;
+.001*trend() +.5*lag(t3,1) + eps : 0;
5.0

z2

0
0

0.0

-10
-5

-2.5

-20
0
40

200

400

600

200

400

600

0
5

m2

200

400

600

200

400

600

200

400

600

m3

5
0

20

-5

0
0
200

m1

z3

2.5

200

400

600

t1

0
10

200

400

600

t2

0
5

t3

5
100

0
0
0

200

400

600

Figure 9.7

200

400

600

AR(1) with various parameter values

Figure 9.7 clearly shows the impact of the different parameter values on the behaviour
of the functions.
9.2.6

Smoothing data

As our last tutorial example, we show how the natural cubic spline function can be used
to fit missing values. Load the tutorial data set DATA.IN7.
First edit the CONS variable to set the observations for the years 1958, 1968 and
1978 to missing values (for each year: select the four observations, press Enter, set to
Missing value, press Enter again, and apply to the whole selection). Afterwards, make
sure that you do not save this modified database. An alternative way to set the missing
values is to run the following algebra code:
CONS = insample(1958,1,1958,4) || insample(1968,1,1968,4)
|| insample(1978,1,1978,4) ? MISSING;

Select the Scatter plot graphics dialog, and do a cross plot of CONS against time
(so there is no need to choose an X variable), adding a Cubic spline smooth using all
three bandwidth settings. The results should be similar to Figure 9.8. The label of
the spline line gives the equivalent number of parameters (comparable to the number of
variables used in a linear regression). So we see that a bandwidth of 1600 corresponds to
nearly 10 parameters (it also corresponds to the HodrickPrescott filter, see 10.10.2),

138

Chapter 9 Tutorial on Data Transformation

whereas automatic bandwidth selection is much less smooth, with an equivalence to 47


parameters.
900

880
CONS

sp1CONS (k=12.00)

860
1955

1960

1965

1970

1975

1980

1985

1990

1970

1975

1980

1985

1990

1970

1975

1980

1985

1990

900

880
CONS

sp2CONS (k=-1600)

860
1955

1960

1965

900

880
CONS

sp3CONS (automatic)

860
1955

1960

Figure 9.8

1965

Splines with various bandwidth settings

The following algebra code creates the three smooths in the database (see 12.5.4):
sp1CONS = smooth_sp(CONS,
12, sp1CONS);
sp2CONS = smooth_sp(CONS, -1600, sp2CONS);
sp3CONS = smooth_sp(CONS,
0, sp3CONS);

The first line sets the bandwidth implicitly by specifying an equivalent number of parameters (12), the next sets the bandwidth directly to 1600, and the last uses automatic
bandwidth selection. You could try to add the appropriate variable to each graph by selecting the area (left mouse button), and then using Add Variable. When done correctly,
each added variable should exactly cover the pre-existing spline.
To add the shading, first create the shading variable:
shading = CONS == MISSING;

Then add this variable to each graph, changing the line type to shading, and removing
the Y label so that it doesnt show in the legend.

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 :
x
=

sample mean

1
T

PT

x2 = T1

sample variance

t=1

T
X

xt ,
2

(xt x
) ,

(10.1)

t=1

sample standard deviation


x .
Note that an alternative definition of the variance would divide by T 1 instead of T .1
1
sample variance (OLS)
x2 = T
1
sample standard error

T
X
t=1

(xt x
) ,

(10.2)

x .

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).

141

142

10.3

Chapter 10 OxMetrics Statistics

Autocorrelation function (ACF) or covariogram

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


b
cj =

T
1 X
(xt x
) (xtj x
) ,
T t=j+1

j = 0, . . . , T 1,

(10.3)

PT
x2 corresponds to b
c0 , see
using the full sample mean x
= T1 t=1 xt . The variance
(10.1).
The sample autocorrelation function (ACF) is the series {brj } where brj is the sample
correlation coefficient between xt and xtj . The length of the correlogram is specified
by the user, leading to a figure which shows (br1 ,br2 , . . . ,brs ) plotted against (1, 2, . . . , s)
where for any j when x is any chosen variable:
brj = b
cj /b
c0 ,

j = 0, . . . , T 1.

(10.4)

The first autocorrelation, {br0 }, 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
xtj are missing are omitted from the summation in (10.3). Consequently, the same
procedure is used in (10.4) and any other derived functions such as the spectrum and
periodogram.

10.4

Partial autocorrelation function (PACF)

Given the sample autocorrelation function {brj } the partial autocorrelations are computed using Durbins method as described in Golub and Van Loan (1989, 4.7.2). This
corresponds to recursively solving the YuleWalker equations. For example, with autocorrelations, br0 ,br1 ,br2 , . . ., the first partial correlation is
b0 = 1 (omitted from the
graphs). The second,
b1 , is the solution from


br0
br1


=

br0 br1
br1 br0



b0
1


,

et cetera.

10.5

Correlogram

The sample correlogram plots the series {rj } where rj is the correlation coefficient
between xt and xtj . The length of the correlogram is specified by the user, leading to

10.6 Cross-correlation function (CCF)

143

a figure which shows (r1 ,r2 , . . . ,rs ) plotted against (1, 2, . . . , s) where for any j when
x is any chosen variable:
PT
0 ) (xtj x
j )
t=j+1 (xt x
rj = qP
.
(10.5)
T
2 PT
2
0 )
j )
t=j+1 (xt x
t=j+1 (xtj x
Here x
0 =
PT
1

1
T j

PT

t=j+1

xt is the sample mean of xt , t = j + 1, . . . , T , and x


j =

rj corresponds to a correlation
t=j+1 xtj is the sample mean of xtj , so that
T j
coefficient proper.
Note the difference with the definition of the sample autocorrelations {rj } in (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 :
PT
) (ytj y)
bcxy
j
t=j+1 (xt x
xy
brj = PT
=
, j = 0, . . . , T 1,
(10.6)
PT
1/2
x
) t=1 (yt y)
(bc0 b
cy0 )
t=1 (xt x
using the full sample means x
and y.
The CCF between xt and yt is different from that between yt and xt : brjxy 6= brjyx .
Both are plotted in the same graph.

10.7

Periodogram

The periodogram is defined as:


p ()

=
=

1 PT 1
1 PT 1
ij
= 2
c|j| cos (j)
j=T +1
2 j=T +1 c|j| e
P
c0 T 1
2 j=T +1 r|j| cos (j) ,

(10.7)

for = 0, 2/T, 4/T, . . . , (int(T /2)2)/T.


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.

144

Chapter 10 OxMetrics Statistics

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


{brj }, defined as in (10.4). The sample spectral density is then defined as:
s () =

1
2

T
1
X

0 ,

K (j)br|j| cos (j) ,

(10.8)

j=(T 1)

where || takes the absolute value, so that, for example, br|1| = br1 . The K () function
is called the lag window. OxMetrics uses the Parzen window:
j
j 3

j 2
0.5,
,
K (j) = 1 6 m
+ 6 m
j 3
m

j
(10.9)
= 2 1 m ,
0.5 m
j
1.0,


= 0,
m > 1.
We have that K(j) = K(j), so that the sign of j does not matter (cos(x) = cos(x)).
The brj s 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:
T

1 X
K
f\
x (x) =
T h t=1

x xt
h


,

(10.10)

10.10 Regression lines and smooths

145

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

K (z) dz = 1.

OxMetrics sets:
h = 1.06
x /T 0.2
as a default, and uses the standard normal density for K ():

K

x xt
h

"
2 #

1
x

x
t
= exp 12
.
h
2

(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.
f[
x (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 f[
x (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
b and b in
b t,
ybt =
b + x

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
line 2
line 3

ybt =
b1 + b1 xt ,
ybt =
b2 + b2 xt ,
ybt =
b3 + b3 xt ,

t = 1, . . . T /3,
t = T /3 + 1, . . . , 2T /3,
t = 2T /3 + 1, . . . , T ,

recursive

line 1
line 2
line 3

ybt =
b1 + b1 xt ,
ybt =
b4 + b4 xt ,
b t,
ybt =
b + x

t = 1, . . . T /3,
t = 1, . . . , 2T /3,
t = 1, . . . , T .

Some examples were given in Chapter 7. The regression line is fitted over the whole
sample, skipping over missing values inside sample.

146
10.10.1

Chapter 10 OxMetrics Statistics


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 yb(x0 ) we locate the interval on which x0 falls, and use the
mean of y in that interval as yb. 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
!1 X

 !

T
T
X
x xt
x xt
K
yt ,
(10.12)
K
ybh (x) =
h
h
t=1
t=1
where, as for (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) = 43 1 u2 , |u| 1,
(10.13)
= 0,
|u| > 1,
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 /T 0.2 .
The function ybh () is computed at 128 points. As h 0, ybh () 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 yb () function is evaluated at the T data points xt
(which is time in the absence of x). Hardle (1990) is a general reference on the subject
of non-parametric regression.
There are three ways of specifying the bandwidth:
Number of parameters
This specifies the equivalent number of parameters (approximately comparable to
the number of regressors used in a linear regression). The default is

1/2
3 (T 1)
T 0.2 .
4
12
Set
Sets the bandwidth directly.
Automatic
Chooses the bandwidth by generalized cross validation (GCV). We find that choosing bandwidth using GCV or cross validation (CV) tends to undersmooth.
Equation (10.14) below indicates how GCV is computed.

147

10.10 Regression lines and smooths

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:
Z b
T
X
2

2
+
[g 00 (x)] dx.
min
yt g x[t]
a

t=1

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:

HodrickPrescott
spline

diagonal
6 + 1
6 + 2/3

2nd diag
4
4 + 1/6

3rd diag

remainder
0
0

The only difference is in this Toeplitz matrix. Since the HodrickPrescott filter uses
= 1600 (for quarterly data), the smoothers from both methods are virtually identical.2
There are three ways of specifying the bandwidth:
2

Some articles describe computation of the HodrickPrescott 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).

148

Chapter 10 OxMetrics Statistics

Number of parameters
This specifies the equivalent number of parameters, ke , (approximately comparable
to the number of regressors used in a linear regression). The default is

1/2
3 (T 1)
T 0.2 .
4
12
Set
Sets the bandwidth directly, with the default of 1600 corresponding to the Hodrick
Prescott filter for quarterly data (see 12.5.4.1 for other frequencies).
Automatic
Chooses the bandwidth by generalized cross validation (GCV). We find that choosing bandwidth using GCV or cross validation (CV) tends to undersmooth. The GCV
criterion is computed as:


RSS
.
(10.14)
GCV () = T
T 1.25ke + 0.5
We have adopted GCV instead of CV because a very good fit at one point could
dominate the CV criterion.

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:
2 (df1 ),
F(df1 , df2 ),
N(0, 1),
t(df1 ),
Uniform(0, 1), resulting in a Quantile plot.
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:


(z)(1 (z))
2

z
/2

1
,
T 1
(z)2
where z denotes the coordinates of the reference distribution (the standard normal),
is the standard normal cdf, and the density.

149

10.12 Box plot

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:
a box, with horizontal lines at Q1 , Q2 (the median) and Q3 ;
a vertical line from Q1 IQR to Q3 + IQR (omitted inside the box);
individual observations: all observations outside the (Q1 IQR, Q3 +IQR) range,
plus the two observations on either end which just fall inside this range.
For an example see Figure 6.6 on page 89. 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 ) mt1 , t = 2, . . . , T,
(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 Holts
method:
mt = yt + (1 ) (mt1 + bt1 ) ,
bt = (mt mt1 ) + (1 ) bt1 .
In this case m1 = y1 , m2 = y2 , b2 = y2 y1 ; when = 0 the EWMA (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:
t1

mt = (1 )

m1 +

t1
X

(1 ) yts .

s=0

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)
1/2

[pt (x, x)pt (y, y)]

t = 3, . . . , T

150

Chapter 10 OxMetrics Statistics

where
pt (x, y) =

t1
X

s xts yts ,

t = 1, . . . , T,

s=0

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
OxMetrics file formats
11.1

OxMetrics data files (.in7/.bn7)

The most convenient way of storing data on disk when using OxMetrics is the combination of the information (.in7) and binary (.bn7) data file.
The information file, with the .in7 extension, holds the information about the data
set. The information file is accompanied by a binary data file. The binary data file holds
the actual data, and has the .bn7 extension. The .in7/.bn7 combination is convenient
because information on sample size etc. is automatically stored.
Loading of very large .in7/.bn7 files is significantly faster than loading .xlsx or
.csv files.
Note OxMetrics uses the same format as PcGive versions 7 and 8. (The difference is
that spaces are allowed in variable names, and the introduction of date and choice
variables.)
11.1.1

The .in7 file format

The .in7 file is a text file that stores the metadata. As an example, see Table 11.1,
which lists the data.in7 file.
Table 11.1

data.in7: information file of artificial data set

pcgive 700
data data.bn7
;Tutorial Data Set:4 equation model with oil shock for PcGive
;October 1985
>CONS
1953 1 1992 3 4 32 data
10-04-1992 13:20:38.33
; Artificial consumption variable
>INC
1953 1 1992 3 4 1336 data 10-04-1992 13:20:38.33
; Artificial income variable
>INFLAT 1953 1 1992 3 4 2640 data 10-04-1992 13:20:38.33
; Artificial inflation variable
>OUTPUT 1953 1 1992 3 4 3944 data 10-04-1992 13:20:38.33
; Artificial output variable

151

152

Chapter 11 OxMetrics file formats

The following items are found in the .in7 file:


Identification The first line must be the file identification followed by a version number. Currently the identification is pcgive and the version is 700. This will change
if new features are added to the format.
Data file name The second line specifies the type of file (data), and gives the name
of the data file corresponding to the information file. Here it is a binary file, called
data.bn7. The .bn7 extension indicates that this file is a binary file. If the specified
file has the .dat extension, it is assumed to be an ASCII (that is, human-readable)
file, ordered by variable, see 11.1.4.
When xxx.in7 is used, and if xxx.bn7 exists in the same directory, the data statement
is ignored. Else, the data part must specify the .bn7 file. This behaviour was
introduced with version 1.0 of OxMetrics, and allows renaming a .in7/.bn7 pair
without having to edit the .in7 file.
Comment Lines starting with a semicolon are comment lines, so the third line in the
example is a comment line. All comment lines following the data statement are
considered to document the whole file; those following a variable belong to the
variable.
Variable definition The remaining entries are variable definitions. The first character
(> or -) indicates the status and is described below.
All lines starting with a semicolon that follow a variable definition are comments
on the variable. This documentation can be edited in the database window by selecting the variable name. When saving the database in the OxMetrics format, the
documentation is preserved.
There is one line defining each variable, which holds the following information:
>CONS

1953 1 1992 3
4
32

sample period
frequency address
name, preceded by status: active (>) or deleted (-)

data

group

10-04-1992 13:20

date & time

type

Status If the status is a minus sign, the variable is deleted (but physically still present).
A deleted variable will not be loaded into OxMetrics.
Variable name Maximum length is 64 characters. The variable name is enclosed in
double quotes if it has a space, but leading and trailing spaces, as well as double
quotes in the name are removed. So a name like CONSINC, which would not be a
valid variable name in any programming language, is allowed.
Generation The generation is not explicitly stored in the information file, but derived
from the variable name. If there is more than one entry with an identical name (also
written in identical case, since Cons and CONS are different), then the first one has
generation 0, the second generation 1, etc. Only the highest generation (most recent
version) will be loaded into OxMetrics.
Sample period The sample period consists of four numbers: startyear, startperiod,
endyear and endperiod. Each variable in the data file can have a different sample
period. When reading such a file into OxMetrics with a still empty database, the
sample containing all data will be used (missing observations will get the missing

11.1 OxMetrics data files (.in7/.bn7)

153

value).
Frequency Variables with different frequencies can be stored, but only one frequency
at a time can be loaded into OxMetrics (although several databases can be open
simultaneously with different frequencies).
Address Gives the physical address of the variable in the binary data file. So the first
observation of CONS starts at byte 32 in data.bn7, the second at byte 40 etc. (data
is stored in double precision, taking eight bytes per observation). The 32 bytes preceding every variable are a separate information block, from which a rudimentary
information file can be reconstructed. If necessary, this is a 64-bit integer.
Group Variables in a file can be grouped together by the group name. No spaces are
allowed in the group name.
Date and time fields These give the date and time at which the variable was written.
No spaces are allowed in either field.
Variable type The optional entry after the date and time fields gives the variable type:
(empty) By default the type field is empty, indicating a normal numerical variable.
date Indicates that this is a variable of type Date.
choice[#] Signals a choice variable. The # is an integer that specifies the number
of labels. The next line enumerates the labels, starting with |, and also using |
as a separator. The choice list can be written over multiple lines, but each line
must start with a |. As a consequence, the | character should not be used in the
choice label.
11.1.2

The .bn7 file format

The .bn7 file is a binary file, and thus not human readable. It holds the actual data.
Each variable starts with a 32 bit signature, followed by the data in the form of 8
byte doubles. The doubles have the standard IEEE form and are stored in little endian
format (the default on PC platforms).
The 32 bit signature consists of:
bytes
0-7
8-11
12-23
24-25
26-27
28-29
30-31

C type
double
int
char[12]
short int
short int
short int
short int

description
marker (double: 9999E99)
number of observations (T )
variable name (truncated or padded with null characters)
frequency
starting period
starting year
not used

This signature is followed by 8 T bytes. The signature is always written, but never
read, because all the relevant information is obtained from the .in7 file, including the
starting address of each variable. Note that int is a 32-bit signed integer, and short int a
16-bit signed integer.
Missing values are encoded as a IEEE defined NaN (not a number); 9999.99 is
not recognized as missing (but was used for this purpose in early versions of PC-GIVE).

154
11.1.3

Chapter 11 OxMetrics file formats


Limitations

The amount of data in the .in7/.bn7 files is limited by available disk space, and, more
strictly, by available memory. In a 32-bit operating system, the maximum database size
is about 22 8 2.68 108 elements, equivalent to 2 Gigabyte of memory space. For
a 64-bit operating system, the maximum number of observations in a variable is 23 1
2.1 109 . This is usually much more than can be loaded at one time in OxMetrics. C
source code and object files to read .in7/.bn7 files are available on request. Ox can
read and write .in7/.bn7 on all computer platforms.
11.1.4

The information and ASCII data files (.in7/.dat)

An information file may describe a human-readable data file which is ordered by variable. This option is especially useful for the situation where OxMetrics is routinely
used to process output generated by another program which cannot write binary data
files. When saving data, OxMetrics will always create a binary data file with accompanying information file. To attach a human-readable file to an information file, the
filename following the data statement in the .in7 file should have the .dat extension
(and the .bn7 file must not exist, otherwise that file is read instead). In the example of
Table 11.1 the second line would read data data.dat. Then OxMetrics will assume
that the data is stored in the human-readable (ASCII) data file data.dat. The data
must be ordered by variable, and offending words are treated as missing values (see
11.3). Apart from the data statement, the organization of the .in7 file is the same as
in 11.1. The value in the address field will be ignored, the date and time field may be
missing.

11.2

Spreadsheet files (.xlsx,.csv)

OxMetrics can read and write the following spreadsheet files:


Excel: .xlsx files (.xlsm can also be loaded);
This is the Excel 2007 (or newer) workbook file (Office Open xml).
text-based: .csv (comma separated).
OxMetrics can also read and write the following obsolete spreadsheet files:1
Excel: .xls files;
Lotus: .wks, .wk1 files.
11.2.1 .xlsx files
OxMetrics can read an .xlsx file provided the following conventions are adopted:
Ordered by observation (that is, variables are in columns).
The data form a contiguous sample.
The data are on the first sheet.
1

Support for .wks and .wk1 files will be dropped in OxMetrics 8; .xls files are under consideration for removal with OxMetrics 9.

11.2 Spreadsheet files (.xlsx,.csv)

155

The data matrix is a rectangular array, structured in one of the following formats:
1. Unlabelled first column with dates, followed by labelled columns, one for each
variable.
The first column either consists of proper calendar dates, or strings that represent
a date. In the latter case, it should be of the form yearperiod, where the can
be any single character: for example, 19801 (or: 1980Q1 1980P1 1980:1 etc.;
this character is ignored).
If the date column can be read as fixed frequency dating of observations, the
sample will be set appropriately, and the date column will not appear as a variable.
If the first column cannot be interpreted as defining a fixed-frequency database,
the column will be loaded with default variable name Svar1.
2. All columns are labelled.
An attempt will be made to read the first column as the dates. Regardless of the
result, the column will appear as a variable in the database.
If string-based dates were used, the date variable is of type choice. Otherwise it
will be of type date, in which case the database will appear as dated.
3. No column is labelled.
This is the same as if all columns are labelled with Svar1, Svar2, ....
If no dates are present, the database will have a fixed frequency of unity, starting
from year 1.
If these conventions are not adopted the file can still be read, but you might have
to provide some additional information, such as frequency, start date and row of first
observation. In the example, these are respectively 4, 1980 1, 2.
Variable types are determined automatically:
1. If a variable contains text fields, it will be interpreted as a choice variable. The
ordering of the choice labels is determined from the comment field, see the example
below.
If there is no comment field, numbers will be assigned consecutively to unique text
fields. This means that these observations with be assigned an integer value that is
not yet used in the variable. Identical text fields will have the same integer value.
Fields that have no label associated show their value, while missing values are
shown with a dot.
When saving as .xlsx, the choice labels are saved to the comment field of the
variable name.
2. A variable with dates will become a date variable. A date variable will interpret all
observations as dates.
3. Otherwise, the variable has only numerical values (the default).
You can use #N/A, #NA, .NaN, ., missing or leave gaps for missing observations
in the input spreadsheet file. When saving as a spreadsheet file, missing values are
written as #N/A.

156

Chapter 11 OxMetrics file formats

For example, the format for writing is (this is also the optimal format for reading):
A
1
2
3
4
5
6

1980(1)
1980(2)
1980(3)
1980(4)
1981(1)

B
CONS
883
884
885
889
900

C
INFL
2.7
3.5
3.9
2.6
3.4

D
DUM
3
5
1
9
2

We shall give some examples to show what happens with slightly different files. The
spreadsheet displayed on the left was created in Excel, and then subsequently loaded
into OxMetrics, with the result displayed on the right.
In the first example the first column has dates, rather than text. There is also text
in the third variable. OxMetrics detects that the dates correspond to a fixed frequency
sequence (monthly in this case), and sets the sample correctly. Text fields are assigned
unused integers, starting from zero, in the order they are found (separately for each
variable). So text gets value 0, and abcd value 3.
A
1
2
3
4
5
5

Jan-80
Feb-80
Mar-80
Apr-80
May-80

B
aap
1
2.3
9
4.125
1

C
D
noot mies
#N/A
1
12.436
2
13.786 text
9.456 abcd
#N/A #N/A

OxMetrics database
aap
noot
1980( 1)
1 missing
1980( 2)
2.3
12.436
1980( 3)
9
13.786
1980( 4) 4.125
9.456
1980( 5)
1 missing

mies
1
2
text
abcd
.

While this method of reading text works, it doesnt guarantee that the labels always
appear in a user-defined order (so that text always corresponds to value 0). When
saving this database from OxMetrics as .xlsx file, the choice labels are saved in the
comment field of the variable. The description of the variable created in OxMetrics is
also preserved there. Using Choice Variable for the description and saving, the file
appears as follows in Excel:

In the second example the dates are valid, but column labels (that is, variable names)
are missing. Also note that any non-numeric fields are converted to missing values.

11.2 Spreadsheet files (.xlsx,.csv)

1
2
3
4

A
1980(1)
1981(1)
1982(1)
1983(1)

B
1
2.3
9
4.125

C
missing
13.786
9.456

D
1
2
3
4

1980
1981
1982
1983

157

OxMetrics database
Svar1 Svar2 Svar3 Svar4
1980(1)
1 missing
1
1981(1)
2.3 missing
2
1982(1)
9 13.786
3
1983(1) 4.125 9.456
4

Finally, both dates and column labels are missing:


1
2
3
4

A
1
2.3
9
4.125

B
#N/A
12.436
13.786
9.456

C
1
2
3
4

1-1
2-1
3-1
4-1

OxMetrics database
Svar1
Svar2 Svar3
1 missing
1
2.3
12.436
2
9
13.786
3
4.125
9.456
4

11.2.2 .csv files


A comma-separated values file stores the spreadsheet in a human-readable text file
with .csv extension. OxMetrics closely follows RFC 4180 (see the documentation
at tools.ietf.org/html/rfc4180):
1. Each line represents a row of the spreadsheet, and all lines must have the same
number of elements. OxMetrics allows \r, \r\n, or \n as end-of-line markers.
2. Each field is separated by a comma.
3. A field may be enclosed in double quotes (quoted, e.g. 1.25) or not (unquoted,
e.g. 1.25). A field with multiple lines, comma or double quotes must be quoted.
An embedded double quote is written as two consecutive double quotes. Spaces are
considered part of a field, but spaces after a quoted field are skipped.
The following rules apply to the fields:
1. A numerical value must be unquoted and written with a period as the fractional
separator.
2. The following unquoted fields are interpreted:
missing values infinities
.
+.Inf
.NaN
.Inf
#N/A
-.Inf
#NA
missing
An empty field is also treated as a missing value.
3. Dates are recognized, provided they are unquoted and follow the same ISO standard
as Ox.
4. A quoted field is interpreted as a text field.
These rules identify the spreadsheet, from which variable and sample information is
extracted along the lines described in 11.2.1. The only difference is that an unlabelled

158

Chapter 11 OxMetrics file formats

first column, with other columns labelled, is loaded if it contains numerical data (even
when recoginized as defining a fixed frequency).
When reading, variables with non-numerical fields are converted to a choice variable, with the text as choice label. A choice variable is not properly preserved in the
saved csv file: the label is written, but the numerical value is reconstructed from the
order when loading. This may not correspond to the original order.
11.2.3

Interpreted and uninterpreted .xlsx and .csv files

OxMetrics can use spreadsheet files for econometric modelling, because it imposes
structure on the spreadsheet to define variables, their names, and the sample period.
Dates are mapped to OxMetrics dates. Text fields, apart from variable names or date
labels in the first column, are interpreted as labels for specific values, defining a choice
variable. Because the underlying value of a choice is still numerical, it can be used to
select an estimation sample by, create dummy variables, or use in a regression.
Another benefit of the adopted handling of choice variables is that they can be easily
manipulated in Ox using the Database class. Database::GetVarChoices gets the list
of choices as an array, while Database::GetObsLabel gets the label of an observation
on a variable.
The Ox loadsheet function can be used to read an entire spreadsheet (.xlsx or
.csv) into an array, without the interpretation that OxMetrics and Ox apply by default.
The Ox loadmat function can be used to read an entire numerical spreadsheet
(.xlsx or .csv) into a matrix, either with or without the interpretation that OxMetrics and Ox apply to dates and strings. Without the interpretation all the strings are
treated as missing values, and variables that only have missing values are dropped.
11.2.4 .xls files
OxMetrics can read the following types of Excel files:
.xls: Excel 5.0, 95, 97, 2000, XP, 2003, 2007 workbooks.
.xls: Excel 2.1, 3.0, 4.0 worksheets;
Workbooks are compound files, and only the first sheet in the file is read.
When reading, variables with non-numerical fields are converted to a choice variable, with the text as choice label. A choice variable is not properly preserved in the
saved csv file: the label is written, but the numerical value is reconstructed from the
order when loading. This may not correspond to the original order.
When saving a database as an .xls Excel file, it is written as an Excel 2.1 worksheet. The maximum size of spreadsheet files is 65 536 rows by 256 columns, and
a warning is given if that maximum is exceeded (OxMetrics can handle much larger
datasets). OxMetrics does not enforce the maximum number of columns, allowing up
to 65 536 instead; rows and columns in excess of 65 536 are not written. There are no
such restrictions with Office Open XML .xlsx files.

11.3 Data by observation (.dat)

11.3

159

Data by observation (.dat)

As the name suggests, a human-readable (or text) data file is a file that can be read using
a file viewer or editor. (A binary file cannot be read in this way.) Initial input of data
to OxMetrics is often in this form, and then saved in the OxMetrics format (see 11.1).
The default extension is .dat.
In this format, there is no information on sample size nor on data frequency. There
may be information on variable names at the beginning of the file. The data set will be
loaded as undated, which can be changed subsequently inside the program.
Each variable must have the same number of observations. Variables that have too
short a sample have to be padded by missing values. Text following ; or // up to the
end of the line is considered to be comment, and skipped. Data files must be ordered
by observation (first observation on all variables, second observation on all variables,
etc.) with one observation per line. The file may start with listing the variable names.
Examples are:
//by observation
891 2.8 //1953 (1)
883 2.7 //1953 (2)
884 3.5 // etc.
891 2.8
885 3.9
. 2.6
891 2.8

//with names
Cons Inflat
891 2.8 //1953 (1)
883 2.7 //1953 (2)
884 3.5 // etc.
891 2.8
885 3.9
889 2.6

Missing values can be represented by a dot or .NaN.

11.4

Data with load info (.dat)

This data type can be read without intervention, unlike data by observation, which is
unstructured. An example is:
>CONS 1953 1 1954 1 4
890.449584960938
.
884.884704589844
885.254089355469

886.328796386719

>INC 1953 1 1954 1 4


908.212280273438
898.481506347656

899.795288085938

900.678527832031
895.776916503906

The variable description starts with a >, followed by the variable name (no spaces
are allowed), the sample and finally the frequency. This is similar to the description in
the .in7 file. The description is followed by the actual data (so the data are always
ordered by variable here). As before, text following ; or // up to the end of the line is
considered to be comment, and skipped.
When loading a .dat file, OxMetrics will first see if it is a Gauss data file. If not,
it will try to read it as a data file with load information. Finally, it will try a data file by
observation.

160

11.5

Chapter 11 OxMetrics file formats

Gauss data file (.dht/.dat)

The .dht/.dat combination is a format written by Gauss. The .dht part is a binary
file which specifies the size of the data. The .dat file holds the actual data in binary
form. OxMetrics can read both 16 and 32 bit .dht files (called small data set v89 and
extended data set v89), but only reads the .dat file if it holds 8 or 4 byte doubles. Any
complex part of the data is ignored. There is no sample information in the .dht file,
the frequency will be set to one, and the first observation will be at year 1. This can
be changed after loading the data, see 8.6.2.
OxMetrics can write a 32-bit .dht/.dat file, but dates, choice labels, variable comments, database comment and sample information is lost.

11.6

Stata data file (.dta)

The .dta file is a format written by Stata. OxMetrics can read files written by Stata
versions 46 as well as those defined as formats 113 to 115. There is no sample information read from the .dta file, so the frequency will be set to one, and the first
observation will be at year 1. This can be changed after loading the data, see 8.6.2.
OxMetrics can write a .dta file as a format-114 file, but dates, database comment
and sample information is lost. Choice labels and variable comments are preserved.

11.7

Results file (.out)

The contents of text windows are written to the results file, using the default extension
.OUT when saving the window content to disk.

11.8

Batch file (.fl)

The batch file stores a set of batch commands, and has the .FL extension. It is a normal
text file. The batch language is explained in Chapter 13.

11.9

Algebra file (.alg)

An algebra file holds the algebra code, and will normally have the .ALG extension. It
is a text file and can be edited. The algebra syntax is explained in Chapter 12.

11.10

Ox file (.ox)

Is used to store Ox programs (Doornik, 2013). When loaded in OxMetrics, with the
Windows version of Ox installed, the file can be run by clicking on the Run button on
the toolbar, or using the Modules/Run Default Module command (Ctrl+r).

11.11 TSP file (.tsp)

11.11

161

TSP file (.tsp)

Is used to store TSP programs. When loaded in OxMetrics, with the OxMetrics compatible version of TSP installed, the file can be run by clicking on the Run button on the
toolbar, or using the Modules/Run Default Module command (Ctrl+r).

11.12

Matrix file (.mat)

A matrix file holds a matrix in human readable form. The actual matrix contents is
preceded by two integers which specify the matrix dimensions (number of rows and
columns). A matrix file normally has the .mat extension. Lines starting with ; or // are
treated as comments. An example of a matrix file is:
2 3
//comment
1 0 0
0 1 .5

11.13

//<-//<-//<-//<--

dimensions, a 2 by 3 matrix
a line of comment
first row of the matrix
second row of the matrix

OxMetrics graphics file (.gwg)

This is the only graphics storage which can be read back into OxMetrics. The file
is text, but direct editing will rarely be necessary because all graphics objects can be
manipulated on screen. Figure 11.1 corresponds to the following .gwg file:
OxMetrics 11 1 1
paper(15000,7500)
box(1,640)
mode(1,0)
xvec(0,2,2)
{
"CONS" 8
< 890.4495849609375
885.2540893554688
>
"" 0
1953.75 0.25;
freq:4;
symbol:1 4 160;
}
xvec(0,3,3)
{
"INC" 8
< 908.2122802734375
895.7769165039063
>
"" 0
1953.75 0.25;
freq:4;
symbol:0 1 90;
}
axis(0,1)

886.5430297851563 886.3287963867188 884.8847045898438


884.528076171875 884.4362182617188 884.3106079101563

900.6785278320313 899.7952880859375 898.4815063476563


894.830810546875 892.7406005859375 892.7684936523438

162

Chapter 11 OxMetrics file formats

{
x;
anchor2: 0;
label:300 1000 60;
grid:0 8 1;
set:0 1 0 0 0 0 0;
rot:0;
}
axis(0,1)
{
y;
anchor2: 0;
label:300 1000 60;
grid:0 8 1;
set:0 1 0 0 0 0 0;
rot:0;
}
area(0,0)
{
}
legend(0,1)
{
365 46 0;
set:300 1 2 1;
}
line(0,11,11)
{
wset:1954.502949852507 884.0768348623853 1954.99133480826
905.3899082568807 0;
}
text(0,1)
{
9128 5619 10$$\theta_i$;
set:0 390 0;
wset: 1955.03558259587 904.0137614678901;
}

CONS

INC

905

900

895

890

885
1954

1955

Figure 11.1

A simple graph

1956

11.14 PDF file (.pdf)

11.14

163

PDF file (.pdf)

A PDF file is a (partially) compressed binary file which can be handled by many PDF
compatible programs.

11.15

PostScript file (.eps)

A PostScript file is an ASCII file which can be printed on any PostScript compatible printer, or on other printers using GhostScript. GhostScript (and its companion,
GhostView for viewing files) can be obtained from the internet.
Direct printing can be achieved simply by copying the file to the PostScript printer.
However, since the file is Encapsulated PostScript (EPS), it will not be centred on the
page. Most popular word-processors can load EPS files.
Figure 11.1 corresponds to the following .EPS file (part of the actual graph is deleted
from the listing):
%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 432 216
%%Creator: Ox (C) J.A. Doornik, 1994-2006.
%%Pages: 0
%%EndComments
%functions deleted ...
%lines
/Linetype0 [ ] def /Linewidth0 10 def
/Linetype1 [ ] def /Linewidth1 6 def
/Linetype2 [ ] def /Linewidth2 10 def
/Linetype3 [50 20] def /Linewidth3 10 def
/Linetype4 [ ] def /Linewidth4 10 def
/Linetype5 [35 35] def /Linewidth5 10 def
/Linetype6 [35 35] def /Linewidth6 20 def
/Linetype7 [35 35] def /Linewidth7 30 def
/Linetype8 [160 80] def /Linewidth8 10 def
/Linetype9 [160 80] def /Linewidth9 20 def
/Linetype10 [160 80] def /Linewidth10 30 def
/Linetype11 [ ] def /Linewidth11 20 def
/Linetype12 [ ] def /Linewidth12 30 def
/Linetype13 [ ] def /Linewidth13 50 def
/Linetype14 [ ] def /Linewidth14 10 def
/Linetype15 [ ] def /Linewidth15 10 def
%fonts
/F0 /Times-Roman ISOLatin1
/F1 /Symbol findfont definefont pop
/F2 /Times-Bold ISOLatin1
/F3 /Times-Italic ISOLatin1
/F4 /Times-BoldItalic ISOLatin1
/F5 /Helvetica ISOLatin1
/F6 /Courier ISOLatin1
/F7 /Times-Roman ISOLatin1
/F8 /Times-Roman ISOLatin1
/F9 /Times-Roman ISOLatin1

164

Chapter 11 OxMetrics file formats

%colors
/BWG 16 array def
/Gray 16 array def
/RGB 16 array def
% first set all to black
0 1 15 { dup Gray exch 0 put RGB exch [0 0 0] put } for
% color 0: white
% color 1: black
BWG 0 0.00 put
BWG 1 0.00 put
BWG 2 0.00 put
BWG 3 0.00 put
BWG 4 0.00 put
BWG 5 0.00 put
BWG 6 0.00 put
BWG 7 0.00 put
BWG 8 0.20 put
BWG 9 0.95 put
BWG 10 0.79 put
BWG 11 0.85 put
BWG 12 0.70 put
BWG 13 0.25 put
BWG 14 0.50 put
BWG 15 0.75 put

<-- background colour


<-- foreground colour
Gray 0 1.00 put RGB
Gray 1 0.00 put RGB
Gray 2 0.30 put RGB
Gray 3 0.11 put RGB
Gray 4 0.35 put RGB
Gray 5 0.41 put RGB
Gray 6 0.44 put RGB
Gray 7 0.45 put RGB
Gray 8 0.21 put RGB
Gray 9 0.95 put RGB
Gray 10 0.80 put RGB
Gray 11 0.85 put RGB
Gray 12 0.70 put RGB
Gray 13 0.25 put RGB
Gray 14 0.50 put RGB
Gray 15 0.75 put RGB

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

[1.00
[0.00
[1.00
[0.00
[0.00
[1.00
[0.00
[0.50
[0.50
[1.00
[0.50
[0.50
[0.00
[0.25
[0.50
[0.75

1.00
0.00
0.00
0.00
0.50
0.00
0.75
0.50
0.00
1.00
1.00
1.00
1.00
0.25
0.50
0.75

1.00]
0.00]
0.00]
1.00]
0.50]
1.00]
0.00]
0.00]
0.50]
0.50]
0.50]
1.00]
1.00]
0.25]
0.50]
0.75]

put
put
put
put
put
put
put
put
put
put
put
put
put
put
put
put

%choose a ColorModel: 0=black/white; 1=black/white/gray; 2=gray; 3=color


/ColorModel 1 def
% /SetColor and /FillColor deleted ...
%init
save
1 setlinejoin
280 /F0 Font
10 setlinewidth
/Ltp Linetype1 def
/Lwd Linewidth1 def
/User { /ptX 0 def /ptY 0 def} def
%.PS uses full page printing
% select papersize: A4, Letter, User (in points: 72/inch)
% select orientation: 0 portrait mode, 1 landscape
% full page printing for .PS, else use EpsPage
%.EPS defers scaling/rotation to document
EpsPage
%A4 /Landscape 1 def

FullPage

%Graph start
% rest deleted ...
%Graph end
restore
showpage
%%EOF

Sometimes minor changes need be made after saving the file, e.g.:
Changing colour model.

11.16 PostScript file (.ps)

165

0 Black and white


All non-white colours are translated to black.
1 Black, white, gray
Colour 0 is white, colours 18 are black, the remainder are translated to a grey
value. One additional change to the line types is made: if line 2 and 3 are both
solid, line 3 is changed to a dotted line.
2 Gray levels
Colour 0 is white, colours 1 is black, the remainder are translated to a grey value.
3 Color
Will result in a colour graph on a colour printer, else the result will be translated
to grey levels inside the printer.
The statement /ColorModel 1 def sets the colour model.
The PostScript mode command on Edit Graph/Graph layout allows choosing a
colour model to be used when saving the file.
Changing line types. For example, to make line two twice as thick, and dashed,
change
/Linetype2 [ ] def /Linewidth2 15 def
to
/Linetype2 [40 40] def /Linewidth2 20 def
The [40 40] defines the pattern: 40 units line, followed by a gap of 40 units. Note
that line type 1 is the black line, used for axes. Line type two is the one used for the
first vector. Line type 0 is usually invisible (white line on white background)
Changing font sizes. Whenever a font is chosen, it is preceded by the font size, as
in:
300 Font0
which selects font 0 (set to Times-Roman) at size 300.
Full page print.
As was pointed out before, when copying the EPS file to the printer, it will not fill
the page. To print the graph in landscape filling a full A4 page, change
EpsPage
%A4 /Landscape 1 def FullPage
to
%EpsPage
A4 /Landscape 1 def FullPage
Change A4 to Letter for letter size, and use /Landscape 0 for portrait mode.
These settings can be controlled in the PostScript Setup dialog. When saving as a
.PS file, the default is full page. When loading the EPS file into a word-processor,
that program will be able to resize the graph to any desired size.

11.16

PostScript file (.ps)

The difference with the .EPS file of the previous section is that the default size is full
page, with settings controlled via the PostScript Setup dialog.

166

11.17

Chapter 11 OxMetrics file formats

Enhanced meta file (.emf)

The Windows metafile format is used for storing the graph as displayed on screen.
Since the graphs are drawn in vector form, the metafile will be a vector graph. EMF
files can be read by many programs, for example Microsoft Word and Scientific Word,
and edited further.

11.18

Windows meta file (.wmf)

The WMF format is an older version of the EMF format.

Chapter 12
Algebra Language
12.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.

12.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.
12.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.
167

168
12.2.2

Chapter 12 Algebra Language


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.
12.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.
12.2.4

Algebra from a Batch file

Algebra code can be specified in a Batch program, see Ch. 13, and specifically 13.5.1.
An Algebra file can also be loaded into a batch file (13.5.14).

12.3
12.3.1

Syntax of Algebra language


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, 1CONS, 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).
12.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.

12.3 Syntax of Algebra language


12.3.3

169

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.
12.3.4
12.3.4.1

Algebra operators
Arithmetic operators

The binary arithmetic operators are ^, *, /, +, -. The ^ is the power operator;


CONS ^2 raises the variable CONS to the power two. All computations are double precision floating point arithmetic. The precedence order is: ^, unary + and unary -, then *,
/, and finally +, -. An example of unary minus is: x = 1. Any arithmetic operation
involving missing values returns a missing value.
12.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
<, <=, >, >=
==
!=
&&, ||
12.3.4.3

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

Algebra operator precedence

Table 12.1 lists the operator precedence, with the highest precedence at the top of the
table.
12.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

170

Chapter 12 Algebra Language

Table 12.1 Algebra operator precedence


Symbol Description
Associativity
^
Power
Left to right
!
+

Logical NOT
Unary minus
Unary plus

Right to left

*
/

Multiply
Divide

Left to right

+
-

Add
Subtract

Left to right

<
<=
>
>=

Less than
Less than or equal to
Greater than
Greater than or equal to

Left to right

==
!=

Equal
Not equal

Left to right

&&

Logical AND

Left to right

||

Logical OR

Left to right

(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.
12.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

12.3 Syntax of Algebra language

171

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.
12.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:


Relative to the current observation.
Each Algebra statement can be seen as running within a loop over all observations.
The relative index is offset to the current observation in the loop. So
CONS_1 = CONS[-1];

can be interpreted as:


for (t = first observation; t <= last observation; t = t + 1)
CONS_1[t] = CONS[t - 1];

Consequently, this statement has the same effect as


CONS_1[0] = CONS[-1];

By absolute date
In this case the index has the form year(period), for example
X = INC + CONS[1980(1)];
y[1955(1)] = 12;

This type of indexing was used in 6.9.2.


By absolute index
In this case the index has the form index(0), which references observation index
(with the first observation having index 0!). For example
X = INC + CONS[0(0)];

12.3.8

// add first CONS value

Keywords

The following keywords are reserved by algebra:

172

Chapter 12 Algebra Language

Table 12.2

Reserved Algebra keywords

keyword
FALSE
TRUE
FREQUENCY
MISSING
PI
NOBS

12.4

value
0.
!FALSE
data frequency
the missing value
Pi (3.1415..)
number of observations

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).

12.5 Algebra Functions

12.5

173

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 12.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

12.5.1

Differencing and lag functions

A variable is lagged using the lag function,1 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.
12.5.2

ACF and periodogram functions

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

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.

174

Chapter 12 Algebra Language

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.
Section 10.7 describes this in more detail.
12.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

12.5 Algebra Functions

175

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 */

12.5.4

Smoothing functions

The smoothing functions which are available in scatter plots can also be accessed from
algebra. Chapter 10 briefly reviews the mathematics underlying the smoothers.
12.5.4.1

HodrickPrescott filter

The HodrickPrescott 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 HodrickPrescott filter is 100(freq)2 :
annual data
quarterly data
monthly data
12.5.4.2

100
1600
14400

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.

176

Chapter 12 Algebra Language

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.
Some examples were given in 9.2.6.
12.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
Holts 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.


12.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 Years 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: Washingtons Birthday */
|| isdayofmonth(5,2,-1)/*last Mon in May: Memorial Day
*/
|| isdayofmonth(9,2,1) /* 1st Mon in Sep: Labor Day
*/

12.6 Algebra function summary


|| isdayofmonth(10,2,2)/* 2nd Mon in Oct: Columbus Day
|| isdayofmonth(11,5,4);/*4th Thu in Nov: Thanksgiving

177
*/
*/

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

12.6

*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/

Algebra function summary

Available functions are listed in Table 12.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

178

Chapter 12 Algebra Language

Table 12.3 Algebra functions


Function
abs(arg)
acf(var,dest,lag)
acos(arg)
almon(var,arg,power)

asin(arg)
atan(arg)
ceil(arg)
cos(arg)
cum(var)
date()
day()
dayofweek()
delete(var,. . . )
denschi(arg)
densf(arg1,arg2)
densn()
denst(arg1)
diff(var,arg)

Returns
absolute value of arg (same as fabs)
autocorrelation function (all arguments must be a variable)
arccosine of arg, or 0 if |arg| > 1
almon lag of var P
P1
1
(c1 + 1 i)c2 xti / ck=0
(c1 +
almon(x, c1 , c2 )= ck=0
1 i)c2
arcsine of arg, or 0 if |arg| > 1
arctangent of arg
ceiling of arg (the smallest integer arg)
cosine of arg
cumulative sum of var
date value (dated database) or the observation index
day (dated database)
day of the week (dated database, 1=Sunday,. . . ,7=Saturday)
delete the list of variables when this Algebra run completes
2 (arg) density
F(arg1, arg2) density
N(0, 1) density
student-t(arg) density
argth difference of var, or the missing value if var is not a
variable, or the difference cannot be taken
returns the result of the (32 bit) integer division
first difference of natural logrithm of var
1 inside the sample yr1 (per1) yr2 (per2), 0 outside it
as dummy for a dated database
see 12.5.4.3, 10.13
see 12.5.4.3, 10.14
exponential function of arg
absolute value of arg
floor of arg (the largest integer arg )
floating point remainder of arg1/arg2

div(arg1,arg2)
dlog(var)
dummy(yr1,per1,yr2,per2)
dummydates(date1,date2)
ewma(var,alpha,beta,dest)
ewmc0(varx,vary,lambda,dest)
exp(arg)
fabs(arg)
floor(arg)
fmod(arg1,arg2)
hours()
indates(date1,date2)
as insample for a dated database
insample(yr1,per1,yr2,per2)
true if inside the sample yr1(per1) to yr2(per2), false outside
isdayofmonth(month,dow,nth) returns 1 for nth day of week in month; dow: 1=Sunday, etc.
nth< 0: from end
iseaster(daysafter)
returns 1 for daysafter easter
lag(var,arg)
argth lag of var, or the missing value if arg1 is not a variable,
or the lag cannot be taken; use arg < 0 for leads
log(var)
natural logarithm of var
log10(var)
base 10 logarithm of var
loggamma(var)
logarithm of the gamma function at var)
makedate(year,month,day)
make date values
maketime(hour,min,sec)
make time values
max(arg1, arg2)
maximum of arg1 and arg2
(Continued on next page)

12.6 Algebra function summary


Function
mean(var)
min(arg1,arg2)
minutes()
month()
movingavg(var,lag,lead)

179

Returns
(Continued)
mean of var
minimum of arg1 and arg2
minutes (dated database)
month (dated database)
the moving average of var
P 2
MAV(x, c1 , c2 ) = t+c
k=tc1 xk /(c2 + c1 + 1)
movingSD(var,lag,lead,mvar) the moving standard deviation of var around mvar
hP
i1/2
(xk zk )2
t+c2
MSD(x, c1 , c2 , z) =
k=tc1 (c2 +c1 +1)

pacf(var,dest,lag)
peak(var)
period()
periodogram(var,dest,freq)
probn(arg1)
quanchi(p,arg)
quanf(p,arg1,arg2)
quann(p)
quant(p,arg1)
ranu()
ranchi(arg)
ranf(arg1,arg2)
rann()
rant(arg1)
ranseed(arg)
round(arg)
season()
seconds()
sin(arg)
smooth hp(var,alpha,dest)
smooth np(var,alpha,dest)
smooth sp(var,alpha,dest)
sort(var)
sortallby(var1)
sortby(var1, var2)
sqrt(arg)
stock(var,arvalue,init)
stockv(var,arvar,init)
tailchi(arg1,arg2)
tailf(arg1,arg2,arg3)
tailn(arg1)
tailt(arg1,arg2)
tan(arg)
time()
trend()
trough(var)
variance(var)
year()

PACF (all arguments must be a variable)


maximum value of var up to current observation
current period
periodogram (all arguments must be a variable)
P(X arg1|X N(0, 1))
2 (arg) quantiles at p
F(arg1, arg2) quantiles at arg1
N(0, 1) quantiles at p
student-t(arg) quantiles at p
uniform random numbers
2 (arg) random numbers
F(arg1, arg2) random numbers
N(0, 1) random numbers
student-t(arg) random numbers
sets the random number seed to arg, returns arg
rounded value of arg
1 in period 1, 0 otherwise
seconds (dated database)
sine of arg
see 12.5.4
see 12.5.4
see 12.5.4
see 12.5.3
see 12.5.3
see 12.5.3
square root of arg
integrates var
stock(x, c1 , c2 ) = (1 c1 )yt1 + xt , given y0 = c2
integrates var
stockv(x, z, c2 ) = (1 zt )yt1 + xt , given y0 = c2
P(X arg1|X 2 (arg2))
P(X arg1|X F(arg2, arg3))
P(X arg1|X N(0, 1))
P(X arg1|X t(arg2))
tangent of arg
time value (dated database)
1 for the first observation, 2 for the second, etc.
minimum value of var up to current observation
variance of var
current year.

Chapter 13
Batch Language
13.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.

13.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.
13.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.
13.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).
180

13.3 Batch files and default folders


13.2.3

181

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.
13.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.
13.2.5

Batch from a Batch file

A batch file can be called from another batch file, see 13.5.15.

13.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.

13.4

General Batch command summary

Table 13.1 gives an alphabetical list of the OxMetrics batch language statements.
13.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.
13.4.2

Command types

There are two types of batch commands:


function calls (with or without arguments) terminated by a semicolon. An example
is the loaddata command.
block commands, which are followed by statements between curly brackets. An
example is the algebra command.

182

Chapter 13 Batch Language

Table 13.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);

13.4.3

Default arguments

Table 13.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", "");

13.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

13.5 Batch commands

183

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 13.1. Module
specific commands are documented with each module (so, for PcGive batch commands
consult Volume I of the PcGive books).
13.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);
}

13.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.
13.5.3 appresults("filename");
Append the contents of the Results window to the named file and clear the Results
window.
13.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.
13.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.
13.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.

184

Chapter 13 Batch Language

13.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).

13.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).

13.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

13.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)

13.5 Batch commands


"f"
"frequency"
"histogram"
"normal"
"pacf"
"periodogram"
"spectrum"
"t"
"uniform"
13.5.11

185

QQ plot against F(d1,d2)


frequency count (for non-standard bars, specify the bar count)
histogram (for non-standard bars, specify the bar count)
QQ plot against normal with same mean and variance
partial autocorrelation function with specified lag length
periodogram
spectral density using specified lag length
QQ plot against student-t(d1)
Quantile plot (QQ against uniform)

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)
13.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"
"contourx"
"contoury"
"points"
"surface"
"surfacex"
"surfacey"
"trisurface"
13.5.13

contour from scattered data; x,y,z are vectors


contour from tabular data; x,y are vectors, z=z(x,y)
contour from tabular data; x,y are vectors, z=z(y,x)
sequence of 3D points
surface from scattered data; x,y,z are vectors
surface from tabular data; x,y are vectors, z=z(x,y)
surface from tabular data; x,y are vectors, z=z(y,x)
triangulated surface from scattered data; x,y,z are vectors

exit;

Stops the batch file and exits OxMetrics.

186

Chapter 13 Batch Language

13.5.14 loadalgebra("filename");
Loads and executes the algebra code from the named .ALG file. The extension must be
provided. See 13.3 on the default folder.
13.5.15 loadbatch("filename");
Loads and executes the batch code from the named .FL file. The extension must be
provided. See 13.3 on the default folder.
13.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).
13.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 13.3 on the default folder.
If the database is already opened, the command works as usedata().
13.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.
13.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.
13.5.20 package("packagename", "modeltype"="");
Used to specify the package and model type for modelling:
package("PcGive", "Single-equation");

13.5.21 print("text");
13.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.

187

13.5 Batch commands


13.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.
13.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!
13.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.
13.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!
13.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
"axis"
"axisline"
"axisformat"
"box"
"bw"
"color"
"colormodel"
"default"
"font"

changes
axis fonts/ticks
axis options
format of labels
box and grid
black&white settings
colour settings
PostScript model
reset default
font

option
"legendfontsize"
"legendhide"
"legendresize"
"line"
"linebw"
"margin"
"palette max"
"palette min"
"papercolor"

changes
legend font size
legend hiding
legend resizing
colour line settings
b&w line settings
paper margins
palette light colour
palette dark colour
Paper colour

"grid"
"histogram"
"legend"

grid style
bar colours
legend style

"printpage"
"symbol"
"xystyle"

PostScript paper
symbol settings
cross-plot style

Use of the default option is as follows:


setdraw("default")
setdraw("default", 0)
setdraw("default", 1)
setdraw("default", 2)

reset all graphics defaults,


reset all graphics defaults,
reset layout, leave line types and colours,
reset line types and colours, leave layout.

188

Chapter 13 Batch Language

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. 14). The default width and precision for axisformat is 8 and 6 respectively.
option
i1
"axis"
fontsize
"axisline"
no X-line:01
"axisformat"
width
"box"
box:01
"bw"
lineno:015
"color"
lineno:015
"colormodel"
model:03
"default"
0,1,2
"font"
fontno:03
"grid"
color:015
"histogram"
inside:015
"legend"
boxed:01
"legendfontsize" fontsize
"legendhide"
hide:01
"legendresize"
resize:01
"line"
lineno:015
"linebw"
lineno:015
"margin"
left
index:07
"palette max"
"palette min"
index:07
"papercolor"
red:0255
"printpage"
orientation:01
"symbol"
lineno:015
"xystyle"
2d along axes:01

linetype
solid
dotted
dashed
long dashes
user defined
symboltype
0 solid box
1 open box
2 plus
3 dash
4 circle

i2
i3
i4
i5
step
tick
no Y-line:01 center dates:01 no small Y:01
precision same precision:01 leading zeros:01
X-grid:01
Y-grid:01
red:0255
green:0255
blue:0255
red:0255
green:0255
blue:0255
fontsize
type:015
outside:015
columns

linetype:04
linetype:04
top
red:0255
red:0255
green:0255
papertype:02
symtype:04
3d along axes:01

papertype
0 A4
1 Letter
2 user defined

5
6
7
8
9

none
line
solid circle
triangle
solid triangle

0
1
2
3

10
11
12

width
width

on
on

green:0255
green:0255
blue:0255
X-size
size

blue:0255
blue:0255

off
off

Y-size

colormodel
black & white
black, white, gray
gray
color

diamond
solid diamond
cross

13.5.28 setdrawwindow("name");
Sets the name of the graphics window in which the graphs appear. The default is
"Batch Graphics".
13.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.

13.6 Examples

189

13.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);

13.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:

190

Chapter 13 Batch Language


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;

13.6 Examples
setdrawwindow("3D surface plots");
drawz(0, "x","y","z", "surface");
drawz(1, "x","y","z", "trisurface");
show;

191

Chapter 14
OxMetrics Graphics
14.1

Graphics paper

Graphs in OxMetrics are drawn on a graphics worksheet, consisting of 10 000 by 15 000


pixels, with (0,0) in the bottom left corner:
(15 000, 10 000)

(700,3200)

(0,0)
These pixels are virtual and different from screen pixels: the paper is always
10 000 15 000, 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:
(15 000, 10 000)
0

(0,0)
192

14.2 Creating graphs

193

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
step 1: select area 2;
step 2: move to (0.0, 0.0);
step 3: draw a line to (1.0,1.0).
2. using pixel coordinates on the worksheet
step 1: move to pixel coordinates (600,600);
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.

14.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.
Examples of the various types of OxMetrics graphs are given in Chapter 6.
14.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.
Create separate Plots
This creates as many graphs as there are series.
Style
Lines
Symbols
Lines and symbols
Index line: plot first series as index
Index line and symbols: plot first series as index
Bars: plot all series as bars
Shading: use shading where this variable is 1, no shading otherwise
First as bar: plot only the first as bar chart
Transformation:
Logarithms: natural logs of the series: log(yt )

194

Chapter 14 OxMetrics Graphics

Growth rates: log(yt yt1 )


First differences: yt = yt yt1
Seasonal growth rates: log(yt yts ), s = 4 for quarterly data, s = 12 for
monthly data,
Seasonal differences: s yt = yt yts
Use log scale: assumes the data are in logs and powers up the axis to reflect the log
scale.
14.2.2

Multiple series with optional transformations

Match series by
None: no matching is done
Mean & range matched to first series
Second series on right scale
Start = 100
Style: as above
Transformation: as above
Use log scale
14.2.3

Scatter plots

The available scatter-plot types are:


Y against X
Y against X, labels along the axes
Scatter plot with regression line
With cubic spline smooth, automatic bandwidth
All scatter plots
The Style, Regression and Smoothing sections allow additional options and combinations.
If there are missing values, these are omitted from the graphs.
14.2.4

Distribution

Estimated density and histogram, optionally with normal reference


The histogram is a simple graph: the range of xt is divided into intervals, and the
number of observations in each interval is counted. The height of each bar records
the number of entries in that interval. In OxMetrics, these are divided by the total
number of observations to show the relative frequency (use bar to keep the count).
OxMetrics sets a default number of intervals dependent on the sample size, but this
can be changed by the user by clicking on Smoothing and Use custom bar count
to set a different value.
Estimated distribution against normal: a QQ plot
Frequencies and/or cumulative frequencies
QQ plot against Uniform, normal, t, F, or 2 distribution
Box plot

14.2 Creating graphs


14.2.5

195

Time-series: ACF etc.

Autocorrelation function
The sample autocorrelation function (ACF), or correlogram, plots the correlations
rj between xt and successive xtj , Also see 10.3. The length of the ACF can be
set by the user. Since the correlation between xt and xt is always unity, it is not
drawn in the graphs.
Partial autocorrelation function
The partial autocorrelation coefficients correct the autocorrelation for the effects of
previous lags. So the first partial autocorrelation coefficient equals the first normal
autocorrelation coefficient.
Cross-correlation function
The sample cross-correlation function (CCF) graphs the correlation between a series
and the lags of another series.
Periodogram
The periodogram and the spectrum (or more accurately here: spectral density) graph
the series in the frequency domain. The sample periodogram is based on the coefficients of the Fourier decomposition of the sample autocorrelations (that is, the
correlations {rj } in 6.6.1 between xt and xtj ).
Spectral density
The sample spectral density is a smoothed (and scaled) function of the periodogram.
It is symmetric between and , and so is only graphed for [0, ]; 1 on the
horizontal axis stands for , 0.5 for 0.5, etc. Peaks at certain frequencies can
indicate regular (cyclical or seasonal) behaviour in the series.
Seasonal sub-plot
In a seasonal sub-plot, the data are displayed by season. For example, for quarterly
data, first the quarter 1 data are graphed, then quarter 2, etc. This helps detecting
changing seasonal patterns.
14.2.6

QQ plots

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


Quantile plot: against uniform
QQ plot against normal (same mean, variance)
QQ plot with choice of distribution
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, butR 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.

196

Chapter 14 OxMetrics Graphics

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.
14.2.7

Error bars
Error bands
Error fans
High-low
Show Z values
As symbol size: Bubble chart
A bubble chart consists of a scatter plot, where the symbols are circles, and the size
of the circle indicates a third dimension (e.g. market share).

14.2.8

Two series by a third

3-dimensional plots

Surface from scatter: X,Y,Z are vectors


Triangulation from scatter: X,Y,Z are vectors
Surface from table: Z,Y columns match
Surface from table: Z,X columns match
3D points
2D contour from 3D scatter surface
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:
Rotation
The Edit menu has an entry for rotation: left/right (azimuth, keyboard short-cuts
are left-arrow, right-arrow), up/down (elevation, keyboard short-cuts are up-arrow,
down-arrow) and side ways (twist). This can be done from the menu for the currently selected 3-d area, or for all graphs. The keyboard short-cuts only work when
a 3D area is selected.
Palette

14.3 Printing graphs

197

The Style entry for the 3D graph on Edit Graphs allows for a choice of palette.
Contour lines
The same page allows for the addition of contour lines to a surface (but not a triangulation).

14.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:
Orientation: portrait or landscape;
Column and scale are ignored, as the graph will fill the page;
Draw a box;
The size of margin to use;
Draw a header for the graph. This is controlled via the Header and Footer boxes.
There are five specials:
&[date] prints the date,
&[time] prints the time,
&[page] prints the page number,
&[pages] prints the total number of pages,
&[file] prints the file name.
Other text in the edit field is printed directly.
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).

14.4

Graphics formats

Graphs can be saved to disk in various formats:


Enhanced metafile (.emf); These can easily be inserted into Microsoft Word 2003
or newer using Insert/Picture/From File.
Encapsulated PostScript (.eps), which is the format used to produce all the graphs
in this book;
OxMetrics Graphics File (.gwg);
PDF (.pdf), this is a popular binary document storage format.
PostScript (.ps), this is like EPS, but defaulting to a full page print.
Portable Network Graphics (.png), which is a bitmap format that may be useful for
insertion in web pages;
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.

198

Chapter 14 OxMetrics Graphics

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.
Graphics file formats are discussed in more detail in 11.1311.17.

14.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.

14.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 14.1.
14.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:
Change the Areas layout, e.g. for example from 2 1 to 1 2.
Box all areas in the current graphics window.
Change the aspect ratio, for example to half-height graphs as used occasionally in
this book.
The aspect ratio of the graph paper defaults to 1.5 (15 000 along the x-axis and
10 000 along the y-axis). This usually works very well, but occasionally it may
need changing, for example to make the graphs square on paper. Half-size graphs
can also look good in publications. Examples are in Figures 6.9 and 6.8.
Change margins.
Adjust all styles to make all lines in all the areas thicker or thinner, or
to Increase all font sizes.
Set the PostScript mode: usually plots on screen are colour, but required in gray
levels for publication purposes.
Display mode can be changed from colour to black & white. Occasionally, this can
be useful when pasting to another application for printing. OxMetrics always starts
in colour mode.

14.6 Editing graphs

199

Paper colour allows the colour to be set for the (normally) white space around the
graphics areas, e.g. to a light grey.
14.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:
change world coordinates: select the desired area and select the Set checkbox for
the X or Y coordinates, then adjust the settings. Press All to apply this to all areas.
reset pixel coordinates to automatic or set specific pixel coordinates.
change layout, e.g. for example from 2 1 to 1 2.
Box the current area, or all areas in the current graphics window.
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:
Rotate left or right (from the keyboard use Alt< or Alt>; this does not require the
shift key, so just hold Alt pressed while typing the < or > key). This canges the
azimuth.
Rotate up or down (from the keyboard use Alt- or Alt+). This canges the elevation.
Twist left or right.
Reset the rotation and twist back to the original values.
14.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:
variable against time;
variable against another variable;
variable against another variable by a third variable. The third variable can indicate
symbol size, have its value printed, or specify error bars.
3D graphs: surface, contour or scatter.
The Lines page of the Graphics Property dialog controls how the vector is displayed.
The line type joining the observations can be:
Line: linked,
Symbols: not linked, but showing symbols,
Line and symbols,

200

Chapter 14 OxMetrics Graphics

Index: this draws a line from the point to the zero axis (if part of the area), or the
edge of the area (towards zero). A non zero base can be specified in the Base for
index/bars edit field.
Index and symbols,
Bars: this draws a bar to the zero axis (if part of the area), or the edge of the area
(towards zero), with the bar centred on the current point. A non zero base can be
specified in the Base for index/bars edit field.
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.
14.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.
14.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):
None removes all scaling.
Means matches the means of all variables to that of the selected variable: the shift
factor will be set to make the means of the variables equal.
Ranges: the scale factor will be set to give all the variables the same range. Maximum minimum will now be the same for every variable. Adjustment is made
relative to the selected variable.
Means and Ranges matches means and ranges. Both the shift and scale factors are
set.
The scale and shift factor can also be set directly.
The regression options in this page are:

14.6 Editing graphs

201

Number of least squares lines.


By default no least squares lines are drawn; you can select up to 40 lines.
Sequential versus Recursive regression lines.
The default is sequential regression: the X-axis is divided in s sections (where s is
the number of regression lines). Each section gets its own regression line. Recursive
regression lines will lead to each subsequent section added on to the previous.
With or without Projections; projections shows the deviation between the variable
and the regression line.
Style sets the line colour and pattern.
14.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.
14.6.4.1

Settings for non-default labelling

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


Minimum and Maximum;
First large tick: the value at which the first large tick mark appears;
Intervals for large ticks: the gap between large tick marks;
Intervals for small ticks: the gap between small tick marks;
These values are all set to a default, but can be changed when Default labelling is
unchecked.
14.6.4.2

Location and transformation

The location and transformation settings further position and define the axis:
Anchor: determines where the axis is anchored, e.g. for an X-axis this is a Y value
(changing the anchor would move the X-axis up or down). Minimum anchors at the
left (bottom) of an area, Maximum at the right (top). Use specified anchor allows
anchoring anywhere in the graph. For 3D graphs, the X axis is anchored at an Y
and Z value, Y at X, Z and Z at X, Y .
Transformation
The Axis type:
Normal the default axis without transformation;
Log (data is in logs) when the data is in natural logarithms, use this to show the
original values on the axis;
Log10 (data is in log10) when the data is in logarithms of base 10, use this to show
the original values on the axis;
Use specified shift and scale allows the shift and scale factors to be set;
Dates when the values on the axis are to be interpreted as date values.

202
14.6.4.3

Chapter 14 OxMetrics Graphics


Style

The following adjustments can be made to an axis (all adjustments apply to the current
axis only):
hide an axis by checking Hide. (Axes can also be deleted, but when an area has no
X or Y axis and is redrawn, that axis will be added.)
No base line removes the line, leaving only tick marks.
No small ticks removes the small tick marks.
Line at y=0 is only for X-axes, and uses the same line colour and type as the grid.
By default a line showing zero is added when both negative and positive data occur.
Grid attaches a grid, perpendicular to the selected axis. The grid is at the large tick
marks. The grid colour and type is set in Graphics Setup, the default is that of line
colour and type 14.
The Tick Size. This sets the small tick size, the large tick size is twice the small tick
size.
The Font Size sets the size of the axis labels.
14.6.4.4

Label style

Labels other side puts the labels on the other side of the axis.
Rotate labels writes text of labels along the Y -axis (Y axis), see e.g. Figure 7.4, or
at a right angle (X-axis).
Centre dates puts the labels in between the tick marks. For example for annual
data, the label 1960 is centred at 1960 by default. With Centre dates it is set half
way between 1960 and 1961. This option is for X axes only. This does not work
when the axis is dated.
Note that you may have as many axes as you wish. Axes can be selected on screen with
the mouse.
14.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:
Hide, legends are never completely deleted.
Auto resize, by default, legends are reduced when the area gets smaller. When the
text gets too small, the legend is hidden.
Boxed draws a box around the legends.
Default box size will be unchecked if the box is resized with the mouse. When it is
checked, the box size is left to OxMetrics.
Columns sets the number of columns for the labels; the default is two.

14.6 Editing graphs

203

Font size determines the size of the label. This is reduced further when Auto resize
is set.
Transparent is the default. In that case, legends are drawn below data plots, with
the exception of shading and separately drawn symbols. Opaque legends, on the
other hand, are drawn on top of everything else.
14.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.
14.6.7

Copy properties to other areas

Some aspects of one area can be copied to all other areas in the graph:
Pixel coordinates: width and height or reset the default;
World coordinates: X or Y;
Axes: labelling, scale tyle or label style;
Legend style;
Histogram style.
14.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 14.9.
14.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.
14.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.
14.6.11

Pointing

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

204
14.6.12

Chapter 14 OxMetrics Graphics


Graphics setup

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

14.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.

14.8

Graphs and sample selection

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

14.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 k+1
i1 . Tables 14.1 to 14.6 list the mathematics symbols which are available in OxMetrics.
The entries in Tables 14.7 to 14.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).

205

14.9 Text formatting

Table 14.1

Greek symbols

\alpha
\beta
\gamma
\delta
\epsilon
\varepsilon
\zeta
\eta

\theta
\vartheta
\iota
\kappa
\lambda
\mu
\nu
\xi

o
\pi
\varpi
\rho
\varrho
\sigma
\varsigma
\tau

\upsilon
\phi
\varphi
\chi
\psi
\omega

\Gamma
\Delta
\Theta

\Lambda
\Xi
\Pi

\Sigma
\Upsilon
\Phi

\Psi
\Omega

Table 14.2

\arrowext
\downarrow
\Downarrow

\Leftarrow
\leftarrow
\Leftrightarrow
\leftrightarrow
\leftarrow\arrowext

\acute a
\bar a

\Rightarrow
\rightarrow
\uparrow
\Uparrow

indicates that the command is not a standard LATEX command.

Table 14.3
a

Arrows

a
a

Mathematics accents

\dot a
\ddot a

a
`
a

\grave a
\hat a

\tilde a

Table 14.4 Foreign and accented characters


a

\aa
\AA

\ae
\AE

\o
\O

\ss

a
a`

\a
\a

a
a

\^a
\"a

a
a

\~a
\=a

\.a

206

Chapter 14 OxMetrics Graphics


Table 14.5

\aleph
\angle
\approx
\ast
\bullet
\cap
\cdot
\clubsuit
\cong
\cup

\degree
3 \Diamond
\diamondsuit
\div
\emptyset
\equiv

Mathematical symbols

\exists

\forall

\geq
>
\gt or >
\heartsuit
=
\Im

\in

\infty
R
\int
h
\langle
d
\lceil
. . . \ldots

\leq
b
\lfloor
<
\lt or <

\arccos
\arcsin
\arctan
\arg
\cos
\cosh
\cot
\coth

csc
deg
det
dim
exp
gcd
hom
inf

\copyright
\euro
\florin
\$
\{

\rfloor
\sim
\spadesuit
\subset
\subseteq
\sum
\supset
\supseteq
\surd
\therefore
\times
\triangledown
\vee
\wedge
\wp


r
\
}

ker
lg
lim
lim inf
lim sup
ln
log
max

\ker
\lg
\lim
\liminf
\limsup
\ln
\log
\max

min
Pr
sec
sin
sinh
sup
tan
tanh

\min
\Pr
\sec
\sin
\sinh
\sup
\tan
\tanh

Miscellaneous symbols
\P
\pounds
\registered
\\
\}

tm

\S
\trademark

\_
\%

indicates that the command is not a standard LATEX command.

Table 14.8
bold
bold italic
font 0 to 9
italic

Log-like symbols

\csc
\deg
\det
\dim
\exp
\gcd
\hom
\inf

Table 14.7
c

Euro
f
$
{

i
e
<

\mid
\neg
\neq
\ni
\oplus
\otimes
\partial
\perp
\pm
\prime
\prod
\propto
\rangle
\rceil
\Re

indicates that the command is not a standard LATEX command.

Table 14.6
arccos
arcsin
arctan
arg
cos
cosh
cot
coth

6
=
3

0Q

\bf
\bi
\f0 \f9
\it

Fonts and sizes

roman
sans serif
typewriter

\rm
\sf
\tt

small

large
normalsize

\small
\large
\normalsize

Chapter 15
OxMetrics Data Management
15.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.

15.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.

15.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.

15.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:
Orientation: portrait or landscape;
Number of columns on the printed page;
Scale for printing: 100 is full scale, 90 smaller, etc.;
Draw a box;
The size of margin to use;
207

208

Chapter 15 OxMetrics Data Management

Write a header and footer. This is controlled via the Header and Footer boxes.
There are five specials:
&[date] prints the date,
&[time] prints the time,
&[page] prints the page number,
&[pages] prints the total number of pages,
&[file] prints the file name.
Other text in the edit field is printed directly.

15.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.
See Chapter 11 for detailed information on the file formats supported by OxMetrics.

15.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 (10.1),
maximum maximum value,
std.dev standard deviation of valid observations, see (10.1).

15.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.

15.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 (high-

15.9 Renaming variables

209

lighted) for:
copying to the clipboard;
as a destination for a block from the clipboard;
to set to a single value: press Enter to specify the value, whence you will be
prompted whether the value should be applied to the whole selection.
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.

15.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.

15.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.

15.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.

15.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.

15.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:
Add observations at the start;
Add observations at the end;
Delete observations at the start;
Delete observations at the end.

210
15.13.1

Chapter 15 OxMetrics Data Management


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.

15.14

Copy and paste

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

15.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:
the sample of the open database will be extended to encompass that of the appended
database;
if a variable from the appended database already exists in the open database, then
the existing variable is updated, except where the appended variable has missing
values (for those observations the existing variable is not changed).

15.16

Daily, weekly and timed data

The calendar1 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).2 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
1

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).
2
This is similar to how Excel stores dates and times.

15.16 Daily, weekly and timed data

211

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:
the first column must be of type Date,
the first column holds date values,
the optional fractional part of this indicates time as a fraction of 24 hours; e.g.
2453372.75 is 18:00 on 2005-1-1 (2005-1-1T18:00 in ISO notation),
the first and last observation must be valid, i.e. cannot be missing.
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.
See 5.3 and 8.8 for more examples.

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, 661692. 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. [94]
Doornik, J. A. (2006). The role of simulation in econometrics. In T. Mills and K. Patterson (Eds.), Palgrave Handbook of Econometrics, pp. 787811. Basingstoke: Palgrave
MacMillan. [133]
Doornik, J. A. (2013). Object-Oriented Matrix Programming using Ox (7th ed.). London:
Timberlake Consultants Press. [64, 160]
Doornik, J. A. and D. F. Hendry (2013). Interactive Monte Carlo Experimentation in Econometrics Using PcNaive (3rd ed.). London: Timberlake Consultants Press. [64]
Doornik, J. A. and M. Ooms (2005). Outlier detection in GARCH models. Discussion paper
2005-w24, Nuffield College. [72]
Doornik, J. A. and M. Ooms (2008). Multimodality in the GARCH regression model. International Journal of Forecasting 24, 432448. [72]
Engler, E. and B. Nielsen (2009). The empirical process of autoregressive residuals. Econometrics Journal 12, 367381. [4, 148]
Golub, G. H. and C. F. Van Loan (1989). Matrix Computations. Baltimore: The Johns Hopkins
University Press. [142]
Granger, C. W. J. (1966). The typical spectral shape of an economic variable. Econometrica 34, 150161. [92]
Granger, C. W. J. and P. Newbold (1986). Forecasting Economic Time Series, (2nd ed.). New
York: Academic Press. [144]
Green, P. J. and B. W. Silverman (1994). Nonparametric Regression and Generalized Linear
Models. A Roughness Penalty Approach. London: Chapman and Hall. [147]
Hall, B. H. and C. Cummins (2005). Time Series Processor 5.0 Users Guide. Palo Alto, CA:
TSP International. [64]
Hardle, W. (1990). Applied Nonparametric Regression. Cambridge: Cambridge University
Press. [146]
Harvey, A. C. (1993). Time Series Models, (2nd ed.). Hemel Hempstead: Harvester Wheatsheaf. [135, 142, 149]
Hastie, T. J. and R. J. Tibshirani (1994). Generalized Additive Models. London: Chapman and
Hall. [147]
Hendry, D. F. and J. A. Doornik (2013). Empirical Econometric Modelling using PcGive:
Volume I (7th ed.). London: Timberlake Consultants Press. [64]

213

214

REFERENCES

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. [64, 147]
Laurent, S. (2013). G@RCH Professional 7 (5th ed.). London: Timberlake Consultants Press.
[64]
Makridakis, S., S. C. Wheelwright, and R. C. Hyndman (1998). Forecasting: Methods and
Applications (3rd ed.). New York: John Wiley and Sons. [149]
Nielsen, B. (2006). Correlograms for non-stationary autoregressions. Journal of the Royal
Statistical Society B 68, 707720. [90, 143]
Priestley, M. B. (1981). Spectral Analysis and Time Series. London: Academic Press. [135,
144]
Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. London: Chapman and Hall. [145]

Author Index
Cummins, C.

64

Davidson, J. E. H. 94
Doornik, J. A. 64, 72, 133, 147, 160
Engler, E.

4, 148

Golub, G. H. 142
Granger, C. W. J. 92, 144
Green, P. J. 147
Hall, B. H. 64
Harvey, A. C. 64, 135, 142, 147, 149
Hastie, T. J. 147
Hendry, D. F. 64, 94
Hyndman, R. C. 149
Hardle, W. 146
Koopman, S. J.
Laurent, S.

64, 147

64

Makridakis, S.

149

Newbold, P. 144
Nielsen, B. 4, 90, 143, 148
Ooms, M.

72

Priestley, M. B.

135, 144

Shephard, N. 64, 147


Silverman, B. W. 145, 147
Srba, F. 94
Tibshirani, R. J.

147

Van Loan, C. F.

142

Wheelwright, S. C.
Yeo, J. S.

149

94

215

Subject Index
3-dimensional plots 96, 196
3D
contour 98, 197, 200
palette 97, 196, 200

densn() 131, 178


denst() 131, 178
diff() 23, 41, 60, 173, 178
div() 178
dlog() 178
dummy() 23, 41, 60, 178
dummydates() 178
ewma() 176, 178
ewmc0() 176, 178
exp() 178
fabs() 178
floor() 178
fmod() 178
hours() 176, 178
indates() 178
insample() 25, 42, 61, 130, 136, 137,
175, 176, 178
isdayofmonth() 176, 178
iseaster() 178
lag() 173, 177, 178
log() 178
log10() 178
loggamma() 132, 178
makedate() 178
maketime() 178
max() 178
mean() 179
min() 179
minutes() 176, 179
month() 176, 179
movingavg() 129, 179
movingSD() 179
pacf() 179
peak() 179
period() 94, 179
periodogram() 144, 173, 174, 179
probn() 179
quanchi() 179
quanf() 179
quann() 179
quant() 179
ranchi() 133, 179

Actual series 17, 34, 52, 82, 141, 193


Add Graph 108
Algebra 6, 24, 41, 60, 130, 167179
editor 130
file (.alg) 160
functions 173, 177
indexing 171
keywords 171
operator precedence 169
Executing code 167, 186
Implementation 172
Syntax 168
Variable names 168
Algebra Constants
FALSE 25, 42, 61, 130, 172
FREQUENCY 172
MISSING 137, 172, 173
NOBS 131, 172
TRUE 25, 42, 61, 130, 172
Algebra Functions
sortallby() 174, 179
sortby() 134, 179
abs() 178
acf() 90, 173, 178
acos() 178
almon() 129, 178
asin() 178
atan() 178
ceil() 178
cos() 178
cum() 129, 132, 178
date() 176, 178
day() 176, 178
dayofweek() 176, 178
delete() 178
denschi() 131, 178
densf() 131, 178

217

218

SUBJECT INDEX

ranf() 133, 179


rann() 133, 179
ranseed() 136, 179
rant() 133, 179
ranu() 133, 179
round() 179
season() 179
seconds() 176, 179
sin() 179
smooth hp() 175, 179
smooth np() 175, 179
smooth sp() 138, 175, 179
sort() 174, 179
sortallby() 174, 179
sortby() 134, 174, 179
sqrt() 179
stock() 129, 179
stockv() 179
tailchi() 133, 179
tailf() 133, 179
tailn() 133, 179
tailt() 133, 179
tan() 179
time() 176, 179
trend() 136, 174, 179
trough() 179
usedata() 168
variance() 179
year() 136, 176, 179
Almon lag 129, 178
Appending
data 121, 183, 210
results 183
ARCH 135
Area 100
Layout 199
Aspect ratio 102, 198
Autocorrelation 82
function 90, 136, 142, 173, 195
Autocovariance 142
Autoregressive
moving average (ARMA) 135
process 135
Axis 112, 201
anchor 112, 201
font size 202
labels 202
scaling 201
tick marks 201
transformation 201
Labelling 201
Location 201
Rotate labels 112, 202

Azimuth

97, 196, 199

Bandwidth 147
selection 138, 145147, 175
Batch 7, 180191
editor 7
file (.fl) 7, 160
running 7
syntax 180
Executing code 180, 186
Graphics settings 108, 187
Batch Commands
appenddata 183
appresults 183
break 183
chdir 183
closedata 183
command 184
database 184
draw 184
drawf 184
drawx 185
drawz 185
exit 185
loadalgebra 186
loadbatch 186
loadcommand 186
loaddata 186
loadgraph 186
module 186
package 186
print 186
printdate 187
println 186
savedata 187
savedrawwindow 187
saveresults 187
setdraw 108, 187
setdrawwindow 188
show 188
usedata 189
Black and white 165
Black, white, gray 165
Box plot 89, 149
Boxed 197, 202, 207
Boxed graph 18, 35, 53
Bubble chart 94, 196
Calculator 22, 39, 57, 128, 167, 209
Changing sample 120, 121, 210
2 -distribution 131, 148
2 -random numbers 134
Choice variables 125

SUBJECT INDEX
Clipboard

21, 24, 38, 41, 57, 60, 86, 102,


117, 121, 204, 209, 210
Colour 105, 107, 165
Comma separated file 154
Conditional statement (Algebra) 25, 42, 61,
130, 170
Copy properties to other areas 203
Correlation
coefficient 142
Correlation coefficient 142
Correlogram 90, 142
Creating a new variable 115
Cross-correlation function 91, 143, 195
Cross-section analysis 174
CSV (comma-separated) file 113
Cumulation 179
Cut and Paste 102, 117, 204, 209, 210
Daily data 67, 122, 210
Data
accuracy 14, 32, 49
appending 120
closing 183
copying to the clipboard 117
description 79
documentation 152
input 114118
loading 119120, 186
ordered by observation 118, 159
ordered by variable 119
pasting from the clipboard 117
printing 207
saving 119, 187
storage 7
with load info 159
Human-readable 119, 120, 159
data.in7/data.bn7 13, 30, 47, 128, 151
Database 6, 113, 114
description 207
editing 208
with dates 122
Appending data 121, 183, 210
Changing the sample 121, 210
Extending the sample 121, 209
Reset starting date 121, 210
Undo 24, 41, 60
Date
in database 67, 122, 210
Algebra functions 176
Representation 8, 123, 210
Default bars 145
Deleting a variable 23, 40, 59, 209
Density

219

estimation 144
Density estimation 87
DHSY 94
Dialogs
Algebra 24, 41, 60, 130
Calculator 22, 39, 57, 128, 209
Dummy 23, 40, 59
Create a New Database 114
Edit Graphics 103
Area Layout 101, 199
Aspect ratio 92
Axes 106, 201
Copy properties to other areas 203
Error bars 200
Graph Layout 102, 198
Hide axis 112
Histogram 89, 203
Label 200
Legend style 202
Legends 110
Lines (Error Bar) 96
Match by 112
Regression 104
Regression, Scale 85, 200
Rename 105
Scaling 111
Style 98, 104, 105, 200
Type 104, 199
Formulate 70
Graphics 17, 34, 51, 80
Autocorrelation function (ACF) 81
Distribution 81, 83
Distribution Options 88
Scatter Plot 137
Scatter Plot Options 85, 86
Select type of graph 80
Two series by a third 94
Graphics Setup 107, 203
Write as batch 187
Graphics Text 110, 203
Lines and symbols 109
Modelling
Formulate 70
New 114
Open 114
Open File 114, 119, 120
Settings GARCH 70
Tail Probability 133
Test 71
Variable Description 15, 32, 49, 115
Directory structure 4
Documentation conventions 10
Dummy variable 23, 40, 59, 129, 173

220
Durbins method

SUBJECT INDEX
142

Editor
Algebra 130
Batch 7
Elevation 97, 196, 199
Enhanced meta file (.emf) 166, 204
Error
bands 200
bars 200
fans 96, 200
Error messages 130
Exponentially-weighted moving average
(EWMA) 149, 176
Exponentially-weighted moving correlation
149, 176
Extending sample 121, 209
F-distribution 131, 148
F-random numbers 134
File
extensions 7
extensions and Open 114
extensions in Windows Explorer
names 7
Folder structure 4
Font 165, 202, 203, 207
Fourier decomposition 91, 195
Frequencies 89
Frequency 153, 172

8, 14

Gamma function 131


Gauss data file (.dht/.dat) 160
Generalized cross validation 146, 148
Graph 100
areas 100
axes 201
coordinates 19, 35, 53, 100, 192
copying 21, 38, 57, 102, 204
layout 92, 165, 198
paper 100, 192
pasting 21, 38, 57, 102, 204
printing 21, 38, 56, 197
saving 21, 38, 56, 187, 198
scale 92, 198
scaling 200
text 110, 203
view 102
ics window 193
3-dimensional plots 96, 196
Actual series 17, 34, 52, 82, 141, 193
Batch control 187
Boxed 18, 35, 53
Distribution 87, 194

Grid lines 105, 202


Lines 203
Multiple s 19, 36, 55
Multiple scales 112
Multiple series 84, 194
QQ plots 92, 195
Renaming variables 105
Scatter plot 84, 141, 145147, 194
Shading 83
Time-series: ACF etc. 90, 195
Transformed series 82, 193
Two series by a third 94, 196
Undo changes 21, 38, 56
Graphics
Adding to 108
Context menu 108
Copy properties to other areas 203
Delete From Graph 108
Drawing 109
Removing from 108
Grey levels 165, 197
Grid 202
Help 5
Histogram 87, 144, 203
HodrickPrescott filter 137, 147, 148, 175
Holts method 149
Human-readable file 119, 120, 159
Integration

129, 179

Keep Graph 102, 193


Kernel 145, 146
smooth 86, 146, 175
Epanechnikov 146
Normal 144
Kurtosis 87
Label
Names used in 200
Lags 22, 23, 39, 40, 57, 59, 178
Latex 204
Leads 178
Legend 110
style 202
Rename variable 200
Renaming variables 105
Licensing code 12, 30, 47
Line 199
colour 103, 105, 107
drawing 203
style 200
type 103, 107, 199, 200
Long memory 90

221

SUBJECT INDEX
Lotus

154

Matching
means 200
means and ranges 84, 111
Matrix file (.mat) 161
Menus
Edit menu
Add Text 110, 203
Change Sample 120, 121
Change sample 209
Copy 120
Database Description 207
Draw 109
Draw Line 109
Edit Field 208
Edit Graph 198, 199
Lines and symbols 203
New Variable 115, 209
Reset Starting Date 121, 210
File menu 13, 30, 48
New 114, 207
New Data Plot Window 84, 102, 193
Open 114, 119, 120, 198
Print 197, 207
Print Page Setup 197, 207
Print Preview 197, 207
Save As 118, 119, 198, 208
Model menu
Algebra 130
Calculator 22, 39, 57, 128
Graphics 16, 34, 51, 193
Model 68
Preferences 107, 200, 203
Tail probability 133
Test 71
View menu
Increase Text Size 207
Point 203
Summary statistics 208
Microsoft Excel 113, 118, 119
data file 119, 154
Copying from 120
Microsoft Word 21, 38, 166, 197
Missing value 82, 87, 115, 142, 145,
147149, 153, 155, 159, 168, 169,
172, 175, 193, 194, 204
Module 6476, 186
Modules
Model 68
Moving
average 129, 179
standard deviation 179

Multiple series

84, 194

New Data Plot Window 102


Non-parametric
density estimation 144
regression 146, 147, 175
Normal
distribution 130, 131, 145, 148
kernel 144
random numbers 134
Numerical
accuracy 133
integration 132
Open command and file types 114
Output storage 8, 160
Ox 6
file (.ox) 160
OxMetrics data file (.in7/.bn7) 7, 151
Binary file (.bn7) 119, 153
Generation 152
Group 153
Information file (.in7) 119, 151, 154
OxMetrics graphics file (.gwg) 161, 198
OxPack 6
OxRun 6
Package 186
Paper colour 199
Partial autocorrelation function 91, 142, 195
Parzen window 144
Paths in Batch files 183
PcGive 11, 28, 46, 68, 87, 90, 189
PDF
file (.pdf) 163
Periodogram 91, 142, 143, 195
Pixel coordinates 188, 192, 199, 203
Pointing 203
PostScript
colour model 164
file (.eps) 163
file (.ps) 165
mode 165, 198
Full page graph 165
Precedence (Algebra) 169
Print
Orientation 197, 207
Printing 197, 207
Probability functions 179
Projections 201
QQ plot 88, 92, 148, 195
Quantile plot 93, 148, 196

222

SUBJECT INDEX

Random number generators 133, 179


Recession shading 83
Register OxMetrics 6, 12, 30, 47
Regression 200
lines 85, 104, 145, 201
Recursive lines 145, 201
Sequential lines 145, 201
Rename variable in legend 200
Renaming variables 15, 23, 32, 41, 49, 59,
209
Reordering variables 23, 40, 59, 209
Results file (.OUT) 160
Results window 8
Sample period 8, 152
for graphs 204
Scaling 84, 111, 200
Scatter plot 84, 137, 141, 145147, 194, 199
Scientific Word 166
Seasonal 94, 170, 179
sub-plot 90, 94, 195
Smoothing 137, 175
Sorting 174
Spectral density 91, 142, 144, 195
Bias 144
Spline smooth 85, 137, 147, 175
Spreadsheet files 119, 154
Stata data file (.dta) 160
Status bar 8, 15, 19, 32, 35, 49, 53
Stock 129, 179
Sub-sample evaluation 128
Summary statistics 208
Surface
from scatter 96
from table 98
Swap
variables in a database 23, 40, 59, 209
Symbol
size 200
type 200
t-distribution 131, 148
t-random numbers 134
Text 110, 203
LATEX-style 204
Rotate 203
Timberlake Consultants 5
Time
Algebra functions 176
Representation 8, 123, 210, 211
Time-series: ACF etc. 90, 195
Toeplitz matrix 147
Tool bar 14, 32, 49
Tool bars 9

Toolbar
Model 68
Transformed series 82, 193
Trend 174, 179
TSP 73, 87, 90
WWW address 5
file (.tsp) 161
Tutorial data set (data.in7/data.bn7)
47
Twist 97, 196, 199
Two series by a third 94, 196

13, 30,

Uniform
distribution 148
random numbers 134
Upgrades 6
Value labels 125
Variable
creation 115
names 152
names in algebra 168
Sorting a 174
Variables
Adding 120, 209
Copying 120, 210
Deleting 23, 40, 59, 209
Renaming 15, 23, 32, 41, 49, 59, 209
Reordering 23, 40, 59, 209
Vector 199
Weekly data 67, 122, 210
Windows bitmap 204
Windows Explorer 7, 8, 14, 76
Windows meta file (.wmf) 166
Windows XP 14
WKS,WK1 files 154
Workspace 25, 43, 62
World coordinates 192, 199, 203
WWW 5
XLS files 154
XLSX files 119, 154
YuleWalker equations

142

You might also like