Sunday 23 April 2017

Getting ready for #GE2017 - a big shapefile

I'm probably as unmoved as anyone else about the forthcoming General Election, but to get my head back into gear for it I thought I'd try to put together a full UK constituency shapefile of all 650 constituency results from the 2015 General Election, using data from a variety of sources. I'm sharing it here in the hope that people will find it useful, and that it might save you some work. If you spot an error, let me know and I'll try to fix it. There are other shapfiles out there, but to my knowledge there isn't a detailed complete UK (as opposed to GB) file that has all results, MPs and so on. I'm also sharing this here in the hope that we can move away from hex maps. I think they are nice and useful in many cases but I'd like to see a move back to the standard geographic representation in this election - hence, I am trying to promote Hexit. Anyway, here's an obligatory geogif I made with the file, using the 'time results declared' field.

The 2015 General Election in 30 seconds - phew

So, what's in the file? Well, I've tried to include a lot of stuff, sourced variously from the British Election Study, from the UK Parliament Data website, the Census and the devolved administrations of the UK. I have also calculated some variables myself, such as constituency area and the order in which results were declared. Key variables include:

  • PCONCODE - this is the ONS code for each constituency. It makes it possible to join lots of other data to the file. 
  • REGN - name of the sub-UK region each constituency is in - i.e. the old Government Office Regions in England, plus Northern Ireland, Scotland and Wales.
  • SECOND - which party came second in a constituency in 2015.
  • ELECT15 - the number of people in the electorate in 2015.
  • MAJ - size of the majority for the sitting MP.
  • TIME - time the results were declared. The very last column has this in 24H format, but you can also see from the ORDER2015 field which order they are actually in.
  • MPFIRST, MPLAST, MPNAME - the first, last and full name of each MP.
  • Winner15 - this contains the full party name of the winning party. The WINNER field contains the abbreviated party name.
  • POP2015 - this contains the mid-year population estimate for each constituency for 2015. I also added in the 18+ population, since it makes a bit more sense to do this, even though it is not the same as the electorate figure. 
  • Others - they should be self-explanatory but the list of Sources below will help if you are confused by any of these.

I hope you find this useful. If you want to download it, it can be accessed here. If you spot any glaring errors, please let me know. Who is going to win the 2017 General Election? My only prediction is that there will be lots of interesting maps and that the patterns on them may look a bit different.



Data notes: I have added a QGIS qml style file to the zipped data folder. This means that if you add the shapefile to QGIS it will display in the familiar colours of each political party. This happens because the qml file has the same name as the shapefile. The colours are matched from the BBC election results page from 2015. I tried very hard to ensure complete UK coverage, so I have patched data together from multiple UK sources but in a few cases I don't have variables for Northern Ireland. This is because the spreadsheet from the British Election Study I sourced some data from covers only GB. The zipped folder name for the current file version is uk_650_wpc_2017_full_res_v1.8.

Sources: General Election 2015 results, from the UK Parliament Data pages. The British Election Study updated Excel file. Northern Ireland constituency boundaries were sourced from OpenDataNI, via their resources page. For Great Britain, I used the constituency boundaries available on the ONS Geography Portal pages - the 2016 boundaries. For the most recent mid-year population estimates, I used data from the National Records of Scotland, NISRA data for Northern Ireland mid-year population estimates and ONS mid-year population estimates for England and Wales. The map data contains OS data © Crown copyright and database right 2017. Similarly, the other data contains National Statistics data © Crown copyright and database right 2017.

Acknowledgements: I would like to thank Ian Turton for suggesting the little QGIS Atlas function tweak which enables the cumulative animation you see above. For more on this, see the related Stack Exchange post where I asked the question.