Advanced econometrics with Julia

By: Blog by Bogumił Kamiński

Re-posted from: https://bkamins.github.io/julialang/2023/12/22/mars.html

Introduction

Working on DataFrames.jl has been a great experience for me.
One of the by-products of this work is the DataFrames.jl: Flexible and Fast Tabular Data in Julia paper about the design of this package that I have co-authored with Milan Bouchet-Valat.
Recently I got a notification about a citation of this paper. The reference is MarSwitching.jl: A Julia package for Markov Switching Dynamic Models article by Mateusz Dadej. I found the MarSwitching.jl package an interesting contribution to the Julia package ecosystem so I have decided to devote this post to it.

Econometrics in Julia

The basic packages for doing econometrics in Julia that I have been using are GLM.jl and MixedModels.jl.
These packages are quite powerful, however, one could say that they provide “standard” functionality in econometrician’s toolbox.
Users often ask for specialized packages implementing various more advanced econometric models.

A basic answer is that with Julia often they are not needed. For a person knowing this language it is usually easy to implement an appropriate estimation procedure from scratch. The reasons are the following:

  1. Julia is expressive – such code is usually short; often learning the API of the package could take longer than coding the model.
  2. Julia is fast – you can expect that your custom implementation will be efficient, as opposed to R/Python you do not need to have to implement the compute engine in e.g. C++.
  3. Advanced econometrics models are often “open ended”. What I mean by this is that the authors of such models describe some specific case in the paper and your problem at hand requires some modifications. When you implement things yourself you can easily include such custom changes.

Having said that, there are some classes of models that have become widely used in econometric practice and the specification of their API is already well established.
In such a case I believe it is worth to have a package that implements it.
The MarSwitching.jl package is in my opinion a good example of such a case.

Markov switching dynamic models

So what are Markov switching dynamic models? Let me explain it by two examples (taken from the documentation).

The general idea is that you can have an economic phenomenon where the parameters of the relationship between the target
variable and the features depend on some unobservable state, often called “regime”.
The objective of the estimation is to find: (a) the probability of switching of the relationship between regimes, and (b) estimate the parameters of the relationship in each of the regimes. If this sounds abstract to you it is best to learn it by examples.

A stylized fact in economics is that inflation falls during recessions and rises during booms.
This relationship is called Phillips curve.
However, it is argued that the strength of this relationship is not constant in time.
In the Regime switching Phillips curve you can find how to estimate and interpret the model that assumes that indeed the relationship can be either in “weak” or “strong” regime.

The second example is related to stock markets.
The hypothesis tested in the Time-varying transition probabilites – modelling stock market example is that the market can be in two states: “bull” and “bear”.
The bull market is characterized by low volatility and positive drift, while bear market with high volatility and negative drift.
Also the model shows that the chance of switching between the two regimes depends on an option implied measure of expected volatility of S&P500 index.
Again, I leave out the details as they are nicely explained in the documentation.

The point is that in economics we repeatedly hypothesize that some observed phenomena depend on some unobserved state of the market.
Markov switching dynamic models are a perfect tool for studying such processes and it is really nice that we have a package that implements them.

Conclusions

We are getting to the end of the year 2023 and I have been using Julia on a daily basis for over five years now.
It is really encouraging that I constantly discover new high-quality and well documented packages in the Julia ecosystem like MarSwitching.jl.

Have a happy holiday break!