Economics programs written in Mathematica


Thomas Cool, June 30 1996, Report no 96-07

Consultancy & Econometrics, email Cool@CAN.NL




The program Mathematica is being discovered by economists. This paper introduces a number of programs that help to provide a working and teaching environment. Keywords are: Chi2, CrossTable, Decision, Dbase, DifData, Finance, Graphics, Inference, Logic, Minimax, Modeling, Sampling, Statistics, Calculus, CES, Economic`Common, Economic`Optimise, IADS, Lagrange, LevelCES, Applied General Equilibrium Analysis, Neural Networks, Nonlinear Estimate, Leontief, List, Manager, Matrices, Tool, Chain Indices, Declare, Genetic Programming.




It seems to me that Mathematica may be one of the revolutions of mankind. The invention of the wheel, the alphabet, hygiene, the steam engine, women's lib, ... What penicilline is to an infected person, what Adam Smith's Wealth of Nations means for civilisation, is what Mathematica will likely be to human inquiry.

Generations of mathematical geniusses have been designing an elegant and compact language to state their theorems and proofs: mathematics. This language is now being implemented on the computer, so that you can proceed along as you think.

The best way to see what this actually means, is to use Mathematica.

These present notebooks and packages have been developed for economics. I'm econometrician involved in decision support, and these tools have served and still serve their purpose. Also, I like to have my software neat and well documented, so that I can turn to it quickly when I need it again. My conjecture is that others could use it too.

These applications may help others:


Keywords on ...

Applied General Equilibirum Analysis

Extend on Asahi Noguchi's packages, see Varian (1993). [Note 1]

Solve systems of production and utility functions and plot 2D diagrams for arbitrary sectors and factors. Plot their time trajectories.

Have easy access to the (Dynamic) Leontief Model.


Substitute y = f[x] back into D[y, x] to get a simpler expression.

A general routine to use Lagrange multipliers.

Decision Making

Logic and inference.

Statistical decision theory including game theory (e.g. minimax).

Crosstables, and ChiSquare tests (in higher dimensions).


Database, datafiles, using packages as datafiles, data contexts, data dictionary


Use NonlinearFit for estimation of equations and systems of equations, with an estimated variance for the estimated parameters.

Errors in variables for one equation.

Lags, Arima and some tests of the WRI Time Series Pack.


Some general efficiency, minimal cost, maximal profit, and factor demand routines. Applications on the CES, LevelCES and IADS functions, while providing the proper limits for Leontief, Cobb-Douglas and Line functions.

Standard representation of factors, price, coefficients and key parameters. Write your own function using the standard, and call the general routines.

Economics Papers

A solution approach to problems of unemployment and inflation, using Mathematica as a word processor, while including many graphs created with it.

Using Dutch data of 1950-1995 for a further explanation of the analysis on unemployment. Provide your own data and test the analysis for your own country.

See how you might apply Chi2 tests to Frauds in the European Community.

Let the gasoline price at the center of a metropolitan area be higher than in the surrounding rural area.


Flat rates & basics.

Try the WRI Finance Package and use some additional features

Genetic Programming

Define a population, a fitness criterion, and evolve. [Note 2]


Plans, events, bond durations, calendar dates.

Use arrow diagrams to clarify relations between variables.

Linear Algebra

Create block diagonal matrices


Make a model with various lags, and simulate it for a period. Store the various runs, and compare the outcomes.

Neural Networks

Use a "master" packages for Freeman's packages, see Freeman (1994).


See Decision Making.

Chain indices. Using approximate US data as an example.

System Enhancement

Speed up the loading of common routines, and use separate contexts: Common, Declare, Graphics, List, Manager and Tool

Have various packages share common keywords with AddedUsage, store and reset definitions without saving, inspect and show levels and dimensions



Notebooks and Packages


The Cool Economics Pack consists of "notebooks" and "packages". Notebooks are the user-friendly interface of Mathematica with the user. The packages contain the routines.

The following lists the available packages (though with the "Cool`" prefix deleted):

{AGE`, Arima`, Arrowise`, Calculus`, CES`,

Chaindex`, Chi2`, Common`, Context`, CrossTable`,

Dbase`, Decision`, Declare`, Dictionary`,

DifData`, Economic`Common`, Economic`Optimise`,

Estimate`, Finance`, FlatRate`, GenePro`,

GP`Estimation`, Graphics`, IADS`, Inference`,

Lagrange`, Lags`, Leontief`, LevelCES`, List`,

Logic`, Lseqlist`, Manager`, Matrices`, Minimax`,

MissingData`, Model`, Neural`, PackLine`,

ReadData`, Sampling`, ShowPlan`,

Statistics`Common`, Time`, Tool`}




Technical Notes & Availability


The "Cool Eonomics Pack" contains about 200 files and takes 6.5 MB on hard disk. Binary files ("*.mb") that control the lay-out have been deleted.

Loading all packages - and the Mathematica packages that are relied on - takes about 2700 KB internal memory.

The Mathematica packages that are relied on and which are supplied by others, are: (1) the standard packages supplied from WRI, (2) for resetting: CleanSlate` (3) for Finance: the Finance Package of WRI, (4) for applied general equilibrium analysis: Asahi Noguchi & Silvio Levy's MyFindRoot` (Varian (1993)), (5) for math: Varian's SymbOpt` (see Varian), (6) for neural networks: Freeman (1994). For copyright considerations, only the CleanSlate` package is included here, and you are advised to buy the Varian book. (But you may also look into MathSource, see

Documentation is provided in & by the notebooks only.

The software has a semi-commercial status. Iíve decided to give it a licensed status, and to ask a small price for it. My hope is that there will be sufficient revenue to provide for the expense of a manual, and that sort of thing.




Thomas Cool
The Netherlands





J.A. Freeman, "Simulating neural networks with Mathematica", Addison Wesley, 1994

J. Kleid, "Genetic Programming with Mathematica", Son Of a Bit Software 1994, available from MathSource

H.R. Varian (ed), "Economic and financial modeling with Mathematica", Telos 1993


This is an update of the report of 1995 with the same titel, Report-no: Thomas Cool 95-03. Programs have been added, others improved and integrated. This paper now is in Word for Windows, to allow for a wider distribution.



I gratefully acknowledge Asahi Noguchiís comment: "... you have done a great deal of elaboration onto former works of mine and others. I am very pleased to see it, and convinced that it will be a useful tool for anyone doing economics using Mathematica."

2 My package was inspired by a notebook by Kleid (1994). Unfortunately, Kleid's electronic address was not functioning in 1995, so I found myself unable to discuss with him the possibility of simply copying some of his routines; and thus I have written my own. This appeared to be feasible in a relatively short time due to the properties of Mathematica, particularly of its internal administration of parts and levels within functions. (That property is also exploited in my package on the "Level CES function".)

I found that the problem of genetic programming very much dictates the programming structure:

  1. an initial population,
  2. scoring on a criterion,
  3. breeding,
  4. iterate.

I noted errors in Kleid's notebook, on crossover, his "doCheck" subroutine, and fitness selection. And, since I was inspired by Kleid's notebook myself, I like to point out the features of my own programming:

  1. the genetic engine is put into package instead of a notebook: with quicker loading, better balance between front and background, and always available "?" help,
  2. embedding in $Cool and standard Mathematica packages,
  3. exploit of the Mathematica programming language, better building blocks, and transparent code for whom who needs to adapt,
  4. flexible input/output e.g. by use of options,
  5. use of constants and functions with more arguments,
  6. natural names like Genesis, Birth, etc.,
  7. features like Evolve, Seed, Method, Death, Mutate, FlexibleSize, Duration,
  8. least squares estimation as the key example rather than centering a cart,
  9. use of packages for (separate) Fitness routines, see for example the Cool`GP`Estimation`, Cool`GP`Cart` packages,
  10. wider range for mutations since also the head of expressions may change (and this is no problem since I always keep the fittest in the population).