Skip to content

Commit

Permalink
tidy notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jhconning committed Jan 27, 2016
1 parent 0d91775 commit c9e3503
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 369 deletions.
7 changes: 5 additions & 2 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ Notes and support materials for The Graduate
Center's `Economics 842:`_ taught by Jonathan Conning


Please note that this is very much a draft of work in progress. Some of
the sections of the documents that follow are *very* preliminar.
Please note that this is very much work in progress; not much
more than a collection of notebook fragments. Some of
the sections of the documents that follow are *very* preliminary
and several code blocks may be broken. Over time this will get cleaned
and more content posted.

.. toctree::
:maxdepth: 3
Expand Down
298 changes: 9 additions & 289 deletions notebooks/Harris_Todaro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### The model\n",
"\n",
"This model is an adaptation of a standard two-sector open economy specific factors model (SFM) of migration. \n",
"* The two sectors are agriculture and 'modern-manufacturing'\n",
"* The agricultural labor market is competitive. Labor is mobile between the agricultural and manufacturing sectors. \n",
Expand Down Expand Up @@ -62,30 +60,14 @@
"source": [
"For given wage $w$ labor demand in manufacturing is:\n",
"\n",
"$$L_m(w) = \\left [ { \\frac{A_m (1-\\alpha) \\bar K}{w/P_m} } \\right ]^\\frac{1}{\\alpha} $$\n",
"\n",
"\n",
"\n",
"$$L_a + L_m + L_u= \\bar{L}$$\n",
"For the numeric simulations below we make the further assumption that each sector uses a CRS Cobb-Douglas production function:\n",
"$$F(T_a, L_a)=\\bar T_a^{(1-\\alpha)} \\cdot L_a^\\alpha$$\n",
"$$G(K_m, L_m)=\\bar K_m^{(1-\\beta)} \\cdot L_m^\\beta$$"
"$$L_m(w) = \\left [ { \\frac{A_m (1-\\alpha) \\bar K}{w/P_m} } \\right ]^\\frac{1}{\\alpha} $$\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### What follows is NOT DONE"
"### Graphical Analysis (not finished)"
]
},
{
Expand Down Expand Up @@ -201,15 +183,6 @@
"TOOLS = \"resize,reset,save,box_select\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -249,7 +222,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Equilibrium allocations\n",
"Let's plot a standard specific factors diagram showing the equilibrium wage and labor allocations."
]
},
Expand All @@ -274,6 +246,13 @@
"Lm = Lbar - La"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Numerical optimization to solve the model"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -457,265 +436,6 @@
"show(rv)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PPF plot\n",
"We can plot the associated production possibility frontier. \n",
"It will be useful to draw this as a paremetric plot by defining QM(La) and QA(La) and create a new columndatasource."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"QA = lambda La: (Tbar**(1-alpha) * La**alpha)\n",
"QM = lambda La: Kbar**(1-beta) * (Lbar - La)**beta"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'eqn' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-8-d253556e7f85>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mLA\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mweq\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0meqn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpMPLa\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mMPLm\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mpriceline\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mQM\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mLA\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mp\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mQA\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mLA\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m \u001b[0mp\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mQA\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mLa\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m ppfsource = ColumnDataSource(data=dict(\n\u001b[0;32m 4\u001b[0m \u001b[0mQA\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mQA\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mLa\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mQM\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mQM\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mLa\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'eqn' is not defined"
]
}
],
"source": [
"LA, weq = eqn(pMPLa, MPLm)\n",
"priceline = (QM(LA)+p*QA(LA))- p*QA(La)\n",
"ppfsource = ColumnDataSource(data=dict(\n",
" QA = QA(La), \n",
" QM = QM(La), \n",
" priceline = priceline\n",
" ) )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"titletxt = \"PPF\"\n",
"ppf = figure(title=titletxt, tools=TOOLS,width=500, height=500)\n",
"ppf.x_range = Range1d(0, max(Qa)*1.25)\n",
"ppf.y_range = Range1d(0, max(Qa)*1.25)\n",
"ppf.line('QA','QM', source=ppfsource, line_width=3)\n",
"ppf.circle(QA(LA), QM(LA), size=10)\n",
"ppf.line('QA','priceline', source=ppfsource, line_width=1, line_dash=[4, 4])\n",
"ppf.xaxis.axis_label = 'Qa'\n",
"ppf.yaxis.axis_label = 'Qm'\n",
"\n",
"print(\"At Pa/Pm ={0:5.2f} country produces:\".format(p))\n",
"print(\" Qa ={0:5.0f}, Qm ={1:5.0f} \".format(QA(LA), QM(LA)))\n",
"show(ppf) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Interactive Plots\n",
"We'll use the slider from the ipywidgets library for Ipython working with Bokeh's ability to refresh a graph when a ColumnDataSource is refreshed.\n",
"First we define a plot again but this time also give Bokeh a data source that can be refreshed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"LA, weq = eqn(pMPLa, MPLm)\n",
"\n",
"weqLine = (np.ones(LbarMax)*weq) * (La<Lbar) # we will use this to plot equilibrium wage\n",
"\n",
"sourceRV = ColumnDataSource(data=dict(\n",
" La = La, \n",
" pMPLa = pMPLa, \n",
" MPLm = MPLm,\n",
" weqLine = weqLine\n",
" ) )\n",
"\n",
"rvs = figure(tools=TOOLS, title='Ricardo-Viner', width=600, height=400)\n",
"rvs.x_range = Range1d(0, LbarMax)\n",
"rvs.y_range = Range1d(0, ymax)\n",
"rvs.line('La', 'pMPLa',line_width=3, source=sourceRV,legend=\"Agric. LD\")\n",
"rvs.line('La', 'MPLm', line_width=3, source=sourceRV, color='red',legend=\"Manuf. LD\")\n",
"rvs.line('La', 'weqLine', line_width=1, line_dash=[4, 4], source=sourceRV, color='black')\n",
"rvs.xaxis.axis_label = 'Labor'\n",
"rvs.xaxis.axis_label_text_font_size = \"12pt\"\n",
"rvs.yaxis.axis_label = r'Real wage'\n",
"rvs.yaxis.axis_label_text_font_size = \"12pt\"\n",
"rvs.legend.orientation = \"top_right\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This next function takes slider values for $\\bar L$ and $p=\\frac{P_a}{P_m}$, updates the curves to be plotted and pushes those values to later Bokeh plots' data 'source' for a refresh. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def updateRV(Lbar=LbarMax, p=1, Tbar=100,Kbar=100,):\n",
" Qa = (Tbar**(1-alpha) * La**alpha) * (La<Lbar)\n",
" Qm = Kbar**(1-beta) * (Lbar - La)**beta\n",
" pMPLa = (p * alpha * Qa/La) *(La<Lbar) \n",
" MPLm = beta * Qm/(Lbar-La)\n",
" \n",
" LA, weq = eqn(pMPLa, MPLm)\n",
" weqLine = (np.ones(LbarMax)*weq) * (La<Lbar) \n",
" \n",
" QA = (Tbar**(1-alpha) * LA**alpha)\n",
" QM = Kbar**(1-beta) * (Lbar - LA)**beta\n",
" sourceRV.data['MPLm'] = MPLm\n",
" sourceRV.data['pMPLa'] = pMPLa\n",
" sourceRV.data['weqLine'] = weqLine \n",
" sourceRV.push_notebook()\n",
" print(\"Equilibrium wages: ( w/Pm ={0:5.2f}, w/Pa ={1:5.2f} )\".format(weq, weq/p))\n",
" print(\"Labor and output : ( La ={0:5.0f}, Lm ={1:5.0f} ), \\\n",
" (Qa = {2:5.0f}, Qm = {3:5.0f}) \".format(LA, Lbar-LA, QA, QM))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's display the plot and follow that by a slider."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"rvs.plot_width=500\n",
"show(rvs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"interact(updateRV,Lbar=(100, LbarMax, 50), p =(0.25,2,0.25), Tbar=(50, 200, 50), Kbar=(50, 200, 50))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Two synchronized plots\n",
"Let's try to show the labor allocation and PPF plots side by side and responsive to the same slider. For this we are going to setup two data sources, one for each plot. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def updateBoth(Lbar=LbarMax, p=1, Tbar=100,Kbar=100,):\n",
" Qa = (Tbar**(1-alpha) * La**alpha) * (La<Lbar)\n",
" Qm = Kbar**(1-beta) * (Lbar - La)**beta\n",
" pMPLa = (p * alpha * Qa/La) *(La<Lbar) \n",
" MPLm = beta * Qm/(Lbar-La)\n",
" \n",
" LA, weq = eqn(pMPLa, MPLm)\n",
" weqLine = (np.ones(LbarMax)*weq) * (La<Lbar) \n",
" \n",
" sourceRV.data['MPLm'] = MPLm\n",
" sourceRV.data['pMPLa'] = pMPLa\n",
" sourceRV.data['weqLine'] = weqLine \n",
" sourceRV.push_notebook()\n",
" \n",
" QA = lambda La: (Tbar**(1-alpha) * La**alpha)\n",
" QM = lambda La: Kbar**(1-beta) * (Lbar - La)**beta\n",
" priceline = (QM(LA)+p*QA(LA)) - p*QA(La)\n",
" \n",
" ppfsource.data['QA'] = QA(La)\n",
" ppfsource.data['QM'] = QM(La)\n",
" ppfsource.data['priceline'] = priceline \n",
" ppfsource.push_notebook()\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As of 10/1/15 THe plots that follow are not quite working.\n",
"\n",
"Major issue: only the RV plot is updating... PPF plot is not changed, not sure why.\n",
"Minor: need to rescale to fit the two plots side by side."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ppf2=ppf\n",
"rvs2=rvs\n",
"\n",
"ppf2.plot_height=350\n",
"ppf2.plot_width=350\n",
"rvs2.plot_height=350\n",
"rvs2.plot_width=350\n",
"show(vplot(hplot(ppf, rvs,)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"interact(updateBoth,Lbar=(100, LbarMax, 50), p =(0.25,2,0.25), Tbar=(50, 200, 50), Kbar=(50, 200, 50))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit c9e3503

Please sign in to comment.