Computable General Equilibrium

We want to discuss the modeling of computable general equilibrium in julia.

1 Like

You just map parameters to residuals of equilibrium constraints and solve. There is nothing Julia-specific there, except for the smooth Julia AD experience.

2 Likes

JuMP supports MCP Mixed complementarity problems · JuMP

And there is the indevelopment GitHub - anthofflab/MPSGE.jl: MPSGE for Julia

1 Like

I’d like to be able to program on Julia for my thesis, without using the GAMS software. I wanted to know whether this was possible or not.

I would say that it is much better than GAMS

1 Like

Should be possible, unless your problem is so large scale that you need a specialized solver that is only implemented in GAMS. For a few thousand variables you should be fine with solvers available in Julia (depending on your problem, of course — it is hard to discuss details without specifics).

Check with your thesis advisor though. It could be that he/she insists on a particular software.

I’ve found a source of documentation for creating CGEs in Julia (GitHub - KennethAnn/Julia-based-CGE-Tutorial: A tutorial for Julia-based CGE modeling with lots of cases). It’s very similar to the GAMS software. I’ve managed to transcribe the code for the CGE1 model into GAMS, I believe. Do you think it might be a good solution to formalize CGEs in Julia in this way? Thanks for all your answers, you’re a great help. No, my thesis director asked me to find a softwear to avoid buying the GAMS license. I wanted to start with R studio, but it seems much more complicated than Julia (even if the gEcon package in R could be a solution).

Which may not be an advantage once your think about it. Having a general programming language like Julia allows you to break up your code into smaller functions, test them, and maybe even move them into a library if they can be reused. I have done this with tiny things, eg a utility function like

GAMS and the code in the repo you linked encourages single monolithic functions, which is not ideal. On mid- and large-scale problems, you want the ability to debug small pieces of your code, check the mapping from parameters to residuals for numerical and AD problems.

CGEs are the simplest of economic models. You map the parameters \theta and the equilibrium objects \varphi (which may be scalars, or coefficients describing a function approximation) into residuals, evaluate these (again, functional equations at collocation nodes), make sure it works with your AD framework, and then put it in a solver and solve

F(\theta, \varphi) = 0

for \varphi(\theta). That’s all there is to it conceptually.

Tricks of the trade include

  1. what belongs in \varphi (answer: everything, really. if it has an equation, put it there, rather than solving for an interim value in F),
  2. domain specs (ideally, use a mapping so that all \varphi \in \mathbb{R}^n work, domain restrictions just make your life difficult and restrict the choice of solvers),
  3. numerical stability (hint: test using BigFloats, for random values, including seemingly extreme \theta and \varphi), do the same for AD,
  4. bookkeping (decomposing the vector into parameters).
1 Like

If you can get a GAMS license (costly), for a PhD student I’d say the decision of Julia vs GAMS depends on your programming ability and how much time you want to spend developing versus doing research and finishing your dissertation.

As @odow mentioned, there has been good progress with MPSGE.jl lately, so many of the issues I faced with JuMP and Complementarity.jl may be resolved now. More applied models with sparsity created issues for me. The models I link to below are old/dated so they might not work with latest packages, but highlight some of the problems I encountered with sparsity. GAMS was much easier/quicker to use in the case of the more applied models and has many built-in features that are useful for quality-checking your model. GAMS also created my models quicker — some of the objects I had to use slowed things down in Julia (again, programming ability).

NREL- SLiDE Model

I found it too difficult to debug my Julia model without using GAMS as a crutch, which probably speaks more to my abilities than pros/cons of Julia – but it was an issue I faced. Applied CGE modeling is error-prone and new modelers can be much more error prone than experienced modelers.

My julia workflow looked like this:

  • Write the model in GAMS/MPSGE format
  • Write the model in GAMS algebraic MCP format
  • Check that the MPSGE and Algebraic model produced identical results in counterfactual cases
  • Write the model in Julia
  • Check that the model in Julia produced identical results to the GAMS models in counterfactual cases
3 Likes