{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# FUNCTION FOR CALCULATING AND GRAPHING THE LEVELS OF \n", "# SOLOW GROWTH MODEL VARIABLES IN SIMULATIONS\n", "#\n", "# might as well put \"check that common libraries are active\" as a default header\n", "# in every long python code cell...\n", "\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import scipy as sp\n", "import numpy as np\n", "%matplotlib inline\n", "\n", "# we are going to want to see what happens for lots of\n", "# different model parameter values and base conditions,\n", "# so stuff our small simulation program inside a function, so \n", "# we can then invoke it with a single line...\n", "#\n", "# we are going to assume the economy starts on its base\n", "# balanced growth path...\n", "#\n", "# we are going to want to keep track not just of what the\n", "# economy's variables are at each point in time, but also \n", "# what the base and alternative balanced-growth path \n", "# values of variables are. Given the parameters, the new BGP \n", "# is attracting the economy to it at the speed (1-α)(n+g+δ), \n", "# closing that fraction of the gap between its current state \n", "# and the balanced growth path attractor every period...\n", "\n", "def sgm_3_bgp_100yr_run(L0, E0, n=0.01, g=0.015, s=0.20, \n", " alpha=0.5, delta=0.025, Delta_s=0, Delta_g=0, Delta_n=0, \n", " T = 100, graphs=\"LEVELS\"):\n", "\n", " sg_df = pd.DataFrame(index=range(T),columns=['Labor', \n", " 'Efficiency',\n", " 'Capital',\n", " 'Output',\n", " 'Output_per_Worker',\n", " 'Capital_Output_Ratio',\n", " 'BGP_base_Labor',\n", " 'BGP_base_Efficiency',\n", " 'BGP_base_Output',\n", " 'BGP_base_Output_per_Worker',\n", " 'BGP_base_Capital_Output_Ratio',\n", " 'BGP_base_Capital',\n", " 'BGP_alt_Labor',\n", " 'BGP_alt_Efficiency',\n", " 'BGP_alt_Output',\n", " 'BGP_alt_Output_per_Worker',\n", " 'BGP_alt_Capital_Output_Ratio',\n", " 'BGP_alt_Capital'],\n", " dtype='float')\n", "\n", " sg_df.Labor[0] = L0\n", " sg_df.BGP_base_Labor[0] = L0\n", " sg_df.BGP_alt_Labor[0] = L0\n", " sg_df.Efficiency[0] = E0\n", " sg_df.BGP_base_Efficiency[0] = E0\n", " sg_df.BGP_alt_Efficiency[0] = E0\n", "\n", " KoverY_base_steady_state = s/(n+g+delta)\n", " YoverL_base_steady_state = ((s/(n+g+delta))**(alpha/(1-alpha)) \n", " * E0)\n", " KoverL_base_steady_state = (YoverL_base_steady_state *\n", " KoverY_base_steady_state)\n", " \n", " sg_df.Capital[0] = KoverL_base_steady_state * L0\n", " sg_df.Output[0] = (sg_df.Capital[0]**alpha * (sg_df.Labor[0] * \n", " sg_df.Efficiency[0])**(1-alpha))\n", " sg_df.Output_per_Worker[0] = sg_df.Output[0]/sg_df.Labor[0]\n", " sg_df.Capital_Output_Ratio[0] = sg_df.Capital[0]/sg_df.Output[0]\n", " \n", " sg_df.BGP_base_Capital_Output_Ratio[0] = (s / (n + g + delta))\n", " sg_df.BGP_base_Output_per_Worker[0] = sg_df.Efficiency[0] * (\n", " sg_df.BGP_base_Capital_Output_Ratio[0]*(alpha/(1 - alpha)))\n", " sg_df.BGP_base_Output[0] = sg_df.BGP_base_Output_per_Worker[0] * sg_df.Labor[0]\n", " sg_df.BGP_base_Capital[0] = sg_df.BGP_base_Output[0] * (\n", " sg_df.BGP_base_Capital_Output_Ratio[0])\n", " \n", " sg_df.BGP_alt_Capital_Output_Ratio[0] = ((s + Delta_s) / \n", " (n + Delta_n + g + Delta_g + delta))\n", " sg_df.BGP_alt_Output_per_Worker[0] = sg_df.Efficiency[0] * (\n", " sg_df.BGP_alt_Capital_Output_Ratio[0]*(alpha/(1 - alpha)))\n", " sg_df.BGP_alt_Output[0] = sg_df.BGP_alt_Output_per_Worker[0] * sg_df.Labor[0]\n", " sg_df.BGP_alt_Capital[0] = sg_df.BGP_alt_Output[0] * (\n", " sg_df.BGP_alt_Capital_Output_Ratio[0])\n", " \n", " for i in range(T):\n", " sg_df.Labor[i+1] = (sg_df.Labor[i] * np.exp(n + Delta_n))\n", " sg_df.Efficiency[i+1] = (sg_df.Efficiency[i] * np.exp(g + Delta_g))\n", " KoverY_current = sg_df.Capital[i]/sg_df.Output[i]\n", " sg_df.Capital[i+1] = (sg_df.Capital[i] * np.exp((s+Delta_s)/ \n", " KoverY_current - delta))\n", " sg_df.Output[i+1] = (sg_df.Capital[i+1]**alpha * \n", " (sg_df.Labor[i+1] * sg_df.Efficiency[i+1])**(1-alpha))\n", " sg_df.Output_per_Worker[i+1] = sg_df.Output[i+1]/sg_df.Labor[i+1]\n", " sg_df.Capital_Output_Ratio[i+1] = (sg_df.Capital[i+1]/\n", " sg_df.Output[i+1])\n", "\n", " for i in range(T):\n", " sg_df.BGP_base_Labor[i+1] = (sg_df.BGP_base_Labor[i] * np.exp(n))\n", " sg_df.BGP_base_Efficiency[i+1] = (sg_df.BGP_base_Efficiency[i] * np.exp(g))\n", " sg_df.BGP_base_Capital_Output_Ratio[i+1] = (s / (n + g + delta))\n", " sg_df.BGP_base_Output_per_Worker[i+1] = sg_df.BGP_base_Efficiency[i+1] * (\n", " sg_df.BGP_base_Capital_Output_Ratio[i+1]**(alpha/(1 - alpha)))\n", " sg_df.BGP_base_Output[i+1] = (sg_df.BGP_base_Output_per_Worker[i+1] * \n", " sg_df.BGP_base_Labor[i+1])\n", " sg_df.BGP_base_Capital[i+1] = (s / (n + g + delta))**(1/(1-alpha)) * (\n", " sg_df.Efficiency[i+1] * sg_df.Labor[i+1])\n", "\n", " for i in range(T):\n", " sg_df.BGP_alt_Labor[i+1] = (sg_df.BGP_alt_Labor[i] * np.exp(n + Delta_n))\n", " sg_df.BGP_alt_Efficiency[i+1] = (sg_df.BGP_alt_Efficiency[i] * np.exp(g+Delta_g))\n", " sg_df.BGP_alt_Capital_Output_Ratio[i+1] = ((s+ Delta_s) / \n", " (n + Delta_n + g + Delta_g + delta))\n", " sg_df.BGP_alt_Output_per_Worker[i+1] = sg_df.BGP_alt_Efficiency[i+1] * (\n", " sg_df.BGP_alt_Capital_Output_Ratio[i+1]**(alpha/(1 - alpha)))\n", " sg_df.BGP_alt_Output[i+1] = (sg_df.BGP_alt_Output_per_Worker[i+1] * \n", " sg_df.BGP_alt_Labor[i+1])\n", " sg_df.BGP_alt_Capital[i+1] = ((s + Delta_s) / (n + Delta_n + g + Delta_g + delta))**(1/(1-alpha)) * (\n", " sg_df.BGP_alt_Efficiency[i+1] * sg_df.BGP_alt_Labor[i+1]) \n", " \n", " if (graphs == \"LEVELS\"):\n", " fig = plt.figure(figsize=(12, 12))\n", "\n", " ax1 = plt.subplot(2,3,1)\n", " sg_df.BGP_base_Labor.plot(ax = ax1, title = \"BGP (base) Labor\")\n", " sg_df.BGP_alt_Labor.plot(ax = ax1, title = \"BGP (alt) Labor\")\n", " sg_df.Labor.plot(ax = ax1, title = \"Labor Force\")\n", " plt.ylabel(\"Values\")\n", " plt.ylim(0, )\n", "\n", " ax2 = plt.subplot(2,3,2)\n", " sg_df.BGP_base_Efficiency.plot(ax = ax2, title = \"BGP (base) Efficiency\")\n", " sg_df.BGP_alt_Efficiency.plot(ax = ax2, title = \"BGP (alt) Efficiency\")\n", " sg_df.Efficiency.plot(ax = ax2, title = \"Efficiency of Labor\")\n", " plt.ylim(0, )\n", " \n", " ax3 = plt.subplot(2,3,3)\n", " sg_df.BGP_base_Capital.plot(ax = ax3, title = \"BGP (base) Capital Stock\")\n", " sg_df.BGP_alt_Capital.plot(ax = ax3, title = \"BGP (alt) Capital Stock\")\n", " sg_df.Capital.plot(ax = ax3, title = \"Capital Stock\")\n", " plt.ylim(0, )\n", "\n", " ax4 = plt.subplot(2,3,4)\n", " sg_df.BGP_base_Output.plot(ax = ax4, title = \"BGP (base) Output\")\n", " sg_df.BGP_alt_Output.plot(ax = ax4, title = \"BGP (alt) Output\")\n", " sg_df.Output.plot(ax = ax4, title = \"Output\")\n", " plt.ylabel(\"Values\")\n", " plt.xlabel(\"Years\")\n", " plt.ylim(0, )\n", "\n", " ax5 = plt.subplot(2,3,5)\n", " sg_df.BGP_base_Output_per_Worker.plot(ax = ax5, title = \"BGP (base) Output per Worker\")\n", " sg_df.BGP_alt_Output_per_Worker.plot(ax = ax5, title = \"BGP (alt) Output per Worker\")\n", " sg_df.Output_per_Worker.plot(ax = ax5, title = \"Output per Worker\")\n", " plt.xlabel(\"Years\")\n", " plt.ylim(0, )\n", "\n", " ax6 = plt.subplot(2,3,6)\n", " sg_df.BGP_base_Capital_Output_Ratio.plot(ax = ax6, \n", " title = \"BGP (base) Capital-Output Ratio\")\n", " sg_df.BGP_alt_Capital_Output_Ratio.plot(ax = ax6, \n", " title = \"BGP (alt) Capital-Output Ratio\")\n", " sg_df.Capital_Output_Ratio.plot(ax = ax6, \n", " title = \"Capital-Output Ratio\")\n", " plt.xlabel(\"Years\")\n", " plt.ylim(0, )\n", "\n", " plt.suptitle('Solow Growth Model: Levels: Simulation Run', size = 20)\n", "\n", " plt.show()\n", " \n", " if (graphs == \"LOGS\"):\n", " fig = plt.figure(figsize=(12, 12))\n", "\n", " ax1 = plt.subplot(2,3,1)\n", " np.log(sg_df.BGP_base_Labor).plot(ax = ax1, title = \"BGP (base) Labor\")\n", " np.log(sg_df.BGP_alt_Labor).plot(ax = ax1, title = \"BGP (alt) Labor\")\n", " np.log(sg_df.Labor).plot(ax = ax1, title = \"Log Labor Force\")\n", " plt.ylabel(\"Values\")\n", " plt.ylim(0, )\n", "\n", " ax2 = plt.subplot(2,3,2)\n", " np.log(sg_df.BGP_base_Efficiency).plot(ax = ax2, title = \"BGP (base) Efficiency\")\n", " np.log(sg_df.BGP_alt_Efficiency).plot(ax = ax2, title = \"BGP (alt) Efficiency\")\n", " np.log(sg_df.Efficiency).plot(ax = ax2, title = \"Log Efficiency of Labor\")\n", " plt.ylim(0, )\n", " \n", " ax3 = plt.subplot(2,3,3)\n", " np.log(sg_df.BGP_base_Capital).plot(ax = ax3, title = \"BGP (base) Capital Stock\")\n", " np.log(sg_df.BGP_alt_Capital).plot(ax = ax3, title = \"BGP (alt) Capital Stock\")\n", " np.log(sg_df.Capital).plot(ax = ax3, title = \"Log Capital Stock\")\n", " plt.ylim(0, )\n", "\n", " ax4 = plt.subplot(2,3,4)\n", " np.log(sg_df.BGP_base_Output).plot(ax = ax4, title = \"BGP (base) Output\")\n", " np.log(sg_df.BGP_alt_Output).plot(ax = ax4, title = \"BGP (alt) Output\")\n", " np.log(sg_df.Output).plot(ax = ax4, title = \"Log Output\")\n", " plt.ylabel(\"Values\")\n", " plt.xlabel(\"Years\")\n", " plt.ylim(0, )\n", "\n", " ax5 = plt.subplot(2,3,5)\n", " np.log(sg_df.BGP_base_Output_per_Worker).plot(ax = ax5, title = \"BGP (base) Output per Worker\")\n", " np.log(sg_df.BGP_alt_Output_per_Worker).plot(ax = ax5, title = \"BGP (alt) Output per Worker\")\n", " np.log(sg_df.Output_per_Worker).plot(ax = ax5, title = \"Log Output per Worker\")\n", " plt.xlabel(\"Years\")\n", " plt.ylim(0, )\n", "\n", " ax6 = plt.subplot(2,3,6)\n", " sg_df.BGP_base_Capital_Output_Ratio.plot(ax = ax6, \n", " title = \"BGP (base) Capital-Output Ratio\")\n", " sg_df.BGP_alt_Capital_Output_Ratio.plot(ax = ax6, \n", " title = \"BGP (alt) Capital-Output Ratio\")\n", " sg_df.Capital_Output_Ratio.plot(ax = ax6, \n", " title = \"Capital-Output Ratio\")\n", " plt.xlabel(\"Years\")\n", " plt.ylim(0, )\n", "\n", " plt.suptitle('Solow Growth Model: Logs: Simulation Run', size = 20)\n", "\n", " plt.show()\n", " \n", " if ((graphs != \"LEVELS\") and (graphs != \"LOGS\")):\n", " fig = \"NONE\"\n", " \n", " print(\"The blue line is the initial balanced-growth path;\")\n", " print(\"the orange line is the alternative balanced growth path;\")\n", " print(\"the green line is the track of the economy as it transitions\")\n", " print(\"from the baseline to the alternative BGP.\")\n", " print(\" \")\n", " \n", " print(n + Delta_n, \"is the baseline labor-force growth rate\")\n", " print(g + Delta_g, \"is the baseline efficiency-of-labor growth rate\")\n", " print(s + Delta_s, \"is the baseline savings rate\")\n", " print(\" \")\n", " \n", " print(n + Delta_n, \"is the alternative labor-force growth rate\")\n", " print(g + Delta_g, \"is the alternative efficiency-of-labor growth rate\")\n", " print(s + Delta_s, \"is the alternative savings-investment rate\")\n", " print(\" \")\n", " \n", " print(delta, \"is the depreciation rate\")\n", " print(alpha, \"is the orientation-of-growth-toward-capital parameter\")\n", " \n", " SGM_dict = {}\n", " SGM_dict[\"df\"] = sg_df\n", " SGM_dict[\"plots\"] = fig\n", " \n", " return SGM_dict" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }