In this section:

About Mathematica

Mathematica and economics

Tips and tricks

About us

Download Mathematica Notebooks for Economics and Econometrics

All the Mathematica code available from this page was written by Luci Ellis, and is freely available. Please do not redistribute it for profit.

Business Cycle Analysis (56kb)
There are two main functions in this notebook. The first, findPeaks[a,b], finds peaks in data, defined as being a point that completes a rises and is followed by b falls. The second function, assymetricDetrending, uses the SplineFit package to generate estimates of trends in macroeconomic data. The reference for this procedure is Julian Allwood and David Shepherd (1999), “Alternative Detrending Procedures for Macroeconomic Time Series”, University of Melbourne Department of Economics Research Paper Number 698, June 1999. Dr Shepherd has kindly given me permission to post my implementation of their procedure on this website. I have not yet implemented their recommendations regarding the endpoint data, so this procedure does not yet deal with the case of incomplete cycles.
Various Econometric functions (24kb)
  • simpleLinRegress[]: quick-and-dirty OLS function for when you only need estimated coefficients, fitted values and residuals. I mainly use it as an input into other functions.
  • ARLagOrderSelectionTable[ ] for the Akaike, Schwarz and Hannan-Quinn selection criteria (updated September 1999 based on helpful suggestions by Virgil Stokes).
  • LjungBoxStatistic[data,k] test statistic and critical value for a vector of real numbers. Used for establishing serial correlation.
  • CochraneOrcutt[data]] for estimating linear models in the presence of AR(1) serial correlation in the errors.
MarkovThings (20kb)
  • MarkovQ[matrix] tests if a (square) matrix is an approprate matrix of transition probabilities for a Markov chain.
  • MarkovErgodicProbabilities[matrix]finds the stationary (ergodic) probabilities implied by a given transition matrix.
  • MakeMarkovChain[n_Integer,p_?MatrixQ] creates a time series of state numbers, ie a Markov chain, of length n, given transition matrix p. The starting point is taken from the ergodic probabilities.
The Johansen Procedure (8kb)
An implementation of the Johansen procedure for testing for cointegration in multivariate systems. I translated the algorithm from Gauss. Untested. Use at your own risk!
Filtering (52kb)
Implements the Hodrick-Prescott filter and the Henderson-weighted moving average (for all standard numbers of terms – 5, 7, 9, 13, 15, 17, and 23) and including the endpoints, as used by the Australian Bureau of Statistics. See also A Tutorial on Multivariate Hodrick-Prescot Filtering
Constructing a Bank of England “Fan Chart” (12kb)
This implements the Two-Piece Normal Distribution (another use of Upvalues), and draws a fan chart similar to that used by the Bank of England for presenting its forecasts of inflation and output growth. The code is based on a working paper by Professor Ken Wallis of Warwick University in the UK. My version is a bit more sophisticated than the BoE version in that you can choose as many bands, evenly spaced in quantile terms, as you like.