In [1]:
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('classic')
import pandas as pd
import quandl as Quandl
import wbdata as wb
from scipy import stats
import runProcs
%matplotlib inline

In [2]:
# 0. Preliminaries

# 0.1 general plot settings

font = {'weight' : 'bold',
        'size'   : 15}
axes={'labelweight' : 'bold'}
plt.rc('font', **font)
plt.rc('axes', **axes)
plt.rcParams['xtick.major.pad']='8'
plt.rcParams['ytick.major.pad']='8'

In [3]:
# 1. Import country codes and organize

# 1.1 Import country codes and names from the country_codes file from Quandl's WB WDI documentation: https://www.quandl.com/data/WWDI/documentation/documentation
countryCodes = {}

try:
    text_file = open('country_codes', 'r')
    lines = text_file.readlines()
    for line in lines:
        split = line.split('|')
        if len(split)>1:
            if len(split[1])==4:
                countryCodes[split[0]] = split[1][:-1]
except:
    countryCodes = {
 'Afghanistan': 'AFG',
 'Africa': 'AFR',
 'Albania': 'ALB',
 'Algeria': 'DZA',
 'American Samoa': 'ASM',
 'Andorra': 'AND',
 'Angola': 'AGO',
 'Antigua and Barbuda': 'ATG',
 'Arab World': 'ARB',
 'Argentina': 'ARG',
 'Armenia': 'ARM',
 'Aruba': 'ABW',
 'Australia': 'AUS',
 'Austria': 'AUT',
 'Azerbaijan': 'AZE',
 'Bahamas, The': 'BHS',
 'Bahrain': 'BHR',
 'Bangladesh': 'BGD',
 'Barbados': 'BRB',
 'Belarus': 'BLR',
 'Belgium': 'BEL',
 'Belize': 'BLZ',
 'Benin': 'BEN',
 'Bermuda': 'BMU',
 'Bhutan': 'BTN',
 'Bolivia': 'BOL',
 'Bosnia and Herzegovina': 'BIH',
 'Botswana': 'BWA',
 'Brazil': 'BRA',
 'Brunei Darussalam': 'BRN',
 'Bulgaria': 'BGR',
 'Burkina Faso': 'BFA',
 'Burundi': 'BDI',
 'Cabo Verde': 'CPV',
 'Cambodia': 'KHM',
 'Cameroon': 'CMR',
 'Canada': 'CAN',
 'Caribbean small states': 'CSS',
 'Cayman Islands': 'CYM',
 'Central African Republic': 'CAF',
 'Chad': 'TCD',
 'Channel Islands': 'CHI',
 'Chile': 'CHL',
 'China': 'CHN',
 'Colombia': 'COL',
 'Comoros': 'COM',
 'Congo, Dem. Rep.': 'COD',
 'Congo, Rep.': 'COG',
 'Costa Rica': 'CRI',
 "Cote d'Ivoire": 'CIV',
 'Croatia': 'HRV',
 'Cuba': 'CUB',
 'Curacao': 'CUW',
 'Cyprus': 'CYP',
 'Czech Republic': 'CZE',
 'Denmark': 'DNK',
 'Djibouti': 'DJI',
 'Dominica': 'DMA',
 'Dominican Republic': 'DOM',
 'East Asia & Pacific (all income levels)': 'EAS',
 'East Asia & Pacific (developing only)': 'EAP',
 'East Asia and the Pacific (IFC classification)': 'CEA',
 'Ecuador': 'ECU',
 'Egypt, Arab Rep.': 'EGY',
 'El Salvador': 'SLV',
 'Equatorial Guinea': 'GNQ',
 'Eritrea': 'ERI',
 'Estonia': 'EST',
 'Ethiopia': 'ETH',
 'Euro area': 'EMU',
 'Europe & Central Asia (all income levels)': 'ECS',
 'Europe & Central Asia (developing only)': 'ECA',
 'Europe and Central Asia (IFC classification)': 'CEU',
 'European Union': 'EUU',
 'Faeroe Islands': 'FRO',
 'Fiji': 'FJI',
 'Finland': 'FIN',
 'France': 'FRA',
 'French Polynesia': 'PYF',
 'Gabon': 'GAB',
 'Gambia, The': 'GMB',
 'Georgia': 'GEO',
 'Germany': 'DEU',
 'Ghana': 'GHA',
 'Greece': 'GRC',
 'Greenland': 'GRL',
 'Grenada': 'GRD',
 'Guam': 'GUM',
 'Guatemala': 'GTM',
 'Guinea': 'GIN',
 'Guinea-Bissau': 'GNB',
 'Guyana': 'GUY',
 'Haiti': 'HTI',
 'Heavily indebted poor countries (HIPC)': 'HPC',
 'High income': 'HIC',
 'High income: OECD': 'OEC',
 'High income: nonOECD': 'NOC',
 'Honduras': 'HND',
 'Hong Kong SAR, China': 'HKG',
 'Hungary': 'HUN',
 'Iceland': 'ISL',
 'India': 'IND',
 'Indonesia': 'IDN',
 'Iran, Islamic Rep.': 'IRN',
 'Iraq': 'IRQ',
 'Ireland': 'IRL',
 'Isle of Man': 'IMN',
 'Israel': 'ISR',
 'Italy': 'ITA',
 'Jamaica': 'JAM',
 'Japan': 'JPN',
 'Jordan': 'JOR',
 'Kazakhstan': 'KAZ',
 'Kenya': 'KEN',
 'Kiribati': 'KIR',
 'Korea, Dem. Rep.': 'PRK',
 'Korea, Rep.': 'KOR',
 'Kosovo': 'KSV',
 'Kuwait': 'KWT',
 'Kyrgyz Republic': 'KGZ',
 'Lao PDR': 'LAO',
 'Latin America & Caribbean (all income levels)': 'LCN',
 'Latin America & Caribbean (developing only)': 'LAC',
 'Latin America and the Caribbean (IFC classification)': 'CLA',
 'Latvia': 'LVA',
 'Least developed countries: UN classification': 'LDC',
 'Lebanon': 'LBN',
 'Lesotho': 'LSO',
 'Liberia': 'LBR',
 'Libya': 'LBY',
 'Liechtenstein': 'LIE',
 'Lithuania': 'LTU',
 'Low & middle income': 'LMY',
 'Low income': 'LIC',
 'Lower middle income': 'LMC',
 'Luxembourg': 'LUX',
 'Macao SAR, China': 'MAC',
 'Macedonia, FYR': 'MKD',
 'Madagascar': 'MDG',
 'Malawi': 'MWI',
 'Malaysia': 'MYS',
 'Maldives': 'MDV',
 'Mali': 'MLI',
 'Malta': 'MLT',
 'Marshall Islands': 'MHL',
 'Mauritania': 'MRT',
 'Mauritius': 'MUS',
 'Mexico': 'MEX',
 'Micronesia, Fed. Sts.': 'FSM',
 'Middle East & North Africa (all income levels)': 'MEA',
 'Middle East & North Africa (developing only)': 'MNA',
 'Middle East and North Africa (IFC classification)': 'CME',
 'Middle income': 'MIC',
 'Moldova': 'MDA',
 'Monaco': 'MCO',
 'Mongolia': 'MNG',
 'Montenegro': 'MNE',
 'Morocco': 'MAR',
 'Mozambique': 'MOZ',
 'Myanmar': 'MMR',
 'Namibia': 'NAM',
 'Nepal': 'NPL',
 'Netherlands': 'NLD',
 'New Caledonia': 'NCL',
 'New Zealand': 'NZL',
 'Nicaragua': 'NIC',
 'Niger': 'NER',
 'Nigeria': 'NGA',
 'North Africa': 'NAF',
 'North America': 'NAC',
 'Northern Mariana Islands': 'MNP',
 'Norway': 'NOR',
 'OECD members': 'OED',
 'Oman': 'OMN',
 'Other small states': 'OSS',
 'Pacific island small states': 'PSS',
 'Pakistan': 'PAK',
 'Palau': 'PLW',
 'Panama': 'PAN',
 'Papua New Guinea': 'PNG',
 'Paraguay': 'PRY',
 'Peru': 'PER',
 'Philippines': 'PHL',
 'Poland': 'POL',
 'Portugal': 'PRT',
 'Puerto Rico': 'PRI',
 'Qatar': 'QAT',
 'Romania': 'ROU',
 'Russian Federation': 'RUS',
 'Rwanda': 'RWA',
 'Samoa': 'WSM',
 'San Marino': 'SMR',
 'Sao Tome and Principe': 'STP',
 'Saudi Arabia': 'SAU',
 'Senegal': 'SEN',
 'Serbia': 'SRB',
 'Seychelles': 'SYC',
 'Sierra Leone': 'SLE',
 'Singapore': 'SGP',
 'Sint Maarten (Dutch part)': 'SXM',
 'Slovak Republic': 'SVK',
 'Slovenia': 'SVN',
 'Small states': 'SST',
 'Solomon Islands': 'SLB',
 'Somalia': 'SOM',
 'South Africa': 'ZAF',
 'South Asia': 'SAS',
 'South Asia (IFC classification)': 'CSA',
 'South Sudan': 'SSD',
 'Spain': 'ESP',
 'Sri Lanka': 'LKA',
 'St. Kitts and Nevis': 'KNA',
 'St. Lucia': 'LCA',
 'St. Martin (French part)': 'MAF',
 'St. Vincent and the Grenadines': 'VCT',
 'Sub-Saharan Africa (IFC classification)': 'CAA',
 'Sub-Saharan Africa (all income levels)': 'SSF',
 'Sub-Saharan Africa (developing only)': 'SSA',
 'Sub-Saharan Africa excluding South Africa': 'SXZ',
 'Sub-Saharan Africa excluding South Africa and Nigeria': 'XZN',
 'Sudan': 'SDN',
 'Suriname': 'SUR',
 'Swaziland': 'SWZ',
 'Sweden': 'SWE',
 'Switzerland': 'CHE',
 'Syrian Arab Republic': 'SYR',
 'Tajikistan': 'TJK',
 'Tanzania': 'TZA',
 'Thailand': 'THA',
 'Timor-Leste': 'TLS',
 'Togo': 'TGO',
 'Tonga': 'TON',
 'Trinidad and Tobago': 'TTO',
 'Tunisia': 'TUN',
 'Turkey': 'TUR',
 'Turkmenistan': 'TKM',
 'Turks and Caicos Islands': 'TCA',
 'Tuvalu': 'TUV',
 'Uganda': 'UGA',
 'Ukraine': 'UKR',
 'United Arab Emirates': 'ARE',
 'United Kingdom': 'GBR',
 'United States': 'USA',
 'Upper middle income': 'UMC',
 'Uruguay': 'URY',
 'Uzbekistan': 'UZB',
 'Vanuatu': 'VUT',
 'Venezuela, RB': 'VEN',
 'Vietnam': 'VNM',
 'Virgin Islands (U.S.)': 'VIR',
 'West Bank and Gaza': 'PSE',
 'World': 'WLD',
 'Yemen, Rep.': 'YEM',
 'Zambia': 'ZMB',
 'Zimbabwe': 'ZWE'}
    
        
#1.2 Use wbdata to get lists of country codes by income groups
countriesIncomeAll =  [i['id'] for i in wb.get_country(incomelevel=['LIC','MIC','HIC'],display=False)]
countriesIncomeH = [i['id'] for i in wb.get_country(incomelevel=['HIC'],display=False)]
countriesIncomeM = [i['id'] for i in wb.get_country(incomelevel=['MIC'],display=False)]
countriesIncomeL = [i['id'] for i in wb.get_country(incomelevel=['LIC'],display=False)]

countriesIncomeOecd = ['AUS','CAN','CHL','CZE','DNK','EST','HUN','ISL','ISR','JPN'
                       ,'KOR','NZL','NOR''POL','SVK','SVN','SWE','CHE','USA']

Figures: money, prices, and output


In [4]:
# 4. Graph of quantity theory data without exchange or interest rates

# 4.0 Import data

qtyTheoryData = pd.read_csv('qtyTheoryData.csv')
qtyTheoryDataL = pd.read_csv('qtyTheoryDataL.csv')
qtyTheoryDataM = pd.read_csv('qtyTheoryDataM.csv')
qtyTheoryDataH = pd.read_csv('qtyTheoryDataH.csv')
qtyTheoryDataOecd = pd.read_csv('qtyTheoryDataOecd.csv')


# 4.1 Money growth inflation with country codes
m = qtyTheoryData['money growth']
p = qtyTheoryData['inflation']
y = qtyTheoryData['gdp growth']
codes = qtyTheoryData['iso code']


a_p, b_p, r_p, p_value, std_err = stats.linregress(m,p)
xVals = np.arange(-10,10)
p_pred = b_p + a_p*xVals

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(p_pred,p_pred,lw=1.5,label='OLS Regression')
ax1.legend(loc='lower right',fontsize=12)
for i in range(len(codes)):
    if codes[i] =='USA':
        usaIndex = i
#         plt.text(m[i], p[i], codes[i], color='red',fontsize=12, clip_on=True,horizontalalignment='center',verticalalignment='center',alpha = 1)
    else:
        plt.text(m[i], p[i], codes[i], color="#11557c",fontsize=12, clip_on=True,horizontalalignment='center',verticalalignment='center',alpha = 1)
plt.text(m[usaIndex], p[usaIndex], codes[usaIndex], color='red',fontsize=12, clip_on=True,horizontalalignment='center',verticalalignment='center',alpha = 1)
ax1.axis([-0.2, 1.4, -0.2, 1.4])
ax1.set_xlabel('money growth')
ax1.set_ylabel('inflation')
plt.grid()

plt.tight_layout()
plt.savefig('fig_moneyInflationCoded.png',bbox_inches='tight',dpi=120)


print('regression coefficient:',np.round(a_p,2))


regression coefficient: 0.98

In [5]:
# 4.2 Money growth and inflation

xmin = -0.05
xmax = 1.4
ymin = -0.05
ymax = 1.4

x45 = np.arange(xmin,xmax,0.001)
y45 = x45 - np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x45,y45)
ax1.plot(qtyTheoryDataH['money growth'],qtyTheoryDataH['inflation'],'bo')
ax1.plot(qtyTheoryDataM['money growth'],qtyTheoryDataM['inflation'],'gs')
ax1.plot(qtyTheoryDataL['money growth'],qtyTheoryDataL['inflation'],'r^')
plt.grid(True)
ax1.set_xlabel('money growth')
ax1.set_ylabel('inflation')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])

plt.legend(['$45^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_moneyInflation.png',bbox_inches='tight',dpi=120)

# 4.3 Money growth and real gdp growth

xmin = -0.05
xmax = 1.4
ymin = -0.05
ymax = .2

x0 = np.arange(xmin,xmax,0.001)
y0 = x0*0 + np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x0,y0)
plt.plot(qtyTheoryDataH['money growth'],qtyTheoryDataH['gdp growth'],'bo')
plt.plot(qtyTheoryDataM['money growth'],qtyTheoryDataM['gdp growth'],'gs')
plt.plot(qtyTheoryDataL['money growth'],qtyTheoryDataL['gdp growth'],'r^')
plt.grid(True)
# ax1.set_title('Money growth and real GDP growth',fontsize=15)
ax1.set_xlabel('money growth')
ax1.set_ylabel('real GDP growth')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])
plt.legend(['$0^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_moneyGDP.png',bbox_inches='tight',dpi=120)

# 4.4 Money growth and real gdp growth

xmin = -0.05
xmax = 1.4
ymin = -0.05
ymax = .2

x0 = np.arange(xmin,xmax,0.001)
y0 = x0*0 + np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x0,y0)
plt.plot(qtyTheoryDataH['inflation'],qtyTheoryDataH['gdp growth'],'bo')
plt.plot(qtyTheoryDataM['inflation'],qtyTheoryDataM['gdp growth'],'gs')
plt.plot(qtyTheoryDataL['inflation'],qtyTheoryDataL['gdp growth'],'r^')
plt.grid(True)
# ax1.set_title('Inflation and real GDP growth',fontsize=15)
ax1.set_xlabel('inflation')
ax1.set_ylabel('real GDP growth')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])
plt.legend(['$0^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_inflationGDP.png',bbox_inches='tight',dpi=120)



In [6]:
# 5. Make tex files for figures

# 5.0 Money growth and inflation with codes
nf = open('figure_moneyInflationCoded.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_moneyInflationCoded} \\textbf{Money growth and deflator inflation for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_moneyInflationCoded.png}\n')
nf.write('\\end{figure}')
nf.close()

# 5.1 Money growth and inflation
nf = open('figure_moneyInflation.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_moneyInflation} \\textbf{Money growth and deflator inflation for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_moneyInflation.png}\n')
nf.write('\\end{figure}')
nf.close()

# 5.2 Inflation and real GDP
nf = open('figure_inflationGDP.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_moneyGDP} \\textbf{Deflator inflation and real GDP growth for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_inflationGDP.png}\n')
nf.write('\\end{figure}')
nf.close()

# 5.3 Inflation and real GDP
nf = open('figure_moneyGDP.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_inflationGDP} \\textbf{Money growth and real GDP growth for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_moneyGDP.png}\n')
nf.write('\\end{figure}')
nf.close()

In [7]:
# 6. Correlations
print(qtyTheoryData[['money growth','inflation','gdp growth']].corr())
print(qtyTheoryDataH[['money growth','inflation','gdp growth']].corr())
print(qtyTheoryDataM[['money growth','inflation','gdp growth']].corr())
print(qtyTheoryDataL[['money growth','inflation','gdp growth']].corr())
print(qtyTheoryDataOecd[['money growth','inflation','gdp growth']].corr())


              money growth  inflation  gdp growth
money growth      1.000000   0.972160    0.084328
inflation         0.972160   1.000000   -0.043356
gdp growth        0.084328  -0.043356    1.000000
              money growth  inflation  gdp growth
money growth      1.000000   0.951716    0.228299
inflation         0.951716   1.000000    0.025692
gdp growth        0.228299   0.025692    1.000000
              money growth  inflation  gdp growth
money growth      1.000000   0.974956    0.029299
inflation         0.974956   1.000000   -0.080869
gdp growth        0.029299  -0.080869    1.000000
              money growth  inflation  gdp growth
money growth      1.000000   0.976335   -0.061547
inflation         0.976335   1.000000   -0.170883
gdp growth       -0.061547  -0.170883    1.000000
              money growth  inflation  gdp growth
money growth      1.000000   0.917601    0.474798
inflation         0.917601   1.000000    0.358369
gdp growth        0.474798   0.358369    1.000000

Figures: money, prices, output, interest, and exchange rates


In [8]:
qtyTheoryData = pd.read_csv('qtyTheoryOpenData.csv',index_col=0)
qtyTheoryDataL = pd.read_csv('qtyTheoryOpenDataL.csv',index_col=0)
qtyTheoryDataM = pd.read_csv('qtyTheoryOpenDataM.csv',index_col=0)
qtyTheoryDataH = pd.read_csv('qtyTheoryOpenDataH.csv',index_col=0)
qtyTheoryDataOecd = pd.read_csv('qtyTheoryOpenDataOecd.csv',index_col=0)


# 8.1 Money growth and inflation

xmin = -0.05
xmax = 1.4
ymin = -0.05
ymax = 1.4

x45 = np.arange(xmin,xmax,0.001)
y45 = x45 - np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x45,y45)
ax1.plot(qtyTheoryDataH['money growth'],qtyTheoryDataH['inflation'],'bo')
ax1.plot(qtyTheoryDataM['money growth'],qtyTheoryDataM['inflation'],'gs')
ax1.plot(qtyTheoryDataL['money growth'],qtyTheoryDataL['inflation'],'r^')
plt.grid(True)
ax1.set_xlabel('money growth')
ax1.set_ylabel('inflation')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])

plt.legend(['$45^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_moneyInflationOpen.png',bbox_inches='tight',dpi=120)

# 8.2 Money growth and real gdp growth

xmin = -0.05
xmax = 1.4
ymin = -0.05
ymax = .2

x0 = np.arange(xmin,xmax,0.001)
y0 = x0*0 + np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x0,y0)
plt.plot(qtyTheoryDataH['money growth'],qtyTheoryDataH['gdp growth'],'bo')
plt.plot(qtyTheoryDataM['money growth'],qtyTheoryDataM['gdp growth'],'gs')
plt.plot(qtyTheoryDataL['money growth'],qtyTheoryDataL['gdp growth'],'r^')
plt.grid(True)
# ax1.set_title('Money growth and real GDP growth',fontsize=15)
ax1.set_xlabel('money growth')
ax1.set_ylabel('real GDP growth')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])
plt.legend(['$0^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_moneyGDPOpen.png',bbox_inches='tight',dpi=120)

# 8.3 Money growth and real gdp growth

xmin = -0.05
xmax = 1.4
ymin = -0.05
ymax = .2

x0 = np.arange(xmin,xmax,0.001)
y0 = x0*0 + np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x0,y0)
plt.plot(qtyTheoryDataH['inflation'],qtyTheoryDataH['gdp growth'],'bo')
plt.plot(qtyTheoryDataM['inflation'],qtyTheoryDataM['gdp growth'],'gs')
plt.plot(qtyTheoryDataL['inflation'],qtyTheoryDataL['gdp growth'],'r^')
plt.grid(True)
# ax1.set_title('Inflation and real GDP growth',fontsize=15)
ax1.set_xlabel('inflation')
ax1.set_ylabel('real GDP growth')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])
plt.legend(['$0^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_inflationGDPOpen.png',bbox_inches='tight',dpi=120)

# 8.4 Money growth differential depreciation

xmin = -0.2
xmax = 1.4
ymin = -0.2
ymax = 1.4

x45 = np.arange(xmin,xmax,0.001)
y45 = x45 - np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x45,y45)
ax1.plot(qtyTheoryDataH['inflation']- qtyTheoryData['inflation'].loc['United States'],qtyTheoryDataH['nominal interest rate']- qtyTheoryData['nominal interest rate'].loc['United States'],'bo')
ax1.plot(qtyTheoryDataM['inflation']- qtyTheoryData['inflation'].loc['United States'],qtyTheoryDataM['nominal interest rate']- qtyTheoryData['nominal interest rate'].loc['United States'],'gs')
ax1.plot(qtyTheoryDataL['inflation']- qtyTheoryData['inflation'].loc['United States'],qtyTheoryDataL['nominal interest rate']- qtyTheoryData['nominal interest rate'].loc['United States'],'r^')
plt.grid(True)
ax1.set_xlabel('inflation differential')
ax1.set_ylabel('interest differential')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])

plt.legend(['$45^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_inflationInterestDifferentialsOpen.png',bbox_inches='tight',dpi=120)

# 8.5 Money growth differential depreciation

xmin = -0.2
xmax = 1.4
ymin = -0.2
ymax = 1.4

x45 = np.arange(xmin,xmax,0.001)
y45 = x45 - np.mean(qtyTheoryData['gdp growth'])

fig = plt.figure()

ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x45,y45)
ax1.plot(qtyTheoryDataH['money growth']- qtyTheoryData['money growth'].loc['United States'],qtyTheoryDataH['exchange rate depreciation'],'bo')
ax1.plot(qtyTheoryDataM['money growth']- qtyTheoryData['money growth'].loc['United States'],qtyTheoryDataM['exchange rate depreciation'],'gs')
ax1.plot(qtyTheoryDataL['money growth']- qtyTheoryData['money growth'].loc['United States'],qtyTheoryDataL['exchange rate depreciation'],'r^')
plt.grid(True)
ax1.set_xlabel('money growth differential')
ax1.set_ylabel('depreciation')
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymin,ymax])

plt.legend(['$45^\circ$'],loc='lower right',fontsize='15')

plt.tight_layout()
plt.savefig('fig_moneyDifferentialDepreciationOpen.png',bbox_inches='tight',dpi=120)



In [9]:
# 9. Make tex files for figures

# 9.1 Money growth and inflation
nf = open('figure_moneyInflationOpen.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_moneyInflationOpen} \\textbf{Money growth and deflator inflation for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_moneyInflationOpen.png}\n')
nf.write('\\end{figure}')
nf.close()

# 9.2 Inflation and real GDP
nf = open('figure_inflationGDPOpen.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_moneyGDPOpen} \\textbf{Deflator inflation and real GDP growth for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_inflationGDPOpen.png}\n')
nf.write('\\end{figure}')
nf.close()

# 9.3 Inflation and real GDP
nf = open('figure_moneyGDPOpen.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_inflationGDPOpen} \\textbf{Money growth and real GDP growth for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_moneyGDPOpen.png}\n')
nf.write('\\end{figure}')
nf.close()

# 9.4 Inflation and interest rate differentials
nf = open('figure_inflationInterestDifferentialsOpen.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_inflationInterestDifferentialsOpen} \\textbf{Interest and inflation relative to US for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_inflationInterestDifferentialsOpen.png}\n')
nf.write('\\end{figure}')
nf.close()

# 9.5 Money growth and exchange rate depreciation
nf = open('figure_moneyDifferentialDepreciationOpen.tex', 'w')
nf.write('\\begin{figure}[h]\n')
nf.write('\\caption{\\label{fig_moneyDifferentialDepreciationOpen} \\textbf{Money growth and depreciation for '),nf.write(str(len(qtyTheoryData))),nf.write(' countries.} High-income countries: blue circles, medium-income: green squares, and low-income: red triangles. {\\tiny Source: Quandl, World Development Indicators, World Bank}}\n')
nf.write('\\hspace*{-.5cm}\\includegraphics[height = 7.cm]{fig_moneyDifferentialDepreciationOpen.png}\n')
nf.write('\\end{figure}')
nf.close()

In [10]:
# 10. Correlations
print(qtyTheoryData[['money growth','inflation','gdp growth','nominal interest rate','exchange rate depreciation']].corr())
print(qtyTheoryDataH[['money growth','inflation','gdp growth','nominal interest rate','exchange rate depreciation']].corr())
print(qtyTheoryDataM[['money growth','inflation','gdp growth','nominal interest rate','exchange rate depreciation']].corr())
print(qtyTheoryDataL[['money growth','inflation','gdp growth','nominal interest rate','exchange rate depreciation']].corr())
print(qtyTheoryDataOecd[['money growth','inflation','gdp growth','nominal interest rate','exchange rate depreciation']].corr())


                            money growth  inflation  gdp growth  \
money growth                    1.000000   0.948167    0.160841   
inflation                       0.948167   1.000000   -0.002527   
gdp growth                      0.160841  -0.002527    1.000000   
nominal interest rate           0.323171   0.382868   -0.021343   
exchange rate depreciation      0.795783   0.864135   -0.046034   

                            nominal interest rate  exchange rate depreciation  
money growth                             0.323171                    0.795783  
inflation                                0.382868                    0.864135  
gdp growth                              -0.021343                   -0.046034  
nominal interest rate                    1.000000                    0.343875  
exchange rate depreciation               0.343875                    1.000000  
                            money growth  inflation  gdp growth  \
money growth                    1.000000   0.872973    0.156104   
inflation                       0.872973   1.000000   -0.068762   
gdp growth                      0.156104  -0.068762    1.000000   
nominal interest rate           0.607209   0.512346   -0.141079   
exchange rate depreciation      0.864155   0.953606   -0.115223   

                            nominal interest rate  exchange rate depreciation  
money growth                             0.607209                    0.864155  
inflation                                0.512346                    0.953606  
gdp growth                              -0.141079                   -0.115223  
nominal interest rate                    1.000000                    0.538832  
exchange rate depreciation               0.538832                    1.000000  
                            money growth  inflation  gdp growth  \
money growth                    1.000000   0.956133    0.104541   
inflation                       0.956133   1.000000   -0.066198   
gdp growth                      0.104541  -0.066198    1.000000   
nominal interest rate           0.381125   0.447903   -0.035920   
exchange rate depreciation      0.899247   0.939476   -0.074205   

                            nominal interest rate  exchange rate depreciation  
money growth                             0.381125                    0.899247  
inflation                                0.447903                    0.939476  
gdp growth                              -0.035920                   -0.074205  
nominal interest rate                    1.000000                    0.430750  
exchange rate depreciation               0.430750                    1.000000  
                            money growth  inflation  gdp growth  \
money growth                    1.000000   0.952370    0.298479   
inflation                       0.952370   1.000000    0.198917   
gdp growth                      0.298479   0.198917    1.000000   
nominal interest rate          -0.066442   0.083812   -0.083799   
exchange rate depreciation      0.581025   0.681962    0.044063   

                            nominal interest rate  exchange rate depreciation  
money growth                            -0.066442                    0.581025  
inflation                                0.083812                    0.681962  
gdp growth                              -0.083799                    0.044063  
nominal interest rate                    1.000000                    0.521828  
exchange rate depreciation               0.521828                    1.000000  
                            money growth  inflation  gdp growth  \
money growth                    1.000000   0.853742    0.347081   
inflation                       0.853742   1.000000    0.139932   
gdp growth                      0.347081   0.139932    1.000000   
nominal interest rate           0.912306   0.786945    0.201125   
exchange rate depreciation      0.867758   0.967074    0.140830   

                            nominal interest rate  exchange rate depreciation  
money growth                             0.912306                    0.867758  
inflation                                0.786945                    0.967074  
gdp growth                               0.201125                    0.140830  
nominal interest rate                    1.000000                    0.832183  
exchange rate depreciation               0.832183                    1.000000  

In [11]:
# 11. Export notebook to python script
runProcs.exportNb('quantityTheoryFigures')