{ "cells": [ { "cell_type": "markdown", "id": "1025f03b", "metadata": {}, "source": [ "# Tutorial Exercises\n", "\n", "This week, you will be investigating attitudes to immigration using data from the European Social Survey (ESS). \n", "\n", "The ESS is a highly respected survey and uses random sampling to achieve a sample that is representative of the population. The survey includes lots of questions about the social and economic circumstances of the household as well as asking a set of questions on political preferences and attitudes. \n", "\n", "### Set up Python libraries\n", "\n", "As usual, run the code cell below to import the relevant Python libraries" ] }, { "cell_type": "code", "execution_count": 1, "id": "f9585fb9", "metadata": {}, "outputs": [], "source": [ "# Set-up Python libraries - you need to run this but you don't need to change it\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.stats as stats\n", "import pandas as pd\n", "import seaborn as sns\n", "sns.set_theme(style='white')\n", "import statsmodels.api as sm\n", "import statsmodels.formula.api as smf" ] }, { "cell_type": "markdown", "id": "b8f7ee99", "metadata": {}, "source": [ "## ESS data\n", "\n", "Today’s data file is restricted to respondents in the UK. The outcome measure of interest is ‘better’ and is a score from 0-10 in answer to the following question: “Is the UK made a worse or a better place to live by people coming to live here from other countries?” 0 is labelled as “Worse place to live” and 10 as “better place to live”, or respondents could choose an answer in between. Thus, high scores indicate more open attitudes, i.e., those who feel more positive about the consequences of immigration, and low scores the opposite. \n", "\n", "This file contains several explanatory/ controls variables: \n", "\n", "* age (a continuous measure in years)\n", "* sex (Male, Female)\n", "* educ (a categorical measure with 3 levels, where 'tertiary' is higher education such as university)\n", "* vote (a categorical measure of the party the respondent last voted for where 1 = Conservatives, 2 = Labour, 3 = any other party)\n", "* bornuk (a binary measure of whether the respondent was born in the UK where 1 = the respondent was not born in the UK, and 0 indicates they were)." ] }, { "cell_type": "code", "execution_count": 3, "id": "1b8f7d56", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | 1 | \n", "vote | \n", "better | \n", "bornuk | \n", "sex | \n", "age | \n", "educ | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "2 | \n", "Conservative | \n", "0.0 | \n", "0 | \n", "Male | \n", "75.0 | \n", "NaN | \n", "
1 | \n", "3 | \n", "Conservative | \n", "7.0 | \n", "0 | \n", "Male | \n", "70.0 | \n", "Upper secondary | \n", "
2 | \n", "4 | \n", "Conservative | \n", "8.0 | \n", "0 | \n", "Female | \n", "54.0 | \n", "Tertiary | \n", "
3 | \n", "5 | \n", "Conservative | \n", "0.0 | \n", "0 | \n", "Male | \n", "58.0 | \n", "Upper secondary | \n", "
4 | \n", "6 | \n", "Conservative | \n", "7.0 | \n", "0 | \n", "Male | \n", "76.0 | \n", "Lower secondary | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
2199 | \n", "2201 | \n", "NaN | \n", "9.0 | \n", "0 | \n", "Female | \n", "32.0 | \n", "Tertiary | \n", "
2200 | \n", "2202 | \n", "NaN | \n", "5.0 | \n", "0 | \n", "Female | \n", "69.0 | \n", "Lower secondary | \n", "
2201 | \n", "2203 | \n", "NaN | \n", "5.0 | \n", "0 | \n", "Female | \n", "34.0 | \n", "Upper secondary | \n", "
2202 | \n", "2204 | \n", "NaN | \n", "2.0 | \n", "0 | \n", "Male | \n", "23.0 | \n", "Lower secondary | \n", "
2203 | \n", "2205 | \n", "NaN | \n", "0.0 | \n", "0 | \n", "Female | \n", "54.0 | \n", "Upper secondary | \n", "
2204 rows × 7 columns
\n", "