In [1]:
import pandas as pd
import matplotlib
import numpy
%matplotlib inline

In [2]:
df = pd.read_csv("constituency_opinion_estimates_2010_2014.csv")

In [23]:
df.head()


Out[23]:
refno constname gsscode redist11pt_mean redist11pt_cilo redist11pt_cihi euref_mean euref_cilo euref_cihi immigcult_mean ... immigcult_cihi ssm_mean ssm_cilo ssm_cihi eudis_mean eudis_cilo eudis_cihi econlr_mean econlr_cilo econlr_cihi
0 1 Aberavon W07000049 3.695284 3.378627 4.008046 48.383518 41.359853 54.660844 3.125392 ... 3.362297 58.023178 50.811772 65.722245 50.609260 42.686492 58.523050 -1.584669 -2.295361 -0.833680
1 2 Aberconwy W07000058 4.300905 3.991315 4.593337 52.310745 45.609311 58.738533 3.311860 ... 3.592840 55.517586 49.636863 62.226684 52.870033 44.818714 60.642912 -0.105823 -0.772076 0.618162
2 3 Aberdeen North S14000001 3.813816 3.461192 4.147387 38.030707 31.609638 44.878581 3.872343 ... 4.140417 64.112562 55.437881 71.854186 39.639451 31.620011 48.915458 -1.252566 -2.103390 -0.351962
3 4 Aberdeen South S14000002 4.220543 3.913391 4.533444 32.784458 27.272056 38.762001 4.099264 ... 4.359464 64.245851 56.582616 71.464928 34.771568 27.021970 43.108658 -0.545755 -1.384504 0.242231
4 5 West Aberdeenshire and Kincardine S14000058 4.754696 4.433378 5.051736 38.580496 32.644998 44.977058 3.707387 ... 3.956183 55.984083 46.999517 63.467649 40.043867 32.667452 47.725542 0.084901 -0.671989 0.833180

5 rows × 21 columns


In [4]:
df.columns


Out[4]:
Index(['refno', 'constname', 'gsscode', 'redist11pt_mean', 'redist11pt_cilo',
       'redist11pt_cihi', 'euref_mean', 'euref_cilo', 'euref_cihi',
       'immigcult_mean', 'immigcult_cilo', 'immigcult_cihi', 'ssm_mean',
       'ssm_cilo', 'ssm_cihi', 'eudis_mean', 'eudis_cilo', 'eudis_cihi',
       'econlr_mean', 'econlr_cilo', 'econlr_cihi'],
      dtype='object')

In [5]:
df['euref_mean'].head()


Out[5]:
0    48.383518
1    52.310745
2    38.030707
3    32.784458
4    38.580496
Name: euref_mean, dtype: float64

In [6]:
df['immigcult_mean'].head()


Out[6]:
0    3.125392
1    3.311860
2    3.872343
3    4.099264
4    3.707387
Name: immigcult_mean, dtype: float64

In [18]:
df.corr()


Out[18]:
refno redist11pt_mean redist11pt_cilo redist11pt_cihi euref_mean euref_cilo euref_cihi immigcult_mean immigcult_cilo immigcult_cihi ssm_mean ssm_cilo ssm_cihi eudis_mean eudis_cilo eudis_cihi econlr_mean econlr_cilo econlr_cihi
refno 1.000000 0.105465 0.107347 0.102611 0.032800 0.030020 0.034251 -0.029933 -0.029380 -0.027276 -0.032670 -0.005004 -0.052281 0.043075 0.048560 0.036051 0.068432 0.077012 0.058452
redist11pt_mean 0.105465 1.000000 0.998403 0.998212 0.199081 0.203076 0.193719 -0.195862 -0.181754 -0.208318 -0.314321 -0.242739 -0.368078 0.290781 0.318835 0.258366 0.895609 0.895114 0.887197
redist11pt_cilo 0.107347 0.998403 1.000000 0.994719 0.198284 0.204082 0.191110 -0.202451 -0.186220 -0.217126 -0.315453 -0.241106 -0.372258 0.292829 0.322095 0.259144 0.890381 0.892278 0.879906
redist11pt_cihi 0.102611 0.998212 0.994719 1.000000 0.198873 0.200940 0.195525 -0.188262 -0.176520 -0.198371 -0.310048 -0.242573 -0.360382 0.286624 0.313130 0.256078 0.894761 0.891910 0.888960
euref_mean 0.032800 0.199081 0.198284 0.198873 1.000000 0.997451 0.997891 -0.935041 -0.941718 -0.922216 -0.793470 -0.758435 -0.791413 0.911005 0.903283 0.905016 0.419109 0.434008 0.403738
euref_cilo 0.030020 0.203076 0.204082 0.200940 0.997451 1.000000 0.991884 -0.934483 -0.938182 -0.924828 -0.791082 -0.751612 -0.793526 0.909102 0.904527 0.900155 0.424447 0.441509 0.407166
euref_cihi 0.034251 0.193719 0.191110 0.195525 0.997891 0.991884 1.000000 -0.929004 -0.938573 -0.913228 -0.788666 -0.758063 -0.782242 0.906501 0.896017 0.903610 0.411169 0.423881 0.398003
immigcult_mean -0.029933 -0.195862 -0.202451 -0.188262 -0.935041 -0.934483 -0.929004 1.000000 0.997232 0.997174 0.818468 0.777395 0.818787 -0.907403 -0.898536 -0.900287 -0.356209 -0.378270 -0.333753
immigcult_cilo -0.029380 -0.181754 -0.186220 -0.176520 -0.941718 -0.938182 -0.938573 0.997232 1.000000 0.989445 0.812780 0.776880 0.809037 -0.909427 -0.897613 -0.905513 -0.347034 -0.366888 -0.326792
immigcult_cihi -0.027276 -0.208318 -0.217126 -0.198371 -0.922216 -0.924828 -0.913228 0.997174 0.989445 1.000000 0.819200 0.773362 0.823707 -0.899613 -0.893796 -0.889342 -0.363045 -0.387159 -0.338548
ssm_mean -0.032670 -0.314321 -0.315453 -0.310048 -0.793470 -0.791082 -0.788666 0.818468 0.812780 0.819200 1.000000 0.982120 0.985135 -0.809790 -0.796706 -0.807914 -0.483151 -0.490479 -0.471578
ssm_cilo -0.005004 -0.242739 -0.241106 -0.242573 -0.758435 -0.751612 -0.758063 0.777395 0.776880 0.773362 0.982120 1.000000 0.945905 -0.764703 -0.741007 -0.774093 -0.416634 -0.413926 -0.416356
ssm_cihi -0.052281 -0.368078 -0.372258 -0.360382 -0.791413 -0.793526 -0.782242 0.818787 0.809037 0.823707 0.985135 0.945905 1.000000 -0.811443 -0.809197 -0.798568 -0.523751 -0.540235 -0.502620
eudis_mean 0.043075 0.290781 0.292829 0.286624 0.911005 0.909102 0.906501 -0.907403 -0.909427 -0.899613 -0.809790 -0.764703 -0.811443 1.000000 0.995683 0.995677 0.492273 0.509316 0.473699
eudis_cilo 0.048560 0.318835 0.322095 0.313130 0.903283 0.904527 0.896017 -0.898536 -0.897613 -0.893796 -0.796706 -0.741007 -0.809197 0.995683 1.000000 0.985537 0.516211 0.536849 0.494130
eudis_cihi 0.036051 0.258366 0.259144 0.256078 0.905016 0.900155 0.903610 -0.900287 -0.905513 -0.889342 -0.807914 -0.774093 -0.798568 0.995677 0.985537 1.000000 0.462340 0.475675 0.448206
econlr_mean 0.068432 0.895609 0.890381 0.894761 0.419109 0.424447 0.411169 -0.356209 -0.347034 -0.363045 -0.483151 -0.416634 -0.523751 0.492273 0.516211 0.462340 1.000000 0.996566 0.996293
econlr_cilo 0.077012 0.895114 0.892278 0.891910 0.434008 0.441509 0.423881 -0.378270 -0.366888 -0.387159 -0.490479 -0.413926 -0.540235 0.509316 0.536849 0.475675 0.996566 1.000000 0.987685
econlr_cihi 0.058452 0.887197 0.879906 0.888960 0.403738 0.407166 0.398003 -0.333753 -0.326792 -0.338548 -0.471578 -0.416356 -0.502620 0.473699 0.494130 0.448206 0.996293 0.987685 1.000000

In [25]:
ax = df.plot(kind='scatter', x='euref_mean', y='immigcult_mean', figsize=(8, 8))
ax.set_ylabel("More likely to think immigration enriches Britain's cultural life")
ax.set_xlabel("% who want to leave the EU")


Out[25]:
<matplotlib.text.Text at 0x106f76a90>

I tried to replicate the economic analysis, but I counldn't find the correct dataset in the URL the authors mention in their reference (World Input-Output Database, University of Groningen, http://www.wiod.org/, 2010 data).

As of the relation between attitudes towards immigration and leave support, my lack of knowledge about UK's especific geography has not allowed me to group the dots corresponding to regions in the same area (i.e., Outer London, West Wales and the Valleys, etc.) and my scatterplot has therefore more dots than the original one. However, the higly negative correlation between attitudes towards immigration and the support to leaving the EU is still clearly shown (r = -0.935041).


In [ ]: