Matlab Code for Solving and Simulating Dynamic Oligopoly Models
The code for Goettler and Gordon (2013), ``Competition and Product Innovation in Dynamic Oligopoly,'' forthcoming in Quantitative Marketing and Economics was written in Gauss and C. To encourage exploration of dynamic oligopoly models by students and researchers, we converted the Gauss code to Matlab which is more widely used.
We provide no guarantees regarding this Matlab code, which is new and relatively untested. Please let us know if you find any errors or have suggestions for improvement.
Download each of the files below, or this zip of all 6 files.
calcval_C.c        run 'mex calcval_C.c' to create the MEX file
Steps for Installing and Running the Code:
1. Download the above files to a directory (or folder)
2. Run Matlab and change to that directory
3. In Matlab, run 'mex calcval_C.c' to create the MEX file
4. In Matlab, run 'pmgshell'
5. Choose parameter values, via menu options 1, 2, and 3
6. Compute the static profit function, via menu option 6
7. Compute the dynamic equilibrium, via menu option 7
8. Simulate the model to obtain welfare statistics and other industry outcomes, via menu option 8
To see what results are saved to files and the filenaming scheme, search for 'save(' in profit_main.m and in eql_ma_foc.m. The outcomes simulated in welf_ma.m are displayed to the screen.
In addition to the above interactive menu system (from the original Pakes-McGuire code), the code can also be run in "batch mode" which is useful for evaluating many models systematically.
To use batch mode, modify the file batchruns.m to hardcode the model(s) of interest. At the matlab prompt, batchruns would then solve and simulate the hardcoded model(s) and save the model configurations and associated files using the hardcoded batchjob ID. You can create many files with code similar to the code in batchruns.m for specific purposes. For example, delta_compstat.m might evaluate the model for a grid of delta values (which, in fact, is what the example code in batchruns.m does).
We thank Ariel Pakes for making available Gauss code that numerically solves the quality ladder game of Pakes and McGuire (RAND, 1994, hereafter PM), as well as two other variants of dynamic investment games in which firms innovate to lower marginal costs or to increase capacity. In addition to computing Markov Perfect Nash Equilibria, the PM code also computes optimal policies for social planners and cartels. Pakes provides a detailed description of the models and code here.
For our QME paper, we modified the PM code involving the Markov Perfect Nash Equilibrium of the quality ladder investment game. The static profit function code in profit_main.m retains code for the other two investment games, but we have not checked its functionality. We did not use the cartel or social planner code, and do not provide Matlab versions of those functions.
A description of the model parameters is provided in the function default() starting on line 89 in batchruns.m, where each parameter is assigned a default value and has a comment line.
Users may also want to change the following hard-coded parameters which govern the algorithm: Par.tol, Par.foc_tol, and ParRlg.damp.
In batch mode, the parameters numtimes, numruns, and wstart are hardcoded in welf_ma.m. In interactive mode via pmgshell, users are queried for values for those parameters.
If you prefer the Gauss code, let us know. It runs MUCH faster than Matlab (and is better documented since many of the comments were erroneously deleted in the conversion process).
As described in our QME paper, we modified the PM model and algorithm in the following ways:
1. provide an alternative approach to bounding the state space, which yields an endogenous long run (i.e., steady state) innovation rate. The PM approach to bounding the state space remains an option.
2. allow for stochastic scrap values from exiting (improves convergence)
3. allow for innovation spillovers, implemented via higher innovation efficiencies for laggard firms
4. allow entrants to enter at the current leader's quality state with some exogenous probability
5. provide a true backwards induction solution via solving the static game in each state in each iteration taking the future value functions as given (by the previous iteration). For a state with J incumbents, we simultaneously solve the 2J incumbents' first-order conditions for investment and exit policies and the one potential entrant's first-order condition for entry. This numerical solution often converges when the iterative best-response algorithm in the PM code fails to do so.
In addition to the above changes, we also made the following computational changes to the code:
1. The computationally intensive computation of continuation values by calcval() in eql_ma_foc.m is now done in C, via Matlab's external interface (MEX).
2. The code uses parallel threads, one for each cpu core, to cycle through the industry states during each iteration of the backward induction algorithm (or of PM's iterated best response algorithm).
3. To facilitate inspection of the equilibrium, the code now reports firms' value functions and policy functions at select states in eql_ma_foc.m and reports more simulated outcomes in welf_ma.m.