{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Load needed libraries\n", "\n", "%matplotlib inline\n", "\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "OECD = pd.read_csv('data/OECD_Productivity.csv')\n", "OECD.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = OECD.copy()\n", "\n", "countries = OECD['Country'].unique()\n", "locs = OECD['LOCATION'].unique()\n", "\n", "df = df.loc[df['Subject'].isin(('GDP per hour worked', 'Average hours worked per person employed'))]\n", "\n", "df = df.loc[df['Measure'].isin(('USD, constant prices, 2010 PPPs', 'Persons/Hours'))]\n", "\n", "df = df[['LOCATION', 'Subject', 'Time', 'Value']]\n", "\n", "# Set MultiIndex; can choose ordering\n", "df.set_index(['Subject', 'LOCATION', 'Time'], inplace=True)\n", "\n", "# Create nested columns\n", "df = df.unstack(0)\n", "\n", "# Remove one unnecessary level of naming\n", "df = df['Value']\n", "\n", "df.columns = ['h', 'y_h']\n", "\n", "df['cntr'] = df.index.get_level_values(0)\n", "\n", "# Show prepared dataset\n", "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = df['h']\n", "y = df['y_h']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.scatter(x, y, alpha=0.2, label='All countries')\n", "plt.scatter(x['KOR'], y['KOR'], color='C2', alpha=0.3, label='Korea')\n", "plt.scatter(x['POL'], y['POL'], color='C3', alpha=0.3, label='Poland')\n", "\n", "plt.legend(frameon=False)\n", "\n", "plt.title('GDP per hour vs average hours worked')\n", "plt.xlabel('Average hours worked per employee')\n", "plt.ylabel('GDP per hour (constant 2010 PPP USD)')\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for loc in locs[:9]:\n", " plt.scatter(np.log(x[loc]), np.log(y[loc]), alpha=0.2, label=loc)\n", "\n", "plt.legend(frameon=False, ncol=2)\n", "\n", "plt.title('GDP per hour vs average hours worked')\n", "plt.ylabel('Average hours worked per employee')\n", "plt.xlabel('GDP per hour (constant 2010 PPP USD)')\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Utility maximization problem\n", "\\begin{align*}\n", "\\max_{c,\\,h}\\quad & U=\\frac{c^{1-\\sigma}}{1-\\sigma}-\\phi\\frac{h^{1+\\kappa}}{1+\\kappa}\\\\\n", "\\text{subject to}\\quad & y=Ah^{1-\\alpha}\\\\\n", " & c=y\n", "\\end{align*}\n", "\n", "Lagrangian\n", "\\begin{align*}\n", "\\mathcal{L}&=\\frac{c^{1-\\sigma}}{1-\\sigma}-\\phi\\frac{h^{1+\\kappa}}{1+\\kappa}+\\lambda\\left[Ah^{1-\\alpha}-c\\right]\n", "\\end{align*}\n", "\n", "FOCs\n", "\\begin{eqnarray*}\n", "c & : & c^{-\\sigma}-\\lambda=0\\\\\n", "h & : & -\\phi h^{\\kappa}+\\lambda\\left(1-\\alpha\\right)Ah^{-\\alpha}=0\n", "\\end{eqnarray*}\n", "\n", "Optimality condition\n", "\\begin{align*}\n", "\\left(1-\\alpha\\right)Ah^{-\\alpha}c^{-\\sigma}=\\phi h^{\\kappa}\n", "\\end{align*}\n", "\\begin{align*}\n", "c&=\\left[\\frac{\\phi}{\\left(1-\\alpha\\right)A}h^{\\alpha+\\kappa}\\right]^{-\\frac{1}{\\sigma}}&=\\left[\\frac{\\left(1-\\alpha\\right)A}{\\phi}\\right]^{\\frac{1}{\\sigma}}h^{-\\frac{\\alpha+\\kappa}{\\sigma}}\n", "\\end{align*}\n", "Plug into budget constraint and solve for optimal $h$\n", "\\begin{align*}\n", "\\left[\\frac{\\left(1-\\alpha\\right)A}{\\phi}\\right]^{\\frac{1}{\\sigma}}h^{-\\frac{\\alpha+\\kappa}{\\sigma}}&=Ah^{1-\\alpha}\n", "\\end{align*}\n", "\\begin{align*}\n", "h^{-\\frac{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}{\\sigma}}&=A^{\\frac{\\sigma-1}{\\sigma}}\\left(\\frac{\\phi}{1-\\alpha}\\right)^{\\frac{1}{\\sigma}}\n", "\\end{align*}\n", "\\begin{align*}\n", "h&=A^{\\frac{1-\\sigma}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}}\\left(\\frac{1-\\alpha}{\\phi}\\right)^{\\frac{1}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}}\n", "\\end{align*}\n", "\\begin{align*}\n", "\\ln h&=\\frac{1-\\sigma}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\ln A+\\frac{1}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\ln\\left(\\frac{1-\\alpha}{\\phi}\\right)\n", "\\end{align*}\n", "\n", "Rewrite above in terms of labor productivity $y/h$\n", "\\begin{align*}\n", "\\frac{y}{h}&=Ah^{-\\alpha}\n", "\\end{align*}\n", "\\begin{align*}\n", "\\ln\\left(y/h\\right)&=\\ln A-\\alpha\\ln h\n", "\\end{align*}\n", "\\begin{align*}\n", "\\ln A&=\\ln\\left(y/h\\right)+\\alpha\\ln h\n", "\\end{align*}\n", "\\begin{align*}\n", "\\ln h&=\\frac{1-\\sigma}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\left[\\ln\\left(y/h\\right)+\\alpha\\ln h\\right]+\\frac{1}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\ln\\left(\\frac{1-\\alpha}{\\phi}\\right)\n", "\\end{align*}\n", "\\begin{align*}\n", "\\left(1-\\frac{\\alpha-\\alpha\\sigma}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\right)\\ln h&=\\frac{1-\\sigma}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\ln\\left(y/h\\right)+\\frac{1}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\ln\\left(\\frac{1-\\alpha}{\\phi}\\right)\n", "\\end{align*}\n", "\\begin{align*}\n", "\\left(\\frac{\\kappa+\\sigma}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\right)\\ln h&=\\frac{1-\\sigma}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\ln\\left(y/h\\right)+\\frac{1}{\\alpha+\\kappa+\\sigma\\left(1-\\alpha\\right)}\\ln\\left(\\frac{1-\\alpha}{\\phi}\\right)\n", "\\end{align*}\n", "\n", "End result\n", "\\begin{align*}\n", "\\ln h&=\\frac{1-\\sigma}{\\kappa+\\sigma}\\ln\\left(y/h\\right)+\\frac{1}{\\kappa+\\sigma}\\ln\\left(\\frac{1-\\alpha}{\\phi}\\right)\n", "\\end{align*}\n", "\\begin{align*}\n", "\\frac{\\partial\\ln h}{\\partial\\ln\\left(y/h\\right)}&=\\frac{1-\\sigma}{\\kappa+\\sigma}\n", "\\end{align*}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import statsmodels.formula.api as smf\n", "\n", "# Exclude Korea as outlier\n", "df_no_Korea = df[df['cntr'] != 'KOR']\n", "\n", "results = smf.ols('np.log(h) ~ np.log(y_h) + C(cntr, Treatment(\"OECD\"))', data=df_no_Korea).fit()\n", "\n", "results.summary()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "elasticity = results.params[-1]\n", "intercept = results.params[0]\n", "\n", "print(elasticity)\n", "\n", "country_effects = results.params[1:-1]\n", "country_effects.index = [e[29:-1] for e in country_effects.index]\n", "\n", "# country_effects.index" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "country_effects.sort_values().plot(kind='bar', color='C0', figsize=(10,5))\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "country_effects.sort_values()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }