Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
1 lines (1 sloc) 8.91 KB
{"nbformat_minor": 0, "nbformat": 4, "cells": [{"source": ["# Data Bootcamp: Economic indicators \n", "\n", "We explore two kinds of economic indicators: \n", "\n", "* **Business cycle indicators.** Here we look at a number of different measures of current economic activity. We do this for the US, but similar methods are used in other countries. We use monthly indicators, which give us a picture of the current state of the economy, and generally do it more quickly than waiting for quarterly data on aggregate GDP. \n", "\n", "* **Country indicators.** Here the goal is to assess the economic and business climate in a country for a specific business opportunity. Should we locate a [business analytics startup](https://github.com/DaveBackus/Global_Economy/blob/master/Cases/case_ba-in-eu.pdf) in Barcelona, Paris, or Stockholm? Should we open a [new factory](https://github.com/DaveBackus/Global_Economy/blob/master/Cases/case_foxconn.pdf) in China, Thailand, or Vietnam? Should we expand a [meat production and retail operation](https://github.com/DaveBackus/Global_Economy/blob/master/Cases/case_zambeef.pdf) beyond [Zambia](https://www.google.com/maps/place/Zambia/@-12.9826533,18.8129711,5z/data=!3m1!4b1!4m2!3m1!1s0x1940f4a5fcfc0b71:0xf19ff9ac7e583e45) to other countries in southern Africa? \n", "\n", "This IPython notebook was created by Dave Backus for the NYU Stern course [Data Bootcamp](http://databootcamp.nyuecon.com/). "], "cell_type": "markdown", "metadata": {}}, {"source": ["## Preliminaries\n", "\n", "Import packages and check code versions. "], "cell_type": "markdown", "metadata": {}}, {"execution_count": null, "cell_type": "code", "source": ["# import packages \n", "import pandas as pd # data management\n", "import matplotlib.pyplot as plt # graphics \n", "import numpy as np # numerical calculations \n", "\n", "# IPython command, puts plots in notebook \n", "%matplotlib inline\n", "\n", "# check Python version \n", "import datetime as dt \n", "import sys\n", "print('Today is', dt.date.today())\n", "print('What version of Python are we running? \\n', sys.version, sep='') "], "outputs": [], "metadata": {"collapsed": false}}, {"source": ["## Business cycle indicators \n", "\n", "We assess the state of the US economy with a collection of monthly indicators that (mostly) move up and down with the economy. We get the data from [FRED](https://research.stlouisfed.org/fred2/), the St Louis Fed's popular data collection. There are lots of indicators to choose from, but we use \n", "\n", "* INDPRO: industrial production\n", "* PAYEMS: nonfarm employment \n", "* AWHMAN: average weekly hours worked in manufacturing\n", "* PERMIT: premits for new housing\n", "* NAPM: purchasing managers index \n", "* RSXFS: retail sales (excluding food services) \n", "\n", "For each indicator the first term is the FRED code, the second a description. You can find more about this kind of thing in our [Global Economy book](http://www.stern.nyu.edu/experience-stern/about/departments-centers-initiatives/centers-of-research/global-economy-business/development-initiatives/global-economy-course), chapter 11. Also in bank reports, which review this kind of information constantly. "], "cell_type": "markdown", "metadata": {"collapsed": false}}, {"execution_count": null, "cell_type": "code", "source": ["# get data from FRED\n", "import pandas as pd \n", "import pandas.io.data as web # web interface with FRED\n", "import datetime as dt # handles dates \n", "\n", "# get data \n", "indicators = ['INDPRO', 'PAYEMS', 'AWHMAN', 'PERMIT', 'NAPM', 'RSXFS']\n", "start_date = dt.datetime(1970, 1, 1)\n", "inds = web.DataReader(indicators, \"fred\", start_date)\n", "end = inds.index[-1]\n", "\n", "# yoy growth rates \n", "g = inds.pct_change(periods=12).dropna()\n", "# standardize\n", "gs = (g - g.mean()) / g.std()\n", "\n", "# correlations \n", "gs.corr()"], "outputs": [], "metadata": {"collapsed": false}}, {"execution_count": null, "cell_type": "code", "source": ["# plot \n", "fig, ax = plt.subplots()\n", "gs.plot(ax=ax)\n", "ax.set_title('Economic indicators', fontsize=14, loc='left')\n", "ax.set_ylabel('Standard deviations from mean')\n", "ax.set_xlabel('')\n", "ax.hlines(y=0, xmin=start_date, xmax=end, linestyles='dashed')\n", "#ax.legend().set_visible(False)\n", "ax.legend(loc='upper left', fontsize=10, handlelength=2, labelspacing=0.15)"], "outputs": [], "metadata": {"collapsed": false}}, {"execution_count": null, "cell_type": "code", "source": ["# focus on recent past \n", "recent_date = dt.datetime(2005, 1, 1)\n", "grecent= gs[gs.index>=recent_date]\n", "\n", "fig, ax = plt.subplots()\n", "grecent.plot(ax=ax)\n", "ax.set_title('Zoom in on recent past', fontsize=14, loc='left')\n", "ax.set_ylabel('Standard deviations from mean')\n", "ax.set_xlabel('')\n", "ax.hlines(y=0, xmin=recent_date, xmax=end, linestyles='dashed')\n", "ax.legend(loc='upper left', fontsize=10, handlelength=2, labelspacing=0.15)"], "outputs": [], "metadata": {"collapsed": false}}, {"source": ["**Question.** How do things look now? \n", "\n", "Keep in mind that zero is average, which has been pretty good on the whole. Anything between -1 and +1 is ok: it's within one standard deviation of the average. "], "cell_type": "markdown", "metadata": {}}, {"source": ["### Heatmap\n", "\n", "See [StackOverflow](http://stackoverflow.com/questions/14391959/heatmap-in-matplotlib-with-pcolor)\n", "\n", "**How would you fix this up?**"], "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": null, "cell_type": "code", "source": ["fig, ax = plt.subplots()\n", "heatmap = ax.pcolor(gs.T, cmap=plt.cm.Blues)\n", "\n", "ax.invert_yaxis()\n", "ax.xaxis.tick_top()\n", "#ax.set_yticks(range(5)+0.5)\n", "\n", "ax.set_xticklabels(gs.index, minor=False)\n", "ax.set_yticklabels(gs.columns, minor=False)"], "outputs": [], "metadata": {"collapsed": false}}, {"execution_count": null, "cell_type": "code", "source": [], "outputs": [], "metadata": {"collapsed": false}}, {"source": ["### Radar plot ??"], "cell_type": "markdown", "metadata": {}}, {"execution_count": null, "cell_type": "code", "source": [], "outputs": [], "metadata": {"collapsed": true}}, {"execution_count": null, "cell_type": "code", "source": [], "outputs": [], "metadata": {"collapsed": true}}, {"execution_count": null, "cell_type": "code", "source": [], "outputs": [], "metadata": {"collapsed": true}}, {"execution_count": null, "cell_type": "code", "source": [], "outputs": [], "metadata": {"collapsed": true}}, {"source": ["## Country indicators: Opportunities in Southern Africa\n", "\n", "Zambeef is a successful meat distributor located in [Zambia](https://www.google.com/maps/place/Zambia/@-12.9826533,18.8129711,5z/data=!3m1!4b1!4m2!3m1!1s0x1940f4a5fcfc0b71:0xf19ff9ac7e583e45). Their leadership wonders whether their operation can be expanded to include neighboring Botswana and Tanzania. We collect a number of economic and institutional indicators to assess the business climates in the three countries and ask: \n", "\n", "* What features of an economy are import to this business?\n", "* What indicators of these features can we find in the World Bank's data?\n", "* How do the three countries compare on these features?\n", "* What locations look the most attractive to you? \n", "\n", "We start by looking through the [World Bank](http://data.worldbank.org/)'s enormous collection of country indicators and using Pandas' [World Bank API](http://pandas.pydata.org/pandas-docs/stable/remote_data.html#world-bank) to access the numbers. "], "cell_type": "markdown", "metadata": {}}, {"execution_count": null, "cell_type": "code", "source": ["from pandas.io import wb # World Bank api \n", "\n", "# read data from World Bank \n", "iso = ['ZMB', 'BWA', 'TZA'] # country list (ISO codes)\n", "var = ['NY.GDP.PCAP.PP.KD', # GDP per person \n", " 'SP.POP.TOTL', # population \n", " 'IC.BUS.EASE.XQ', # ease of doing business (rank of 189)\n", " 'IS.ROD.PAVE.ZS', # paved roads (percent of total)\n", " 'SE.ADT.LITR.ZS'] # adult literacy (15 and up)\n", "year = 2014 \n", "df = wb.download(indicator=var, country=iso, start=2005, end=2014)\n", "df"], "outputs": [], "metadata": {"collapsed": false}}, {"source": ["**Can we extract the most recent obs for each variable and country?**"], "cell_type": "markdown", "metadata": {"collapsed": true}}, {"execution_count": null, "cell_type": "code", "source": [], "outputs": [], "metadata": {"collapsed": true}}, {"execution_count": null, "cell_type": "code", "source": [], "outputs": [], "metadata": {"collapsed": true}}], "metadata": {"kernelspec": {"display_name": "Python 3", "name": "python3", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "name": "python", "file_extension": ".py", "version": "3.5.1", "pygments_lexer": "ipython3", "codemirror_mode": {"version": 3, "name": "ipython"}}}}
You can’t perform that action at this time.