I’ve just came across a clever trick to draw implicit functions in gnuplot, here. The idea is to use the level curves of the surface plot.

With this trick we can draw indifference curves of CES utility function quite easily. See my scripts on gist.

I’ve just came across a clever trick to draw implicit functions in gnuplot, here. The idea is to use the level curves of the surface plot.

With this trick we can draw indifference curves of CES utility function quite easily. See my scripts on gist.

The title says it all. Here’s the code https://gist.github.com/trialsolution/cd2ac7fae9d4ede70aec

OK, not a million ways, but many…

The 2×2 Heckscher-Ohlin model for a small open economy is probably the one people spend the most time with on undergraduate trade theory classes. But we can translate the model in many equivalent ways into an optimization model. In the GAMS code below I start with Edward Tower’s textbook model from his excellent book ‘Introduction to Numerical Simulations for Trade Theory and Policy’, and formulate it as

– direct/indirect utility maximization,

– as an MCP, CNS or NLP model

– in one go or in a sequence of optimization models

– with or without explicit trade balance

Salhofer (1996) developes an optimization framework to find an efficient combination of policies. Efficient here means that the losses in the consumer surplus (compared to non-distortion) combined with the impacts on the budget are minimized. Salhofer applies the framework on the Austrian bread grains market and finds an efficient combination of four policy measures (deficiency payment, price floor, production quota and co-responsibility levy).

I’m glad I can take his welfare economics graduate course these days and that he shares not only his insights but his GAMS code with us. Here comes a modified version of what he used for the original article. My code compares the efficient policies under different functional forms for the behavioural curves (log-linear versus linear). And I also included a numerical calibration approach using the CNS model type in GAMS. The original model used the analytically derived calibration parameters, just as it can be found in the article.

Reference:

Salhofer, K. 1996. “Efficient Income Redistribution for a Small Country Using Optimal Combined Instruments.” Agricultural Economics 13 (3): 191–99. doi:10.1016/0169-5150(95)01162-5.

Replicating results in journal articles is always difficult and many times even impossible. But sometimes you can find ‘simple’ numerical examples in journal articles that you can try to re-do with some efforts. It was also the case in the excellent article of Bach-Martin (2001) “Would the Right Tariff Aggregator for Policy Analysis Please Stand Up?” (Journal of Policy Modeling 23 (6)).

The article is about calculating aggregate tariffs over single tariff lines taking into account the demand structure of the economy. On page 630 the authors provid an example assuming a small open economy, covering only one aggregate product over six tariff lines. It was relatively easy to recover the calculations in the benchmark but I got some headache when I tried to run their tariff cut scenario. In my results imports grew so rapidly that they substituted a lion share of domestic production too. That was not the case in their results: they even reported a small decrease in expenditures on imports at world prices. It took me a while to figure out that they not only fixed total utility but also the consumption of the domestic goods! A small piece of information that was probably obvious for the authors but not for me. Making the domestic output constant was mentioned a few pages earlier, but I overlooked it and spent some time on reverse engineering their final numbers.

My GAMS code is available here: https://gist.github.com/trialsolution/7578734.

Here comes a GAMS implementation of a textbook example in “Risk, uncertainty and the agricultural firm” (Charles B. Moss). The examples was originally published in the famous Freund article in Econometrica (1956). The code contains some useful comments too on risk aversion and co.

A small GAMS example for using the calibrated share form of CES utility functions:

https://gist.github.com/trialsolution/7465475

Inspired by a question on the GAMS mailing list here comes three ways you can check the positive definitness of a matrix with GAMS.

One thing you can do is to pass the matrix to R and do the check there. Here’s an example how to do that: link.

If your matrix is symmetric then you can either

- do a Cholesky decomposition and check if the diagonals are all positive or
- you can compute the eigenvalues and check if all of them are positive.

In GAMS there both exist a utility to calcuate the lower triangular matrix in the Cholesky decomposition (cholesky.exe) and a utility that calculates the eigenvalues (eigenvalue.exe). All you have to do is to pass by your matrix in a .gdx file and retrieve the results.

The example for the Cholesky decomposition technique is here. The one using the eigenvalues trick is here.

A few days ago an email about panel data estimations caught my attention on the GAMS mailing list. I quickly put together a small example on a pooled OLS model in GAMS. See here.

But I have a strange feeling that we’re re-inventing the wheel if we want to do panel data econometrics only using GAMS. So here comes another example using the plm package of R. The idea is dead simple. GAMS pushes the data into a gdx, R reads in with the gdxrrw package and makes the calculations. Then the results are written to a gdx file where the GAMS process can pick it up again.

There’s always a trade off between implementing calculations in the original programming environment (here GAMS) and get the job done by an external program (R). In the latter case you need to build up and control the communication and know the basics of the other programming environment. If you choose implementing something in the original environment, you risk re-inventing the wheel and lose valuable time…

And now the code:

https://gist.github.com/trialsolution/5696875

I’ve just come across this beautiful worked example on how to calibrate CES utility functions by Rutherford: http://www.mpsge.org/calibration.pdf

In the example Thomas needs to decide whether or not to move in a different town where his salary and the rental prices would be different (both higher).

We use a CES utility function with only two goods: housing and an aggregate for others. The paper points out that the decision depends on Thomas’ substitution elasticity between housing and other goods. The “critical elasticity” would be the one that makes him indifferent in moving or not.

On page 5 there is a numerical example with the computed critical elasticity. I wrote a short gams script to verify if that elasticity is correct (although I have no doubts it was).