Sunday 9 January 2011

How to parametrize your graphs and wake up the audience

Today I'm going to visualize the first stage of the Hotelling model. Based on results derived in the previous post, we may define the equilibrium price of firm i (given rival's location xj) as:

My Plot will be built around two curves, each representing the total cost of purchasing the product from one of the two shops (located at x1 and x2), with the cost function ti defined as before:

I'll start by setting a few basic options of the plot: its range, the origin of the axes and the thickness of the curves.


I can now set the locations to anything I want and adjust the prices to the corresponding equilibrium values:


resulting in the following graph:

It is useful to obtain the location at which the two curves intersect (call it xTilde), and to make the axes display it, together with the firms' locations and the corresponding equilibrium prices:




giving the following result:


I will now add a few 'extras' to the graph, starting with two slightly transparent Rectangles with dashed edges: a blue one, corresponding to the profit of the firm located on the left, as well as a pink one, reflecting the profit of the other firm.


The following will add the extras to the plot and display it:



Finally, we might Append a few dotted lines to our collection of extras for the purpose of clarity:


Which brings us to why it's actually worth doing all this (rather than using, say, Adobe Illustrator). The reason is that any graphs created in this way are parametrized, which means we can adjust the values of any variables and see what happens straight away, rather than having to draw the whole thing all over again. Further still, we can create interactive dynamic visualizations, illustrating the comparative statics of our model.

The following code will allow the user to 'drag and drop' the locations of the two firms and observe the outcome.



To understand the syntax, specifically, using the Locator option to allow the 'drag and drop', check out the instructions for Manipulate under 'more information'.

The end product can be recorded as a stand-alone video, such as the one below.


Observe why it is always optimal for the firms' to locate at the opposite ends of the market: moving towards the competitor hardly increases one's share of the market, as it prompts the rival to respond with more aggressive pricing, pushing the profits of both firms down. Easy.