In quantitative marketing, one of the keys questions I faced was which programming language to use for research. Over the years, I noticed that the top 3 commonly used programming languages in our field are R, GAUSS, and MATLAB. Each programming language has its pros and cons, but let's compare which language does well in what category.
The following are some simple comparisons. The computer that I used was Intel Core 2 Duo CPU @ 2.66 GHz with 3.48 GB RAM. The language versions are R: 2.6.2, GAUSS: GAUSS 10, MATLAB:7.8.0.
1. Simple Operations
|Sum 1 to 10,000,000||9.53 sec||0.78 sec||7.60 sec|
|Create 10,000,000 random N(0,1) and sort||5.04 sec||6.80 sec||1.66 sec|
|Cross product of 10 1000x1000 matrices||0.12 sec||11.23 sec||1.14 sec|
Looking at this simple comparison, we can't say which language has the upper hand. Each langauge has its advantage. R for matrix operations, GAUSS for arithmetics, and MATLAB for assignment and sorting.
2. Static Models
Now let's turn to more complicated operations. One of the most basic model is the estimation of choice using the logit model. By running a more complicated model, we can compare the overall performances, such as calling functions/procedures and simple arithmetics, for each language. The data has 2430 purchase observations from 100 households. The goal was to estimate 5 parameters, 3 brand intercept parameters and 2 promotional coefficient parameters.
|Estimation of logit||2.31 sec||0.42 sec||0.22 sec|
This time, I'll add some unobserved heterogeneity in the model. In general, there are two main streams in accounting for unobserved heterogeneity, namely discrete and continuous. Let's look at the discrete case, commonly known as finite mixture model, first. Let's assume there are 2 segments, this requires estimating 5*2=10 coefficent parameters and 1 segment parameter. If we assume there are 3 segments, we need 5*3=15 coefficient parameters and 2 segment parameters.
|Estimation of logit w/ discrete unobserved heterogeneity (2 segment)||12.36 sec||4.59 sec||6.54 sec|
|Estimation of logit w/ discrete unobserved heterogeneity (3 segment)||63.96 sec||14.01 sec||22.04 sec|
For running unobserved heterogeneity (2 segment), I'm a bit bothered that R does not get the same results as GAUSS and MATLAB. For running unobserved heterogeneity (3 segment), all three languages gave different values. Because there were no differences when estimating 5 parameter, I assume having too many parameters may cause some issues in estimations.
Next, I added continuous unobserved heterogeneity in the model. It is common to assume that continuous unobserved heterogeneity come from a normal distribution. Parameters are estimated by a simulated integration. The number of draws are essential in estimating simulated integration, the more draws the close to actual normal distribution. Let's just use 10 and 30 draws for now.
|Estimation of logit w/ continuous unobserved heterogeneity (10 draws)||147.57 sec||34.63 sec||25.16 sec|
|Estimation of logit w/ continuous unobserved heterogeneity (30 draws)||244.45 sec||93.45 sec||70.26 sec|
Because the continuous unobserved heterogeneity involves random draws, the parameter values are not identical among different programming languages. Although, the results are reasonably close (<10% difference).
3. Aggregate BLP Models
Because individual consumer level data are hard to obtain, aggregate models are commonly used. Recently, the most widely used aggregate model is the BLP model. The BLP model estimates the linear parameters in the outer loop and the non-linear parameters in the inner loop. For this reason, it is optimal to check which programming language performing well in executing loop within a loop.
The basic setting are as follows. There are 4 brands and 3 promotional activities. These 7 parameters consist the linear parameters in the BLP model. The non-linear parameters are 2 heterogeneity parameters. Let's just use 1000 and 3000 draws for now. There are 50 markets per each brand.
|BLP model (1000 draws)||274 secs||34.7 secs||78.2 secs|
|BLP model (3000 draws)||383 secs||161 secs||648 secs|
Because the BLP model requires loop within a loop, GAUSS seems to be the superior language.
4. Dynamic Models
Now let's assume the models are dynamic, that is, consumers are forward looking. For dynamic models, expected lifetime value functions are commonly used. One distinction we need to make is the assumption of time horizon for the expected lifetime value function, i.e. whether the time horizon is finite or infinite. Let's look at the finite case first.
Before we do an estimation for the finite dynamic model, doing a simulation of it is worthwhile. We want to see how well each programming language deals the 'curse of dimensionality' that is caused by state space. Let's look at the career choice example. A person has 4 career choices to make for 40 years.
|Simulation of dynamic model (finite)||29 mins||0.38 sec||109 mins|
It is not a mistake that GAUSS is in secs while other languages are in mins. GAUSS performed in a remarkably faster time. The simulation of dynamic programming calls numerous for loops and procedure/function calls. We learned from previous exercises that GAUSS is good at looping. It seems looping accompanied by procedure/function calls are also more proficient in GAUSS. Now, you may also recall that GAUSS is not an Object-Oriented language while the other two are. It is well known that calling an object is a costly task in OOP.
Each programming language has several procedures to solve maximization. For R I used 'optim', for GAUSS 'optmum', and for MATLAB 'fminunc.'