{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "\n", "

This worksheet will illustrate all the calculations in the directed search reading for the case where there is complete information.  The first is the basic equation

\n", "

$$\\pi w_1 /2+(1-\\pi)w_1=\\pi w_2+(1-\\pi)w_2 /2$$

\n", "

The solution to this equation makes both workers indfferent about whether they apply to firm 1 or firm 2.

" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 2, "metadata": { }, "output_type": "execute_result" } ], "source": [ "var('pi,w_1,w_2')\n", "eq1 = pi*w_1/2+(1-pi)*w_1 == pi*w_2+(1-pi)*w_2/2\n", "prob = solve(eq1,pi)\n", "show(prob)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "\n", "

If your formula is right, then the solution should be $1/2$ when the wages are the same.

" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 3, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(solve(eq1.substitute(w_1=w_2),pi))" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "\n", "

We now need access to the first solution to $\\pi$.  To find it, you treat the solution as if it were an array because most equations have more than one solution.  In this case, there is only one solution, so we use element $0$.  You can substitute this into other equations.

\n", "

We'll do this by definining the profit function of firm 1.  This profit is given by

\n", "

$$(1-(1-\\pi)^2)(y_1-w_1)$$

\n", "

as we discussed in class.

\n", "

 

\n", "

We can also take the derivative of this profit function to try to find the best reply function.

" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 8, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 8, "metadata": { }, "output_type": "execute_result" } ], "source": [ "var('y_1,y_2')\n", "Profit = ((1-(1-prob[0])^2))*(y_1-w_1)\n", "show(Profit)\n", "der = Profit.derivative(w_1)\n", "show(der)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "\n", "

Now use the right hand side of the derivative and set it to zero, then solve for $w_1$.

" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 9, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 9, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 9, "metadata": { }, "output_type": "execute_result" } ], "source": [ "eq2 = der.rhs() == 0\n", "show(eq2)\n", "br = solve(eq2,w_1)\n", "show(br)\n", "show(br[0])" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "Now we can do a very similar thing for firm $2$." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 17, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 17, "metadata": { }, "output_type": "execute_result" } ], "source": [ "Prof_2 = ((1-(prob[0])^2))*(y_2-w_2)\n", "show(Prof_2)\n", "der_2 = Prof_2.derivative(w_2)\n", "show(der_2) " ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "Again, we can find the best reply function for firm 2 by finding the value for $w_2$ for each value of $w_1$ that makes the derivative zero." ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 28, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 28, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 28, "metadata": { }, "output_type": "execute_result" } ], "source": [ "eq3 = der_2.rhs() == 0\n", "show(eq3)\n", "br_2 = solve(eq3,w_1)\n", "show(br_2)\n", "show(br_2[1])" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "

Notice that when I 'solved' the first order condition, instead of solving for $w_2$, which would tell us firm 2's best reply to each $w_1$, I solved for $w_1$. What that gives is the inverse of firm 2's best reply function (for each $w_2$, it gives the value for $w_1$ such that $w_2$ is a best reply.) This ensures that it provides the curve as the inverse image as we did for the picture we drew in class.

" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "In the next step we'll just plot the two best reply functions to look for their intersection. To do this, I substitute the value $y_1 =1$ and $w_2 = \\frac{3}{4}$, so that firm 2 is less productive. The equilibrium should then have the property that the equilibrium wage for firm 2 is less than it is for firm 1. To help show this, I also draw the $45^o$ line ($w_1 = w_2$). As you can see, the point where the lines cross has $w_1 > w_2$.\n", "\n", "\n", "Notice that there were two solutions for the best reply function, and that I used the second one. Make sure you check what happens when you use the first solution instead." ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: Some output was deleted.\n" ] } ], "source": [ "plot(br[0].rhs().substitute(y_1=1),(w_2,0,1),color=\"red\")+plot(br_2[1].rhs().substitute(y_2=3/4),(w_2,0,1),color=\"green\")+plot(w_2,(w_2,0,1),color=\"black\",linestyle='dashed')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "\n", "

As a last step, find the equilibrium by finding the wage that is a best reply to itself.  What that means is that both firms will be best replying to the other firm if they both use this wage.

\n", "\n", "\n", "The inverse function has a square root in it, which will make finding an algebraic solution difficult (if you try it, you'll get an implicit solution). So instead, we'll calculate the intersection point using numerical methods. Just to make sure, we can solve the numerical equation again for the case where $y_1 = y_2 = 1$ in which case we already know from previous calculations that $w_1$ and $w_2$ should both be equal to $\\frac{1}{2}$. That will give a simple check that our coding is correct." ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 33, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 33, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 33, "metadata": { }, "output_type": "execute_result" }, { "data": { "text/html": [ "" ] }, "execution_count": 33, "metadata": { }, "output_type": "execute_result" } ], "source": [ "show(br[0].rhs().substitute(y_1=1))\n", "show(br_2[1].rhs().substitute(y_2=(3/4)))\n", "eq4 = br[0].rhs().substitute(y_1=1) == br_2[1].rhs().substitute(y_2=(3/4))\n", "show(eq4.find_root(.2,1))\n", "eq5 = br[0].rhs().substitute(y_1=1) == br_2[1].rhs().substitute(y_2=1)\n", "show(eq5.find_root(.2,1))" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "Notice that the root of the second equation is pretty close to .5." ] } ], "metadata": { "kernelspec": { "display_name": "SageMath (stable)", "language": "sagemath", "metadata": { "cocalc": { "description": "Open-source mathematical software system", "priority": 10, "url": "https://www.sagemath.org/" } }, "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.15" } }, "nbformat": 4, "nbformat_minor": 0 }