Democracy and Economic Well-Being: Controlled for Urbanization Rates

I continue to look at the relationship between economic well-being and the level of democracy.  I have previously established that there is a statistically significant difference in the mean level of income per person for countries that are full democracies. Based on last week’s work the level of urbanization was also shown to have a statistically significant effect on the level of economic well-being.  This week I want to control for the level of urbanization to see if the level of democracy still has an effect.  I have posted my analysis in the form of a Jupyter notebook on the GitHub repository for this course.

Explanation

Before launching into the source code let me explain my rationale for this analysis.  I am using the GapMinder data set.  The variables of interest are the polity score (measure of the level of democratization), urbanization rate and income per person (economic well-being).  As has been my practice I have collapsed the 20+ categories of polity score into 5 using the study author’s definitions.  I also break the urbanization rate into 3 categories (urban, in transition, not urban).

I want to compare the level of economic well-being (quantitative variable) by the level of democracy (categorical variable) therefore I will be doing an ANOVA.  Since there are more than one categories of level of democracy I will preform a Tukey Honestly Significantly Different Test.  Since I am controlling for the level of urbanization I have written a for loop.

Source Code

For this analysis the following Python code was used:

# Import libraries needed
import pandas as pd
import statsmodels.formula.api as smf
import statsmodels.stats.multicomp as ssm
import seaborn as sns
import matplotlib.pyplot as plt

# Read in the GapMinder Data
print('Reading in GapMinder data')
df = pd.read_csv('gapminder.csv', low_memory=False)

# Change the data type for variables of interest
df['polityscore'] = pd.to_numeric(df['polityscore'], errors='coerce')
df['urbanrate'] = pd.to_numeric(df['urbanrate'], errors='coerce')
df['incomeperperson'] = pd.to_numeric(df['incomeperperson'], errors='coerce')
 
# Get the subset of complete data cases
subset = df[['polityscore','urbanrate','incomeperperson']].dropna()

# Recode polity score
print('Creating government type variable')
# This function converts the polity score to a category
def convert_polityscore_to_category(score):
    if score == 10:
        return('1 - Full Democracy')
    elif score > 5:
        return('2 - Democracy')
    elif score > 0:
        return ('3 - Open Anocracy')
    elif score > -6:
        return ('4 - Closed Anocracy')
    else:
        return('5 - Autocracy')

# Now we can use the function to create the new variable
subset['openness'] = subset['polityscore'].apply(convert_polityscore_to_category).astype('category')

# Recode urbanization rate
print('Creating urbanization type variable')
# This function converts the polity score to a category
def convert_urbanrate_to_category(urbanrate):
    if urbanrate < 33:
        return('Not Urban')
    elif urbanrate < 66:
        return('In Transition')
    else:
        return('Urban')

# Now we can use the function to create the new variable
subset['urban'] = subset['urbanrate'].apply(convert_urbanrate_to_category).astype('category')

datasets = {'Not Urban': subset[subset['urban']=='Not Urban'], 'In Transition': subset[subset['urban']=='In Transition'], 'Urban' : subset[subset['urban']=='Urban']}

for title, data in datasets.iteritems():
    # ANOVA
    ols_data = data[['incomeperperson','openness']].dropna()
    # Convert float to int
    #ols_data['incomeperperson'] = ols_data['incomeperperson'].astype(int)
    model = smf.ols(formula='incomeperperson ~ C(openness)', data=ols_data).fit()
    print('ANOVA for Countries Classified as '+title)    
    print(model.summary())
    print('\n')
    
    # Tukey Honestly Significantly Different
    tukey = ssm.MultiComparison(data['incomeperperson'], data['openness']).tukeyhsd()
    print('Tukey Honestly Significantly Different Test for Countries Classified as '+title)
    print(tukey.summary())
    print('\n')
    
    # Economic Well-Being by Level of Openness
    # Visualize Mean Economic Well Being by Level of Openness
    sns.set_context('poster')
    plt.figure(figsize=(14, 7))
    sns.factorplot(x='openness', y='incomeperperson', data=ols_data, kind='bar', ci=None, size=4, aspect=4)
    plt.ylabel('Average Economic Well-Being (GDP Per Person)')
    plt.xlabel('Level of Openness')
    plt.title(title)

Results

155 of the 213 countries had complete data and was analyzed.  All three cases had statistically significant F-statistics.  However we are really interested in the Tukey test.  Here’s the results:

Not Urban

dat-week4-not-urban

Tukey Honestly Significantly Different Test for Countries Classified as Not Urban
                Multiple Comparison of Means - Tukey HSD,FWER=0.05               
=================================================================================
       group1              group2         meandiff     lower      upper    reject
---------------------------------------------------------------------------------
 1 - Full Democracy    2 - Democracy     -9934.9336 -11114.7298 -8755.1375  True 
 1 - Full Democracy  3 - Open Anocracy   -9960.5319 -11231.6024 -8689.4615  True 
 1 - Full Democracy 4 - Closed Anocracy -10143.4331 -11341.8099 -8945.0564  True 
 1 - Full Democracy    5 - Autocracy     -9675.8887 -10946.9591 -8404.8182  True 
   2 - Democracy     3 - Open Anocracy    -25.5983   -675.6343   624.4377  False 
   2 - Democracy    4 - Closed Anocracy  -208.4995   -701.4837   284.4847  False 
   2 - Democracy       5 - Autocracy      259.045     -390.991   909.081   False 
 3 - Open Anocracy  4 - Closed Anocracy  -182.9012    -866.081   500.2787  False 
 3 - Open Anocracy     5 - Autocracy      284.6433   -519.2523  1088.5388  False 
4 - Closed Anocracy    5 - Autocracy      467.5445   -215.6354  1150.7243  False 
---------------------------------------------------------------------------------

One observes that the average economic well-being for the full democracies are different in a statistically significant way from all other types.  The other types of countries are not distinct from each other.

In Transition

dat-week4-transition

Tukey Honestly Significantly Different Test for Countries Classified as In Transition
                Multiple Comparison of Means - Tukey HSD,FWER=0.05               
=================================================================================
       group1              group2         meandiff     lower      upper    reject
---------------------------------------------------------------------------------
 1 - Full Democracy    2 - Democracy    -10103.3992 -14015.0251 -6191.7733  True 
 1 - Full Democracy  3 - Open Anocracy  -10884.4008 -15360.6475 -6408.1541  True 
 1 - Full Democracy 4 - Closed Anocracy -10413.5784 -14810.8727 -6016.284   True 
 1 - Full Democracy    5 - Autocracy     -9944.1569 -15096.0724 -4792.2413  True 
   2 - Democracy     3 - Open Anocracy   -781.0016   -4452.4171 2890.4138  False 
   2 - Democracy    4 - Closed Anocracy  -310.1792   -3884.9106 3264.5522  False 
   2 - Democracy       5 - Autocracy      159.2423   -4311.1873 4629.6719  False 
 3 - Open Anocracy  4 - Closed Anocracy   470.8224   -3714.2309 4655.8758  False 
 3 - Open Anocracy     5 - Autocracy      940.2439   -4031.7484 5912.2363  False 
4 - Closed Anocracy    5 - Autocracy      469.4215   -4431.6111 5370.4542  False 
---------------------------------------------------------------------------------

For the countries who are in between not urban and urban we once again observe that the full democracy is different from all other categories in a statistically significant way.  All other categories are not different.

Urban

dat-week4-urban

Tukey Honestly Significantly Different Test for Countries Classified as Urban
                Multiple Comparison of Means - Tukey HSD,FWER=0.05               
=================================================================================
       group1              group2         meandiff     lower      upper    reject
---------------------------------------------------------------------------------
 1 - Full Democracy    2 - Democracy     -15686.311 -24286.5252 -7086.0968  True 
 1 - Full Democracy  3 - Open Anocracy  -20566.3926 -37331.2965 -3801.4887  True 
 1 - Full Democracy 4 - Closed Anocracy -14332.9237 -27849.2214 -816.6261   True 
 1 - Full Democracy    5 - Autocracy    -11519.3235 -22341.0225 -697.6246   True 
   2 - Democracy     3 - Open Anocracy   -4880.0816 -21754.9205 11994.7573 False 
   2 - Democracy    4 - Closed Anocracy  1353.3873  -12299.0296 15005.8041 False 
   2 - Democracy       5 - Autocracy     4166.9875   -6824.2523 15158.2272 False 
 3 - Open Anocracy  4 - Closed Anocracy  6233.4688   -13603.033 26069.9707 False 
 3 - Open Anocracy     5 - Autocracy      9047.069   -9061.0968 27155.2349 False 
4 - Closed Anocracy    5 - Autocracy     2813.6002  -12336.7783 17963.9787 False 
---------------------------------------------------------------------------------

This last comparison again shows that countries that are full democracies are different from all other groups in a statistically significant way.

Summary

In this analysis of 155 countries we examined the relationship between the level of economic well-being and the amount of democratization.  We controlled by the level of urbanization.  We found that countries identified as full democracies (had a polity score of 10) had an average income per person that was different from all other types.  The other types did not have a statistically significant difference from one to another.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s