9 Exercise 2
Create a quarto document with “Exercise 2” as title and your name as author.
Import the constituency results of the British General Elections for both 2019 and 2017. For each dataset, create a new variable called year to indicate the year of the election.
Combine them into a single dataset.
Determine the number of seats won by the Conservatives between 2017 and 2019. Also, calculate the number of seats lost by the Labour party between the two elections. (hint: Use the
first_party
variable to identify the winning party in each constituency).Convert the dataset into a longer format where all the party variables are consolidated into a single column along with their corresponding vote shares.
In 2017, which parties presented the highest and lowest number of candidates? (hint: We assume that no candidate was presented when the party received zero votes). Please provide an intuitive explanation of the results. If you are unfamiliar with the UK party system, you can find more information on this Wikipedia page.
Calculate the mean of vote shares of each party in each country. In which country do the main parties suffer the most from regionalist parties ?
Bonus (this is more difficult but you can try to challenge yourself) : On average, what is the margin of victory of the conservatives when they gain from Lab ?