library(rio)
library(dplyr)
library(stargazer)
library(texreg)
library(purrr)
library(htmlTable)
library(ggplot2)
# exclude the non EU member states which are in the dataset
exclusde.vc <- c("CY-TCC", "TR", "MK", "ME", "RS", "AL")
my.df.ex <- subset(my.df, !(isocntry %in% exclusde.vc))
View(my.df.ex)
table(my.df.ex$isocntry)
## 
##   AT   BE   BG   CY   CZ DE-E DE-W   DK   EE   ES   FI   FR   GB   GR   HR   HU 
## 1018 1012 1039  505 1013  505 1035 1022 1001 1008 1001 1014 1010 1008 1013 1011 
##   IE   IT   LT   LU   LV   MT   NL   PL   PT   RO   SE   SI   SK 
## 1013 1023 1008  510 1000  501 1006 1008 1003 1058 1023 1007 1007
# Functions to make cleaning missings and rescaling easier.

item_test <- function(x, y){
  # tests if the value x is in y and returns NA if evaluated to true or 
  # the original value if evaluated to false
  return(ifelse(x %in% y, NA, x))
}

clean_na <- function(dataset, variables, values, suffix = "_m"){
  # create a tibble with the same length as the dataset
  new_tib <- tibble::tibble(x = 1:nrow(dataset))
  for (i in variables){
    # create new name by attaching the suffix to the old variable name
    new_name <- paste0(i, suffix)
    # updated version, grep had the issue to match all variables starting with the
    # specified name. This meant that already existing variables with extensions
    # would be matched to
    # ends_with only matched the variables exactly as described because 
    # if they end with the whole specified name they cant be miss interpreted
    # select gives us back a whole data frame, however a list is needed for map
    # to get a list we use the pull function of the dplyr package and specify
    # the first (and only) variable in the data frame
    newcol <- dataset %>% select(ends_with(i)) %>% 
      pull(., var = 1) %>% 
      map(y = values, .f = item_test) %>% 
      as.numeric(unlist(.))
    
    # add the new column to the before created tibble
    # !! x := y syntax is so that new_name is evaluated as an object and not the
    # directly specified name
    new_tib <- new_tib %>% tibble::add_column(!! new_name := newcol)
  }
  # select all columns except the placeholder variable "x"
  new_tib <- new_tib %>% select(-c(x))
  # return the original data set and the tibble appended to it
  return(cbind(dataset, new_tib))
}

remap <- function(old_value, values, new_values_){
  if (old_value %in% values){
    # match the first value, as there are only distinct values in our var
    # match can be used instead to which. Which is slower
    new_val <- match(old_value, values)[1] %>% new_values_[.]
    return(new_val)
  }
  else{
    # return the old_value if its not found in the values vector as it is not 
    # supposed to be decoder
    return(old_value)
  }
}

recode_variable <- function(dataset, variables, old_values, new_values, suffix = "_re"){
  # takes two vectors and maps the old values to the new ones
  # both vectors must be equal in length and in correct order
  # index 1 of the first will be mapped to the index 1 of new_values
  
  # check for duplicates
  
  if (length(old_values) == length(new_values)){
    # duplicates has one or more True values the sum function will evaluate 
    # to < 0 and the if statement will evaluate to FALSE and the remapping
    # will not start
    if (duplicated(values_old) %>% sum(., na.rm = TRUE) == 0) {
      
      new_tib <- tibble::tibble(x = 1:nrow(dataset))
      for (i in variables){
        new_name <- paste0(i, suffix)
        # here has to be a check if the new_name is already in the data set
        # if so it has to be aborted
        if (new_name %in% colnames(dataset)){
          message(paste0(new_name, " was ommited because the variable name allready exists in dataframe."))
        }
        else {
          newcol <- dataset %>% select(ends_with(i)) %>% 
          pull(., var = 1) %>% 
          map(., values = old_values, new_values_ = new_values, .f = remap) %>% 
          # list is returned by map and this converts it to a numeric vector
          as.numeric(unlist(.))
          new_tib <- new_tib %>% tibble::add_column(!! new_name := newcol)
        }
      }
      # return the original data set and the tibble appended to it
      new_tib <- new_tib %>% select(-c(x))
      return(cbind(dataset, new_tib))
    }
    else{
      print("Error: The old values to be mapped are not unique.")
      return(none())
    }
  }
  else{
    print("Error: Vectors have different length. Must have equal length")
    return(none())
  }
}

Missing values

# Concept: Free Market and market integration in the EU/currency union
# Variables: QB2_1, QB2_2

missings_qb2 <- c(3, 4)
variables_qb2 <- c("qb2_1", "qb2_2")
my.df.ex <- my.df.ex %>% clean_na(variables_qb2, missings_qb2,  "_m")

# Concept: Free Movement
# Variables: QB9_1, QB9_2, QB5_7

missings_qb9 <- c(3, 4)
missings_qb5 <- c(3, 4)

variables_qb9 <- c("qb9_1", "qb9_2")
variables_qb5 <- c("qb5_7")

my.df.ex <- my.df.ex %>% clean_na(variables_qb9, missings_qb9, "_m")
my.df.ex <- my.df.ex %>% clean_na(variables_qb5, missings_qb5, "_m")

# Concept: Further political integration
# Variables: QB5_1, QB5_2, QB5_3, QB5_4, QB5_5

missings_qb5_2 <- c(3, 4)
variables_qb5_2 <- c("qb5_1", "qb5_2", "qb5_3", "qb5_4", "qb5_5")

my.df.ex <- my.df.ex %>% clean_na(variables_qb5_2, missings_qb5_2, "_m")

# Concept: Identity
# Variables: QC1a_1, QC1a_2, QC1a_3

missings_qc1a <- c(5)
variables_qc1a <- c("qc1a_1", "qc1a_2", "qc1a_3")
my.df.ex <- my.df.ex %>% clean_na(variables_qc1a, missings_qc1a, "_m")

# Concept: Age
# Variable: D11

missings_d11<- c(99)
variables_d11<- c("d11")
my.df.ex <- my.df.ex %>% clean_na(variables_d11, missings_d11, "_m")

# Concept: Education
# Variable: D8
table(my.df.ex$d8, useNA = "ifany")
## 
##    0    2    3    4    6    7    8    9   10   11   12   13   14   15   16   17 
##   75   27   11    2    1    8   14   27  153  140  414  204 1157 1567 1835 1708 
##   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33 
## 5463 3002 1475 1171 1251 1170 1188  985  493  299  234  121  180   53   90   43 
##   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49 
##   42   55   21   22   28   24   61   19   32   21   21   30   15    5   18   14 
##   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65 
##   25    9   10   12    6    8    2    2    6   10   13    5    5    2    2    2 
##   66   67   68   69   70   71   72   73   74   75   76   77   78   80   81   84 
##    6    2    4    3    3    2   12    2    1    6    1    1    1    1    1    1 
##   88   92   97   98   99 
##    2    1  239 1630  355
# even though 97 is not a missing code finishing full time education at 97
# should resemble an exception however in this data apparently 239 individuals
# finished at 97. Which is unlikely and is more likely error by the respondents.
missings_d8<- c(00, 01, 97, 98, 99)
variables_d8<- c("d8")
my.df.ex <- my.df.ex %>% clean_na(variables_d8, missings_d8, "_m")

# Concept: Gender
# Variable D10

table(my.df.ex$d10)
## 
##     1     2 
## 12449 14933
### No missings. All either coded male or female. ###

# Concept: City vs. Countryside
# Variable: D25

missings_d25 <- c(4)
variables_d25 <- c("d25")
my.df.ex <- my.df.ex %>% clean_na(variables_d25, missings_d25, "_m")

# Concept: Immigration
# Variables: QB7_1. QB7_2

missings_qb7 <- c(5)
variables_qb7 <- c("qb7_1", "qb7_2")
my.df.ex <- my.df.ex %>% clean_na(variables_qb7, missings_qb7, "_m")


# Concept: Knowledge of the EU
# Variables: QA11_1, QA11_2, QA11_3, QA11_4, QA11_5, QA11_6, QA11_7, QA11_8, QA11_9, QA11_10

missings_qa11 <- c(3)
variables_qa11 <- c("qa11_1", "qa11_2", "qa11_3", "qa11_4", "qa11_5", "qa11_6", "qa11_7", "qa11_8", "qa11_9", "qa11_10")
my.df.ex <- my.df.ex %>% clean_na(variables_qa11, missings_qa11,"_m")

# Concept: Occupation
# Varaibles: D15a, D15b

table(my.df.ex$d15a)
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
## 1213 1630 1549 8959  249    8  364  798  535  750  275 1850 2534  962 2048  322 
##   17   18 
## 2526  810
table(my.df.ex$d15b)
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15 
##  332    7  124  304  221  383  320 1433 1543  542 1672  315 2792 1680 1683
# has basically no missings, there are occupation which are non important to us
# but not missing. These will be dealt with further below.

Recoding/-scaling, accumulated scoring

# Concept: Free Market and market integration in the EU/currency union
# Variables: QB2_1, QB2_2
values_old <- c(1, 2)
values_new <- c(1, 0)
variables <- c("qb2_1_m", "qb2_2_m")
my.df.ex <- my.df.ex %>% recode_variable(variables, values_old, values_new)
my.df.ex <- my.df.ex %>% mutate(free_market_integration_score = (qb2_2_m_re + 
                                                                   qb2_1_m_re))

table(my.df.ex$free_market_integration_score, useNA = "ifany")
## 
##     0     1     2  <NA> 
##  2793  4707 13255  6627
# Concept: Free Movement
# Variables: QB9_1. QB9_2, QB5_7

values_old <- c(1, 2)
values_new <- c(1, 0)
variables <- c("qb9_1_m", "qb9_2_m", "qb5_7_m")
my.df.ex <- my.df.ex %>% recode_variable(variables, values_old, values_new)
my.df.ex <- my.df.ex %>% mutate(free_movement_score = (qb9_1_m_re + 
                                                         qb9_2_m_re + 
                                                         qb5_7_m_re))

table(my.df.ex$free_movement_score, useNA = "ifany")
## 
##     0     1     2     3  <NA> 
##   746   954  1153 18444  6085
# Concept: Further political integration
# Variables: QB5_1, QB5_2, QB5_3, QB5_4, QB5_5

values_old <- c(1, 2)
values_new <- c(1, 0)
variables <- c("qb5_1_m", "qb5_2_m", "qb5_3_m", "qb5_4_m", "qb5_5_m")
my.df.ex <- my.df.ex %>% recode_variable(variables, values_old, values_new)
my.df.ex <- my.df.ex %>% mutate(furhter_political_integration_score = (qb5_1_m_re + 
                                                                         qb5_2_m_re + 
                                                                         qb5_3_m_re + 
                                                                         qb5_4_m_re + 
                                                                         qb5_5_m_re))
table(my.df.ex$furhter_political_integration_score, useNA = "ifany")
## 
##     0     1     2     3     4     5  <NA> 
##  1075  1034  1517  2075  3434 12710  5537
# Concept: Identity
# Variables: QC1a_1, QC1a_2, QC1a_3
values_old <- c(1, 2, 3, 4)
values_new <- c(3, 2, 1, 0)
variables <- c("qc1a_1_m", "qc1a_2_m", "qc1a_3_m")
my.df.ex <- my.df.ex %>% recode_variable(variables, values_old, values_new)

### This is the independent variable and does not need a score. ###
### Further below is the splitting into the different ideal types of territorial identification. ###

# Concept: Age
# Variable: D11

# Age has to be subtracted by 15 so that 15 resembles the base age of respondents.
# Each increase in age means one ontop of the lowest possible to take part in
# the eurobaromenter

my.df.ex <- my.df.ex %>% mutate(age = d11_m - 15)
table(my.df.ex$age)
## 
##   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19 
##  81 161 174 263 298 270 291 290 281 267 308 261 312 321 349 388 331 379 377 350 
##  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39 
## 437 361 361 398 407 458 396 456 364 404 494 398 390 471 459 520 404 493 410 426 
##  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59 
## 562 465 428 530 496 599 477 503 489 543 601 524 525 550 543 577 473 530 408 367 
##  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79 
## 387 334 310 305 241 267 176 202 132 123  97  86  66  56  54  32  22  24  12   2 
##  80  81  82  83 
##   1   2   1   1
# Concept: Education
# Variable: D8
table(my.df.ex$d8_m)
## 
##    2    3    4    6    7    8    9   10   11   12   13   14   15   16   17   18 
##   27   11    2    1    8   14   27  153  140  414  204 1157 1567 1835 1708 5463 
##   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34 
## 3002 1475 1171 1251 1170 1188  985  493  299  234  121  180   53   90   43   42 
##   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50 
##   55   21   22   28   24   61   19   32   21   21   30   15    5   18   14   25 
##   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66 
##    9   10   12    6    8    2    2    6   10   13    5    5    2    2    2    6 
##   67   68   69   70   71   72   73   74   75   76   77   78   80   81   84   88 
##    2    4    3    3    2   12    2    1    6    1    1    1    1    1    1    2 
##   92 
##    1
my.df.ex <- my.df.ex %>% mutate(education = d8_m)
table(my.df.ex$education)
## 
##    2    3    4    6    7    8    9   10   11   12   13   14   15   16   17   18 
##   27   11    2    1    8   14   27  153  140  414  204 1157 1567 1835 1708 5463 
##   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34 
## 3002 1475 1171 1251 1170 1188  985  493  299  234  121  180   53   90   43   42 
##   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50 
##   55   21   22   28   24   61   19   32   21   21   30   15    5   18   14   25 
##   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66 
##    9   10   12    6    8    2    2    6   10   13    5    5    2    2    2    6 
##   67   68   69   70   71   72   73   74   75   76   77   78   80   81   84   88 
##    2    4    3    3    2   12    2    1    6    1    1    1    1    1    1    2 
##   92 
##    1
mean(my.df.ex$education, na.rm = TRUE)
## [1] 19.77339
### The code for No education is not in this sample. No further rescaling needed. ###

# Concept: Gender
# Variable D10

my.df.ex<- my.df.ex %>% mutate(female = case_when(is.na(d10) == T ~ NA_real_, 
                                              d10 == 1 ~ 0,
                                              d10 == 2 ~ 1,
                                              TRUE ~ NA_real_
                                              ))
table(my.df.ex$female)
## 
##     0     1 
## 12449 14933
### No score needed. ###

# Concept: Urban environment
# Variable: D25
my.df.ex <- my.df.ex %>% mutate(urban_env = case_when(is.na(d25_m) == T ~ NA_real_, 
                                              d25_m == 1 ~ 0,
                                              d25_m == 2 ~ 0,
                                              d25_m == 3 ~ 1,
                                              TRUE ~ NA_real_
                                              ))
table(my.df.ex$urban_env, useNA = "ifany")
## 
##     0     1  <NA> 
## 19521  7858     3
# Concept: Immigration
# Variables: QB7_1. QB7_2

my.df.ex <- my.df.ex %>% mutate(EU_immigration = case_when(is.na(qb7_1_m) == T ~ NA_real_, 
                                              qb7_1_m == 1 ~ 3,
                                              qb7_1_m == 2 ~ 2,
                                              qb7_1_m == 3 ~ 1,
                                              qb7_1_m == 4 ~ 0,
                                              TRUE ~ NA_real_
                                              ))
my.df.ex<- my.df.ex %>% mutate(Non_EU_immigration = case_when(is.na(qb7_2_m) == T ~ NA_real_, 
                                              qb7_2_m == 1 ~ 3,
                                              qb7_2_m == 2 ~ 2,
                                              qb7_2_m == 3 ~ 1,
                                              qb7_2_m == 4 ~ 0,
                                              TRUE ~ NA_real_
                                              ))
table(my.df.ex$EU_immigration, useNA = "ifany")
## 
##     0     1     2     3  <NA> 
##  1602  5562 13328  5399  1491
table(my.df.ex$Non_EU_immigration, useNA = "ifany")
## 
##    0    1    2    3 <NA> 
## 4912 9646 8325 2774 1725
# Concept: Knowledge of the EU
# Variables: QA11_1, QA11_2, QA11_3, QA11_4, QA11_5, QA11_6, QA11_7, QA11_8, QA11_9, QA11_10

values_old <- c(1, 2)
values_new <- c(1, 0)
variables <- c("qa11_1_m", "qa11_2_m", "qa11_3_m", "qa11_4_m", "qa11_5_m", "qa11_6_m", "qa11_7_m", "qa11_8_m", "qa11_9_m", "qa11_10_m")
my.df.ex <- my.df.ex %>% recode_variable(variables, values_old, values_new)

my.df.ex <- my.df.ex %>% mutate(knowledge_EU =  qa11_1_m_re + 
                                qa11_2_m_re + 
                                qa11_3_m_re +
                                qa11_4_m_re +
                                qa11_5_m_re +
                                qa11_6_m_re +
                                qa11_7_m_re +
                                qa11_8_m_re +
                                qa11_9_m_re +
                                qa11_10_m_re)
table(my.df.ex$knowledge_EU, useNA = "ifany")
## 
##    0    1    2    3    4    5    6    7    8    9   10 <NA> 
##  737  568  880 1475 1822 2524 3148 3158 2324 1437 7002 2307
# Concept: Occupation
# Varaibles: D15a, D15b
table(my.df.ex$d15a, useNA = "ifany")
## 
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
## 1213 1630 1549 8959  249    8  364  798  535  750  275 1850 2534  962 2048  322 
##   17   18 
## 2526  810
table(my.df.ex$d15b, useNA = "ifany")
## 
##     1     2     3     4     5     6     7     8     9    10    11    12    13 
##   332     7   124   304   221   383   320  1433  1543   542  1672   315  2792 
##    14    15  <NA> 
##  1680  1683 14031
d15 <- my.df.ex %>% select(d15a, d15b)
d15
# if they have a value on the first variable then the second will be missing
# it does not matter for me if the second variable has an NA or not. 
# As long as it equals 9 or 11 the respondent is from the management level.
my.df.ex <- my.df.ex %>% mutate(management = ifelse(
  d15a %in% c(1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 16, 17, 18) & 
    d15b %in% c(1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, NA),
  0,
  1
))
table(my.df.ex$management, useNA = "ifany")
## 
##     0     1 
## 23042  4340

Country Factor Variable

table(my.df.ex$isocntry, useNA = "ifany")
## 
##   AT   BE   BG   CY   CZ DE-E DE-W   DK   EE   ES   FI   FR   GB   GR   HR   HU 
## 1018 1012 1039  505 1013  505 1035 1022 1001 1008 1001 1014 1010 1008 1013 1011 
##   IE   IT   LT   LU   LV   MT   NL   PL   PT   RO   SE   SI   SK 
## 1013 1023 1008  510 1000  501 1006 1008 1003 1058 1023 1007 1007
my.df.ex <- my.df.ex %>% mutate(country = ifelse(isocntry == "DE-E" | 
                                                 isocntry =="DE-W", "DE", isocntry))
table(my.df.ex$country, useNA = "ifany")
## 
##   AT   BE   BG   CY   CZ   DE   DK   EE   ES   FI   FR   GB   GR   HR   HU   IE 
## 1018 1012 1039  505 1013 1540 1022 1001 1008 1001 1014 1010 1008 1013 1011 1013 
##   IT   LT   LU   LV   MT   NL   PL   PT   RO   SE   SI   SK 
## 1023 1008  510 1000  501 1006 1008 1003 1058 1023 1007 1007

Constructing the six different ideal types of identification

# Concept: Identity
# Variables: QC1a_1, QC1a_2, QC1a_3, QC1a_4

# Is that orientation the best? 
my.df.ex$id_type <- 100 * my.df.ex$qc1a_1_m_re + 
  10 * my.df.ex$qc1a_2_m_re + 
  1 * my.df.ex$qc1a_3_m_re 

table(my.df.ex$id_type, useNA = "ifany")
## 
##    0    1    2    3   10   11   12   13   20   21   22   23   30   31   32   33 
##  106   10    9    2   18   15   17    1   26   31   44    9   30   17   34   13 
##  100  101  102  103  110  111  112  113  120  121  122  123  130  131  132  133 
##   32   11    7    5   96  383  125   19  128  312  397   58   86  151  208   82 
##  200  201  202  203  210  211  212  213  220  221  222  223  230  231  232  233 
##   25   20   14    3   82  232  153   57  475 2220 3218  188  228  753 1261  406 
##  300  301  302  303  310  311  312  313  320  321  322  323  330  331  332  333 
##   25   11   16    8   50  120   56   11  207  651  714  105 1340 3179 5065 3449 
## <NA> 
##  558
class(my.df.ex$id_type)
## [1] "numeric"
# classifing the id_types as the 6 different territorial identities
supranationalist.vc <- as.numeric(c(2:3,
                                    12:13,
                                    22:23,
                                    32,
                                    102:103,
                                    112:113,
                                    122:123,
                                    132:133,
                                    223))
localist.vc <- as.numeric(c(200:201,
                            210:211,
                            301,
                            310:311,
                            320:321))
nationalist.vc <- as.numeric(c(20:21,
                               30:31,
                               120:121,
                               130:131,
                               220:221,
                               230:231,
                               330:331))
cosmopolit.vc <- as.numeric(c(33,
                              222,
                              232:233,
                              322:323,
                              332:333))
apolide.vc <- as.numeric(c(0:1,
                           10:11,
                           100:101,
                           110:111))
glocalist.vc <- as.numeric(c(202:203,
                             212:213,
                             302:303,
                             312:313))

my.df.ex <- my.df.ex %>% mutate(supranationalist = 
                            if_else(id_type %in% supranationalist.vc, 1, 0))
my.df.ex <- my.df.ex %>% mutate(localist = 
                            if_else(id_type %in% localist.vc, 1, 0))
my.df.ex <- my.df.ex %>% mutate(nationalist = 
                            if_else(id_type %in% nationalist.vc, 1, 0))
my.df.ex <- my.df.ex %>% mutate(cosmopolit = 
                            if_else(id_type %in% cosmopolit.vc, 1, 0))
my.df.ex <- my.df.ex %>% mutate(apolide = 
                            if_else(id_type %in% apolide.vc, 1, 0)) # will be excluded later
my.df.ex <- my.df.ex %>% mutate(glocalist = 
                            if_else(id_type %in% glocalist.vc, 1, 0))


table(my.df.ex$supranationalist, useNA = "ifany")
## 
##     0     1 
## 26177  1205
table(my.df.ex$localist, useNA = "ifany")
## 
##     0     1 
## 25984  1398
table(my.df.ex$nationalist, useNA = "ifany")
## 
##     0     1 
## 18406  8976
table(my.df.ex$cosmopolit, useNA = "ifany")
## 
##     0     1 
## 13151 14231
table(my.df.ex$apolide, useNA = "ifany")
## 
##     0     1 
## 26711   671
table(my.df.ex$glocalist, useNA = "ifany")
## 
##     0     1 
## 27064   318
# appolides dropped, resulting in 671 cases "lost"
# dropped them because they do not hold any identity and hence can not be
# interpreted along the exclusive/inclusive axis as they do not fit any of these
# categories

# edge cases in the topology above will not result in unclear results
# because they are most likely ending up in the same category anyway
# in this step
my.df.ex <- my.df.ex %>% mutate(inclusive = ifelse(supranationalist == 1 |
                                               cosmopolit == 1 | 
                                               glocalist == 1, 1, 0))
my.df.ex <- my.df.ex %>% mutate(exclusive = ifelse(localist == 1 | 
                                               nationalist == 1, 1, 0))

table(my.df.ex$inclusive)
## 
##     0     1 
## 11628 15754
table(my.df.ex$exclusive)
## 
##     0     1 
## 17008 10374

linear regression analysis

vars_in_model.vc <- c("inclusive", 
                   "exclusive",
                    "country",
                   "age",
                   "knowledge_EU", 
                   "EU_immigration", 
                   "Non_EU_immigration", 
                   "urban_env",
                   "female",
                   "education",
                   "free_market_integration_score",
                   "furhter_political_integration_score",
                   "free_movement_score",
                   "management")

my.df.filtered <- my.df.ex[vars_in_model.vc]
#View(my.df.de.filtered)
#nrow(my.df.de.filtered)
#names(my.df.de.filtered)
#Listwise deletion
my.df.listw <- na.omit(my.df.filtered)

# standardization of the beta coefficients to compare who has the greatest impact
# but I cant use the country variable as it cant be standardized.
`%!in%` = Negate(`%in%`)

x <- my.df.listw$country
country_codes <- c()
# getting every country code
for (i in x){
  if (i %!in% country_codes){
    country_codes <- append(country_codes, i)
  }
}
# creating dummy variables for every country
for (i in country_codes){
  my.df.listw <- my.df.listw %>% mutate(., !! i := ifelse(country == i, 1, 0))
}
my.df.std <- as.data.frame(scale(select(my.df.listw, -one_of("country"))))

Summary statistics

[1] 12687 12687 12687 12687 12687 12687 12687 12687 12687 12687 12687 12687 [1] 1.5609679 4.1415622 2.7298810 0.6609127 37.2858044 20.0284543 [7] 7.2747694 0.5177741 0.1559864 0.2934500 1.9820288 1.4435249 [1] 0.6847700 1.3612667 0.7212514 0.4734182 16.2743207 5.7738581 [7] 2.6368601 0.4997037 0.3628568 0.4553608 0.7801890 0.9105200 [1] 0 0 0 0 0 2 0 0 0 0 0 0 [1] 2 5 3 1 81 81 10 1 1 1 3 3
Variable Variable label Obs Mean SD Min Max
free_market_integration_score Free Market Integration Support 12687 1.561 0.685 0 2
furhter_political_integration_score further Political Integration Support 12687 4.142 1.361 0 5
free_movement_score Free Movement Supportt 12687 2.730 0.721 0 3
inclusive Inclusive Identity 12687 0.661 0.473 0 1
age Age 12687 37.286 16.274 0 81
education Education 12687 20.028 5.774 2 81
knowledge_EU Knowledge about the EU 12687 7.275 2.637 0 10
female Female 12687 0.518 0.500 0 1
management Management Position 12687 0.156 0.363 0 1
urban_env Urban Environment 12687 0.293 0.455 0 1
EU_immigration EU Immigration Support 12687 1.982 0.780 0 3
Non_EU_immigration Non-EU Immigration Support 12687 1.444 0.911 0 3
Variable Variable label Obs Mean SD Min Max
free_market_integration_score Free Market Integration Support 12687 1.561 0.685 0 2
furhter_political_integration_score further Political Integration Support 12687 4.142 1.361 0 5
free_movement_score Free Movement Supportt 12687 2.730 0.721 0 3
inclusive Inclusive Identity 12687 0.661 0.473 0 1
age Age 12687 37.286 16.274 0 81
education Education 12687 20.028 5.774 2 81
knowledge_EU Knowledge about the EU 12687 7.275 2.637 0 10
female Female 12687 0.518 0.500 0 1
management Management Position 12687 0.156 0.363 0 1
urban_env Urban Environment 12687 0.293 0.455 0 1
EU_immigration EU Immigration Support 12687 1.982 0.780 0 3
Non_EU_immigration Non-EU Immigration Support 12687 1.444 0.911 0 3

Full Model

#  first do inclusvie b1a.lw
# then do inclusive plus country dummy b1b.lw

b1a.lw <- lm(free_market_integration_score  ~ inclusive, data = my.df.listw)
b1b.lw <- lm(free_market_integration_score  ~ inclusive + country, data = my.df.listw)

b2a.lw <- lm(furhter_political_integration_score  ~ inclusive, data = my.df.listw)
b2b.lw <- lm(furhter_political_integration_score  ~ inclusive + country, data = my.df.listw)

b3a.lw <- lm(free_movement_score  ~ inclusive, data = my.df.listw)
b3b.lw <- lm(free_movement_score  ~ inclusive + country, data = my.df.listw)

m1.lw <- lm(free_market_integration_score  ~ inclusive + 
              age + 
              education +
              knowledge_EU + 
              female + 
              management + 
              urban_env + 
              EU_immigration + 
              Non_EU_immigration +
              country,
            data = my.df.listw)

m2.lw <- lm(furhter_political_integration_score  ~ inclusive + 
              age + 
              education +
              knowledge_EU + 
              female + 
              management + 
              urban_env + 
              EU_immigration + 
              Non_EU_immigration +
              country,
            data = my.df.listw)

m3.lw <- lm(free_movement_score  ~ inclusive + 
              age + 
              education +
              knowledge_EU + 
              female + 
              management + 
              urban_env + 
              EU_immigration + 
              Non_EU_immigration +
              country,
            data = my.df.listw)

b1a.lw
## 
## Call:
## lm(formula = free_market_integration_score ~ inclusive, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive  
##      1.2799       0.4253
b1b.lw
## 
## Call:
## lm(formula = free_market_integration_score ~ inclusive + country, 
##     data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive    countryBE    countryBG    countryCY    countryCZ  
##   1.1741885    0.3924055    0.1900415   -0.0591105    0.3614935   -0.3478740  
##   countryDE    countryDK    countryEE    countryES    countryFI    countryFR  
##   0.2756664   -0.3061030    0.4735795    0.2695252    0.2124429    0.1549873  
##   countryGB    countryGR    countryHR    countryHU    countryIE    countryIT  
##  -0.4008313    0.2757694    0.0008418    0.0813340    0.3303251   -0.0307192  
##   countryLT    countryLU    countryLV    countryMT    countryNL    countryPL  
##   0.3523734    0.2684351    0.3497893    0.2721016    0.2276105   -0.1846925  
##   countryPT    countryRO    countrySE    countrySI    countrySK  
##   0.3041094    0.0458101   -0.4414521    0.4156892    0.2414589
b2a.lw
## 
## Call:
## lm(formula = furhter_political_integration_score ~ inclusive, 
##     data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive  
##      3.5823       0.8462
b2b.lw
## 
## Call:
## lm(formula = furhter_political_integration_score ~ inclusive + 
##     country, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive    countryBE    countryBG    countryCY    countryCZ  
##      2.8661       0.8197       0.9238       0.8973       1.4104       0.2120  
##   countryDE    countryDK    countryEE    countryES    countryFI    countryFR  
##      1.0898       0.3706       0.8130       1.1808       0.3999       0.8977  
##   countryGB    countryGR    countryHR    countryHU    countryIE    countryIT  
##      0.1142       1.0674       0.8170       0.3697       0.8886       0.4194  
##   countryLT    countryLU    countryLV    countryMT    countryNL    countryPL  
##      1.2361       0.9160       0.7473       0.8183       0.9952       0.5551  
##   countryPT    countryRO    countrySE    countrySI    countrySK  
##      0.8501       0.5613       0.3008       1.0589       0.4230
b3a.lw
## 
## Call:
## lm(formula = free_movement_score ~ inclusive, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive  
##      2.4986       0.3499
b3b.lw
## 
## Call:
## lm(formula = free_movement_score ~ inclusive + country, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive    countryBE    countryBG    countryCY    countryCZ  
##     2.05910      0.34578      0.33829      0.58006      0.62040      0.49773  
##   countryDE    countryDK    countryEE    countryES    countryFI    countryFR  
##     0.52594      0.38275      0.66954      0.56741      0.57467      0.44237  
##   countryGB    countryGR    countryHR    countryHU    countryIE    countryIT  
##     0.20410      0.50429      0.53594      0.31509      0.47631      0.05204  
##   countryLT    countryLU    countryLV    countryMT    countryNL    countryPL  
##     0.64859      0.54761      0.54135      0.53522      0.42370      0.35078  
##   countryPT    countryRO    countrySE    countrySI    countrySK  
##     0.57562      0.21704      0.48091      0.49137      0.44475
m1.lw
## 
## Call:
## lm(formula = free_market_integration_score ~ inclusive + age + 
##     education + knowledge_EU + female + management + urban_env + 
##     EU_immigration + Non_EU_immigration + country, data = my.df.listw)
## 
## Coefficients:
##        (Intercept)           inclusive                 age           education  
##          0.7860720           0.3204436          -0.0003070           0.0001788  
##       knowledge_EU              female          management           urban_env  
##          0.0269554          -0.0239004          -0.0173994           0.0104355  
##     EU_immigration  Non_EU_immigration           countryBE           countryBG  
##          0.1102858           0.0216987           0.2293725          -0.0696785  
##          countryCY           countryCZ           countryDE           countryDK  
##          0.3845033          -0.2741017           0.2820351          -0.3125707  
##          countryEE           countryES           countryFI           countryFR  
##          0.4820770           0.2186708           0.1827724           0.2036708  
##          countryGB           countryGR           countryHR           countryHU  
##         -0.3970487           0.2839797          -0.0076985           0.1127347  
##          countryIE           countryIT           countryLT           countryLU  
##          0.2852110           0.0220782           0.3501848           0.2501540  
##          countryLV           countryMT           countryNL           countryPL  
##          0.4291180           0.2737118           0.2514142          -0.1738668  
##          countryPT           countryRO           countrySE           countrySI  
##          0.2660433           0.0504636          -0.4233962           0.4020582  
##          countrySK  
##          0.2906875
m2.lw
## 
## Call:
## lm(formula = furhter_political_integration_score ~ inclusive + 
##     age + education + knowledge_EU + female + management + urban_env + 
##     EU_immigration + Non_EU_immigration + country, data = my.df.listw)
## 
## Coefficients:
##        (Intercept)           inclusive                 age           education  
##          1.9289235           0.6625305           0.0008618          -0.0007864  
##       knowledge_EU              female          management           urban_env  
##          0.0556230           0.0529638           0.0482060          -0.0179294  
##     EU_immigration  Non_EU_immigration           countryBE           countryBG  
##          0.2561005           0.0482663           1.0054989           0.8848587  
##          countryCY           countryCZ           countryDE           countryDK  
##          1.4567105           0.3820092           1.0896743           0.3509701  
##          countryEE           countryES           countryFI           countryFR  
##          0.8195324           1.0658571           0.3148121           0.9907898  
##          countryGB           countryGR           countryHR           countryHU  
##          0.1138505           1.0908714           0.7873753           0.4307867  
##          countryIE           countryIT           countryLT           countryLU  
##          0.7807888           0.5230995           1.2134238           0.8755878  
##          countryLV           countryMT           countryNL           countryPL  
##          0.9011392           0.8221144           1.0152291           0.5732232  
##          countryPT           countryRO           countrySE           countrySI  
##          0.7593104           0.5754552           0.3283908           1.0301337  
##          countrySK  
##          0.5171326
m3.lw
## 
## Call:
## lm(formula = free_movement_score ~ inclusive + age + education + 
##     knowledge_EU + female + management + urban_env + EU_immigration + 
##     Non_EU_immigration + country, data = my.df.listw)
## 
## Coefficients:
##        (Intercept)           inclusive                 age           education  
##          1.4249458           0.2292343          -0.0010522           0.0002844  
##       knowledge_EU              female          management           urban_env  
##          0.0337767           0.0098835           0.0374268          -0.0104015  
##     EU_immigration  Non_EU_immigration           countryBE           countryBG  
##          0.2503935          -0.0115543           0.4098042           0.5438453  
##          countryCY           countryCZ           countryDE           countryDK  
##          0.6524004           0.6072042           0.5279240           0.3560368  
##          countryEE           countryES           countryFI           countryFR  
##          0.6644791           0.4968654           0.5143730           0.5167497  
##          countryGB           countryGR           countryHR           countryHU  
##          0.2190506           0.5165861           0.5099501           0.3512261  
##          countryIE           countryIT           countryLT           countryLU  
##          0.4054057           0.1397117           0.6364943           0.5201978  
##          countryLV           countryMT           countryNL           countryPL  
##          0.6503121           0.5378338           0.4559306           0.3572875  
##          countryPT           countryRO           countrySE           countrySI  
##          0.5358963           0.2371276           0.5015406           0.4706039  
##          countrySK  
##          0.5140533

Standardized Beta

# only needed for the full models as the point of standardized beta is to 
# compare the coefficients of the variables

# country variable can not be included as it can not be standardized.
# Either do a dummy variable for every country or so.
m1.lw.std <- lm(free_market_integration_score  ~ inclusive + 
              age + 
              education +
              knowledge_EU + 
              female + 
              management + 
              urban_env + 
              EU_immigration + 
              Non_EU_immigration +
              BE +
                BG +
                CY +
                CZ +
                DE +
                DK +
                EE +
                ES +
                FI +
                FR +
                GB +
                GR +
                HR +
                HU +
                IE +
                IT +
                LT +
                LU +
                LV +
                MT +
                NL +
                PL +
                PT +
                RO +
                SE +
                SI +
                SK,
            data = my.df.std)

m2.lw.std <- lm(furhter_political_integration_score  ~ inclusive + 
              age + 
              education +
              knowledge_EU + 
              female + 
              management + 
              urban_env + 
              EU_immigration + 
              Non_EU_immigration +
              BE +
                BG +
                CY +
                CZ +
                DE +
                DK +
                EE +
                ES +
                FI +
                FR +
                GB +
                GR +
                HR +
                HU +
                IE +
                IT +
                LT +
                LU +
                LV +
                MT +
                NL +
                PL +
                PT +
                RO +
                SE +
                SI +
                SK,
            data = my.df.std)

m3.lw.std <- lm(free_movement_score  ~ inclusive + 
              age + 
              education +
              knowledge_EU + 
              female + 
              management + 
              urban_env + 
              EU_immigration + 
              Non_EU_immigration +
              BE +
                BG +
                CY +
                CZ +
                DE +
                DK +
                EE +
                ES +
                FI +
                FR +
                GB +
                GR +
                HR +
                HU +
                IE +
                IT +
                LT +
                LU +
                LV +
                MT +
                NL +
                PL +
                PT +
                RO +
                SE +
                SI +
                SK,
            data = my.df.std)

summary(m1.lw.std)
## 
## Call:
## lm(formula = free_market_integration_score ~ inclusive + age + 
##     education + knowledge_EU + female + management + urban_env + 
##     EU_immigration + Non_EU_immigration + BE + BG + CY + CZ + 
##     DE + DK + EE + ES + FI + FR + GB + GR + HR + HU + IE + IT + 
##     LT + LU + LV + MT + NL + PL + PT + RO + SE + SI + SK, data = my.df.std)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1798 -0.4389  0.2005  0.5755  2.1509 
## 
## Coefficients:
##                                 Estimate            Std. Error t value
## (Intercept)        -0.000000000000005623  0.007742548162061573   0.000
## inclusive           0.221539810355539823  0.008310637906067207  26.657
## age                -0.007297263971145803  0.008141285825490728  -0.896
## education           0.001507296400899489  0.008251245278214433   0.183
## knowledge_EU        0.103797832660394995  0.008144740694760568  12.744
## female             -0.017441089995939407  0.007852750468428966  -2.221
## management         -0.009219853066675129  0.007938913859223216  -1.161
## urban_env           0.006939437657800075  0.007986743109826500   0.869
## EU_immigration      0.125653548700062734  0.009048560519445656  13.887
## Non_EU_immigration  0.028852153772762925  0.009366570846780642   3.080
## BE                  0.072218815382963333  0.011498792016549705   6.281
## BG                 -0.016172767238060159  0.009968274524347636  -1.622
## CY                  0.078653550208589287  0.009499119051985073   8.280
## CZ                 -0.074749661349720747  0.010715797377532817  -6.976
## DE                  0.098044195937440751  0.012164553274237532   8.060
## DK                 -0.070588196292991984  0.009950170035815612  -7.094
## EE                  0.123467396188947406  0.010415067604880023  11.855
## ES                  0.064637565095944871  0.011123173031499614   5.811
## FI                  0.047202198769654972  0.010541387415216966   4.478
## FR                  0.052412949792162947  0.010402931476225785   5.038
## GB                 -0.098585843722477376  0.010242378834097191  -9.625
## GR                  0.081767583315534548  0.011010435233198581   7.426
## HR                 -0.002369377310409559  0.011305549293477208  -0.210
## HU                  0.035711387915485823  0.011525129234201856   3.099
## IE                  0.083335650449251508  0.011048508419972637   7.543
## IT                  0.005880107730322175  0.010565133965627695   0.557
## LT                  0.099790627288889086  0.010897140374852905   9.158
## LU                  0.047044973324925597  0.009288911700876385   5.065
## LV                  0.116408472548668041  0.010733159908306358  10.846
## MT                  0.042343713907177880  0.008813772109451569   4.804
## NL                  0.069842589825330051  0.010851220556214951   6.436
## PL                 -0.047958026147258540  0.010723142535793550  -4.472
## PT                  0.073458283259783833  0.010782511393557645   6.813
## RO                  0.013747388127490006  0.010648352681947360   1.291
## SE                 -0.109730777223954898  0.010630180364956813 -10.323
## SI                  0.119885583241121224  0.011182581609993081  10.721
## SK                  0.080180909299152517  0.010782447835699996   7.436
##                                Pr(>|t|)    
## (Intercept)                     1.00000    
## inclusive          < 0.0000000000000002 ***
## age                             0.37009    
## education                       0.85506    
## knowledge_EU       < 0.0000000000000002 ***
## female                          0.02637 *  
## management                      0.24552    
## urban_env                       0.38493    
## EU_immigration     < 0.0000000000000002 ***
## Non_EU_immigration              0.00207 ** 
## BE                 0.000000000348411813 ***
## BG                              0.10474    
## CY                 < 0.0000000000000002 ***
## CZ                 0.000000000003196126 ***
## DE                 0.000000000000000832 ***
## DK                 0.000000000001370612 ***
## EE                 < 0.0000000000000002 ***
## ES                 0.000000006356976235 ***
## FI                 0.000007607717970172 ***
## FR                 0.000000476199558535 ***
## GB                 < 0.0000000000000002 ***
## GR                 0.000000000000118768 ***
## HR                              0.83400    
## HU                              0.00195 ** 
## IE                 0.000000000000049173 ***
## IT                              0.57784    
## LT                 < 0.0000000000000002 ***
## LU                 0.000000414939392999 ***
## LV                 < 0.0000000000000002 ***
## MT                 0.000001571022193955 ***
## NL                 0.000000000126772414 ***
## PL                 0.000007802576524706 ***
## PT                 0.000000000010010340 ***
## RO                              0.19672    
## SE                 < 0.0000000000000002 ***
## SI                 < 0.0000000000000002 ***
## SK                 0.000000000000110261 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8721 on 12650 degrees of freedom
## Multiple R-squared:  0.2416, Adjusted R-squared:  0.2395 
## F-statistic: 111.9 on 36 and 12650 DF,  p-value: < 0.00000000000000022
summary(m2.lw.std)
## 
## Call:
## lm(formula = furhter_political_integration_score ~ inclusive + 
##     age + education + knowledge_EU + female + management + urban_env + 
##     EU_immigration + Non_EU_immigration + BE + BG + CY + CZ + 
##     DE + DK + EE + ES + FI + FR + GB + GR + HR + HU + IE + IT + 
##     LT + LU + LV + MT + NL + PL + PT + RO + SE + SI + SK, data = my.df.std)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.6256 -0.3179  0.2248  0.5836  1.9674 
## 
## Coefficients:
##                                Estimate           Std. Error t value
## (Intercept)        -0.00000000000001135  0.00800391946698140   0.000
## inclusive           0.23041330308572011  0.00859118666453262  26.820
## age                 0.01030251700636753  0.00841611763220270   1.224
## education          -0.00333548626525790  0.00852978907289795  -0.391
## knowledge_EU        0.10774534014494654  0.00841968913021937  12.797
## female              0.01944232025167897  0.00811784195952233   2.395
## management          0.01284971707269694  0.00820691403585742   1.566
## urban_env          -0.00599759692140784  0.00825635789619665  -0.726
## EU_immigration      0.14678002282821234  0.00935401991357668  15.692
## Non_EU_immigration  0.03228423208954058  0.00968276556634894   3.334
## BE                  0.15925462679725497  0.01188696580784674  13.397
## BG                  0.10331441274550060  0.01030478142952834  10.026
## CY                  0.14989703564644496  0.00981978830585835  15.265
## CZ                  0.05240501414309681  0.01107753900124608   4.731
## DE                  0.19055350908176913  0.01257520169340186  15.153
## DK                  0.03987083849961567  0.01028606577349777   3.876
## EE                  0.10558531426549543  0.01076665725646973   9.807
## ES                  0.15848740135038145  0.01149866675646445  13.783
## FI                  0.04089822829698343  0.01089724134427372   3.753
## FR                  0.12826048894659545  0.01075411143894865  11.927
## GB                  0.01422025262381267  0.01058813889465049   1.343
## GR                  0.15800429713541894  0.01138212317938891  13.882
## HR                  0.12190214626435360  0.01168719963775932  10.430
## HU                  0.06864559975286423  0.01191419211172756   5.762
## IE                  0.11476242109589065  0.01142148163275755  10.048
## IT                  0.07008224919081006  0.01092178952571577   6.417
## LT                  0.17394277798496602  0.01126500373715345  15.441
## LU                  0.08283369181018874  0.00960248481940597   8.626
## LV                  0.12297058774418947  0.01109548765266491  11.083
## MT                  0.06397778036569884  0.00911130556604682   7.022
## NL                  0.14187179231647273  0.01121753376698039  12.647
## PL                  0.07953713230826420  0.01108513211580741   7.175
## PT                  0.10546522899708580  0.01114650513492776   9.462
## RO                  0.07885961998334370  0.01100781752187754   7.164
## SE                  0.04281284379143144  0.01098903174764968   3.896
## SI                  0.15451588012233286  0.01156008083719817  13.366
## SK                  0.07175432453144803  0.01114643943149738   6.437
##                                Pr(>|t|)    
## (Intercept)                    1.000000    
## inclusive          < 0.0000000000000002 ***
## age                            0.220922    
## education                      0.695774    
## knowledge_EU       < 0.0000000000000002 ***
## female                         0.016634 *  
## management                     0.117440    
## urban_env                      0.467594    
## EU_immigration     < 0.0000000000000002 ***
## Non_EU_immigration             0.000858 ***
## BE                 < 0.0000000000000002 ***
## BG                 < 0.0000000000000002 ***
## CY                 < 0.0000000000000002 ***
## CZ                    0.000002261162833 ***
## DE                 < 0.0000000000000002 ***
## DK                             0.000107 ***
## EE                 < 0.0000000000000002 ***
## ES                 < 0.0000000000000002 ***
## FI                             0.000175 ***
## FR                 < 0.0000000000000002 ***
## GB                             0.179284    
## GR                 < 0.0000000000000002 ***
## HR                 < 0.0000000000000002 ***
## HU                    0.000000008522837 ***
## IE                 < 0.0000000000000002 ***
## IT                    0.000000000144191 ***
## LT                 < 0.0000000000000002 ***
## LU                 < 0.0000000000000002 ***
## LV                 < 0.0000000000000002 ***
## MT                    0.000000000002302 ***
## NL                 < 0.0000000000000002 ***
## PL                    0.000000000000763 ***
## PT                 < 0.0000000000000002 ***
## RO                    0.000000000000827 ***
## SE                    0.000098313628559 ***
## SI                 < 0.0000000000000002 ***
## SK                    0.000000000125910 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9015 on 12650 degrees of freedom
## Multiple R-squared:  0.1895, Adjusted R-squared:  0.1872 
## F-statistic: 82.18 on 36 and 12650 DF,  p-value: < 0.00000000000000022
summary(m3.lw.std)
## 
## Call:
## lm(formula = free_movement_score ~ inclusive + age + education + 
##     knowledge_EU + female + management + urban_env + EU_immigration + 
##     Non_EU_immigration + BE + BG + CY + CZ + DE + DK + EE + ES + 
##     FI + FR + GB + GR + HR + HU + IE + IT + LT + LU + LV + MT + 
##     NL + PL + PT + RO + SE + SI + SK, data = my.df.std)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2126 -0.1205  0.1918  0.4920  1.8795 
## 
## Coefficients:
##                                Estimate           Std. Error t value
## (Intercept)        -0.00000000000001249  0.00802657502889756   0.000
## inclusive           0.15046581647216392  0.00861550452057984  17.465
## age                -0.02374124635897282  0.00843993994512035  -2.813
## education           0.00227670654656636  0.00855393313947309   0.266
## knowledge_EU        0.12348587273744874  0.00844352155247092  14.625
## female              0.00684760328465412  0.00814081998571291   0.841
## management          0.01882916151223077  0.00823014418576672   2.288
## urban_env          -0.00656693987275517  0.00827972799984286  -0.793
## EU_immigration      0.27085454715906321  0.00938049701372633  28.874
## Non_EU_immigration -0.01458631972317059  0.00971017320028542  -1.502
## BE                  0.12250205617001800  0.01192061255941214  10.276
## BG                  0.11984473101893257  0.01033394971572515  11.597
## CY                  0.12670407954380256  0.00984758379066860  12.867
## CZ                  0.15721367954870658  0.01110889462292077  14.152
## DE                  0.17424013070459676  0.01261079653687178  13.817
## DK                  0.07633730152782314  0.01031518108393618   7.400
## EE                  0.16157542289312379  0.01079713290919341  14.965
## ES                  0.13944117750778745  0.01153121440486709  12.092
## FI                  0.12612110954101155  0.01092808662289115  11.541
## FR                  0.12625486676873607  0.01078455158000247  11.707
## GB                  0.05163844572096456  0.01061810924071584   4.863
## GR                  0.14121948414008170  0.01141434094438415  12.372
## HR                  0.14900947162356906  0.01172028093950305  12.714
## HU                  0.10563157888282453  0.01194791592893759   8.841
## IE                  0.11246374846773992  0.01145381080415572   9.819
## IT                  0.03532750493829222  0.01095270428939572   3.225
## LT                  0.17220468507602738  0.01129688998872129  15.244
## LU                  0.09288216793241234  0.00962966521399546   9.645
## LV                  0.16748958327088767  0.01112689407904663  15.053
## MT                  0.07899535604891469  0.00913709564904805   8.646
## NL                  0.12025061029596081  0.01124928565202281  10.690
## PL                  0.09356653251676626  0.01111650923023672   8.417
## PT                  0.14048412379182179  0.01117805596927522  12.568
## RO                  0.06133126438647994  0.01103897579282935   5.556
## SE                  0.12340868558778087  0.01102013684436943  11.198
## SI                  0.13322680645739091  0.01159280232174625  11.492
## SK                  0.13462041178337789  0.01117799007986744  12.043
##                                Pr(>|t|)    
## (Intercept)                     1.00000    
## inclusive          < 0.0000000000000002 ***
## age                             0.00492 ** 
## education                       0.79012    
## knowledge_EU       < 0.0000000000000002 ***
## female                          0.40028    
## management                      0.02216 *  
## urban_env                       0.42771    
## EU_immigration     < 0.0000000000000002 ***
## Non_EU_immigration              0.13308    
## BE                 < 0.0000000000000002 ***
## BG                 < 0.0000000000000002 ***
## CY                 < 0.0000000000000002 ***
## CZ                 < 0.0000000000000002 ***
## DE                 < 0.0000000000000002 ***
## DK                    0.000000000000144 ***
## EE                 < 0.0000000000000002 ***
## ES                 < 0.0000000000000002 ***
## FI                 < 0.0000000000000002 ***
## FR                 < 0.0000000000000002 ***
## GB                    0.000001168673676 ***
## GR                 < 0.0000000000000002 ***
## HR                 < 0.0000000000000002 ***
## HU                 < 0.0000000000000002 ***
## IE                 < 0.0000000000000002 ***
## IT                              0.00126 ** 
## LT                 < 0.0000000000000002 ***
## LU                 < 0.0000000000000002 ***
## LV                 < 0.0000000000000002 ***
## MT                 < 0.0000000000000002 ***
## NL                 < 0.0000000000000002 ***
## PL                 < 0.0000000000000002 ***
## PT                 < 0.0000000000000002 ***
## RO                    0.000000028179156 ***
## SE                 < 0.0000000000000002 ***
## SI                 < 0.0000000000000002 ***
## SK                 < 0.0000000000000002 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9041 on 12650 degrees of freedom
## Multiple R-squared:  0.1849, Adjusted R-squared:  0.1826 
## F-statistic: 79.74 on 36 and 12650 DF,  p-value: < 0.00000000000000022
stargazer(m1.lw.std,
          m2.lw.std,
          m3.lw.std,
          title = "Table 2: Standardized models",
          covariate.labels = c("Inclusive Identity",
                               "Age",
                               "Education",
                               "Knowledge of the EU",
                               "Female",
                               "Management Position",
                               "Urban Environment",
                              "EU Immigration",
                              "Non EU Immigration",
                              "Intercept"),
          omit = c("BE",
                "BG",
                "CY",
                "CZ",
                "DE",
                "DK",
                "EE",
                "ES",
                "FI",
                "FR",
                "GB",
                "GR",
                "HR",
                "HU",
                "IE",
                "IT",
                "LT",
                "LU",
                "LV",
                "MT",
                "NL",
                "PL",
                "PT",
                "RO",
                "SE",
                "SI",
                "SK"), # excludes the country variable to be displayed in the table.
                               # The variable is only used to control for effects and does not have to be in the table.
          keep.stat = c("n", "rsq"),
          notes = "Country dummies not displayed in table, but included in regression",
          out = "models_standardized_beta.html")
% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu % Date and time: Sat, Sep 03, 2022 - 12:41:02
library(stargazer)

stargazer(b1a.lw,
          b1b.lw,
          b2a.lw,
          b2b.lw,
          b3a.lw,
          b3b.lw,
          m1.lw,
          m2.lw,
          m3.lw,
          title = "Table 1: All models",
          covariate.labels = c("Inclusive Identity",
                               "Age",
                               "Education",
                               "Knowledge of the EU",
                               "Female",
                               "Management Position",
                               "Urban Environment",
                              "EU Immigration",
                              "Non EU Immigration",
                              "Intercept"),
          omit = c("country"), # excludes the country variable to be displayed in the table.
                               # The variable is only used to control for effects and does not have to be in the table.
          keep.stat = c("n", "rsq"),
          notes = "Country dummies not displayed in table, but included in regression: 2,4,6,7,8,9",
          out = "models.html")
% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu % Date and time: Sat, Sep 03, 2022 - 12:41:03

Graphs

b1a.lw # 1.2799 0.4253
## 
## Call:
## lm(formula = free_market_integration_score ~ inclusive, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive  
##      1.2799       0.4253
b1b.lw # 1.1741885 0.3924055
## 
## Call:
## lm(formula = free_market_integration_score ~ inclusive + country, 
##     data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive    countryBE    countryBG    countryCY    countryCZ  
##   1.1741885    0.3924055    0.1900415   -0.0591105    0.3614935   -0.3478740  
##   countryDE    countryDK    countryEE    countryES    countryFI    countryFR  
##   0.2756664   -0.3061030    0.4735795    0.2695252    0.2124429    0.1549873  
##   countryGB    countryGR    countryHR    countryHU    countryIE    countryIT  
##  -0.4008313    0.2757694    0.0008418    0.0813340    0.3303251   -0.0307192  
##   countryLT    countryLU    countryLV    countryMT    countryNL    countryPL  
##   0.3523734    0.2684351    0.3497893    0.2721016    0.2276105   -0.1846925  
##   countryPT    countryRO    countrySE    countrySI    countrySK  
##   0.3041094    0.0458101   -0.4414521    0.4156892    0.2414589
b2a.lw # 3.5823 0.8462
## 
## Call:
## lm(formula = furhter_political_integration_score ~ inclusive, 
##     data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive  
##      3.5823       0.8462
b2b.lw # 2.8661 0.8197
## 
## Call:
## lm(formula = furhter_political_integration_score ~ inclusive + 
##     country, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive    countryBE    countryBG    countryCY    countryCZ  
##      2.8661       0.8197       0.9238       0.8973       1.4104       0.2120  
##   countryDE    countryDK    countryEE    countryES    countryFI    countryFR  
##      1.0898       0.3706       0.8130       1.1808       0.3999       0.8977  
##   countryGB    countryGR    countryHR    countryHU    countryIE    countryIT  
##      0.1142       1.0674       0.8170       0.3697       0.8886       0.4194  
##   countryLT    countryLU    countryLV    countryMT    countryNL    countryPL  
##      1.2361       0.9160       0.7473       0.8183       0.9952       0.5551  
##   countryPT    countryRO    countrySE    countrySI    countrySK  
##      0.8501       0.5613       0.3008       1.0589       0.4230
b3a.lw # 2.4986 0.3499
## 
## Call:
## lm(formula = free_movement_score ~ inclusive, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive  
##      2.4986       0.3499
b3b.lw # 2.05910 0.34578
## 
## Call:
## lm(formula = free_movement_score ~ inclusive + country, data = my.df.listw)
## 
## Coefficients:
## (Intercept)    inclusive    countryBE    countryBG    countryCY    countryCZ  
##     2.05910      0.34578      0.33829      0.58006      0.62040      0.49773  
##   countryDE    countryDK    countryEE    countryES    countryFI    countryFR  
##     0.52594      0.38275      0.66954      0.56741      0.57467      0.44237  
##   countryGB    countryGR    countryHR    countryHU    countryIE    countryIT  
##     0.20410      0.50429      0.53594      0.31509      0.47631      0.05204  
##   countryLT    countryLU    countryLV    countryMT    countryNL    countryPL  
##     0.64859      0.54761      0.54135      0.53522      0.42370      0.35078  
##   countryPT    countryRO    countrySE    countrySI    countrySK  
##     0.57562      0.21704      0.48091      0.49137      0.44475
m1.lw # 0.760720 0.3204436
## 
## Call:
## lm(formula = free_market_integration_score ~ inclusive + age + 
##     education + knowledge_EU + female + management + urban_env + 
##     EU_immigration + Non_EU_immigration + country, data = my.df.listw)
## 
## Coefficients:
##        (Intercept)           inclusive                 age           education  
##          0.7860720           0.3204436          -0.0003070           0.0001788  
##       knowledge_EU              female          management           urban_env  
##          0.0269554          -0.0239004          -0.0173994           0.0104355  
##     EU_immigration  Non_EU_immigration           countryBE           countryBG  
##          0.1102858           0.0216987           0.2293725          -0.0696785  
##          countryCY           countryCZ           countryDE           countryDK  
##          0.3845033          -0.2741017           0.2820351          -0.3125707  
##          countryEE           countryES           countryFI           countryFR  
##          0.4820770           0.2186708           0.1827724           0.2036708  
##          countryGB           countryGR           countryHR           countryHU  
##         -0.3970487           0.2839797          -0.0076985           0.1127347  
##          countryIE           countryIT           countryLT           countryLU  
##          0.2852110           0.0220782           0.3501848           0.2501540  
##          countryLV           countryMT           countryNL           countryPL  
##          0.4291180           0.2737118           0.2514142          -0.1738668  
##          countryPT           countryRO           countrySE           countrySI  
##          0.2660433           0.0504636          -0.4233962           0.4020582  
##          countrySK  
##          0.2906875
m2.lw # 1.9289235 0.6625305
## 
## Call:
## lm(formula = furhter_political_integration_score ~ inclusive + 
##     age + education + knowledge_EU + female + management + urban_env + 
##     EU_immigration + Non_EU_immigration + country, data = my.df.listw)
## 
## Coefficients:
##        (Intercept)           inclusive                 age           education  
##          1.9289235           0.6625305           0.0008618          -0.0007864  
##       knowledge_EU              female          management           urban_env  
##          0.0556230           0.0529638           0.0482060          -0.0179294  
##     EU_immigration  Non_EU_immigration           countryBE           countryBG  
##          0.2561005           0.0482663           1.0054989           0.8848587  
##          countryCY           countryCZ           countryDE           countryDK  
##          1.4567105           0.3820092           1.0896743           0.3509701  
##          countryEE           countryES           countryFI           countryFR  
##          0.8195324           1.0658571           0.3148121           0.9907898  
##          countryGB           countryGR           countryHR           countryHU  
##          0.1138505           1.0908714           0.7873753           0.4307867  
##          countryIE           countryIT           countryLT           countryLU  
##          0.7807888           0.5230995           1.2134238           0.8755878  
##          countryLV           countryMT           countryNL           countryPL  
##          0.9011392           0.8221144           1.0152291           0.5732232  
##          countryPT           countryRO           countrySE           countrySI  
##          0.7593104           0.5754552           0.3283908           1.0301337  
##          countrySK  
##          0.5171326
m3.lw # 1.4249458 0.2292343
## 
## Call:
## lm(formula = free_movement_score ~ inclusive + age + education + 
##     knowledge_EU + female + management + urban_env + EU_immigration + 
##     Non_EU_immigration + country, data = my.df.listw)
## 
## Coefficients:
##        (Intercept)           inclusive                 age           education  
##          1.4249458           0.2292343          -0.0010522           0.0002844  
##       knowledge_EU              female          management           urban_env  
##          0.0337767           0.0098835           0.0374268          -0.0104015  
##     EU_immigration  Non_EU_immigration           countryBE           countryBG  
##          0.2503935          -0.0115543           0.4098042           0.5438453  
##          countryCY           countryCZ           countryDE           countryDK  
##          0.6524004           0.6072042           0.5279240           0.3560368  
##          countryEE           countryES           countryFI           countryFR  
##          0.6644791           0.4968654           0.5143730           0.5167497  
##          countryGB           countryGR           countryHR           countryHU  
##          0.2190506           0.5165861           0.5099501           0.3512261  
##          countryIE           countryIT           countryLT           countryLU  
##          0.4054057           0.1397117           0.6364943           0.5201978  
##          countryLV           countryMT           countryNL           countryPL  
##          0.6503121           0.5378338           0.4559306           0.3572875  
##          countryPT           countryRO           countrySE           countrySI  
##          0.5358963           0.2371276           0.5015406           0.4706039  
##          countrySK  
##          0.5140533
average_scores_on_integration_process <- c(1.2799, 
               1.2799 + 0.4253,  
               1.1741885, 
               1.1741885 + 0.3924055,
               0.760720,
               0.760720 + 0.320443,
               3.5823,
               3.5823 + 0.8462,
               2.8661,
               2.8661 + 0.8197,
               1.9289235,
               1.9289235 + 0.6625305,
               2.4986,
               2.4986 + 0.3499,
               2.05910,
               2.05910 + 0.34578,
               1.4249458,
               1.4249458 + 0.2292343)

Models <- c("b1a", 
            "b1a",
            "b1b",
            "b1b",
            "m1", 
            "m1", 
            "b2a", 
            "b2a",
            "b2b",
            "b2b",
            "m2", 
            "m2",
            "b3a", 
            "b3a",
            "b3b",
            "b3b",
            "m3", 
            "m3")
inclusive_exclusive <- c("exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive")

graph.df <- tibble::tibble(inclusive_exclusive, Models, average_scores_on_integration_process)

plot <- ggplot(data = graph.df, aes(x = Models, y = average_scores_on_integration_process, fill = inclusive_exclusive)) +
  geom_bar(stat="identity", position = "dodge") +
  geom_text(aes(label=average_scores_on_integration_process), color="black", size = 3.5, nudge_x = c(-0.22, 0.22)) +
  labs(x = "Bi- and Multivariate Models", 
       y = "Average attitude score",
       title = "Graph 1: All models",
       caption = "Plotted using Eurobarometer 92.3 data") +
  guides(fill=guide_legend(title="Identity")) +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))


plot

ggsave(filename = "all_plots.pdf", device = "pdf", dpi = "retina")

market integration plot

average_score_market_integration <- c(1.2799, 
               1.2799 + 0.4253,  
               1.1741885, 
               1.1741885 + 0.3924055,
               0.760720,
               0.760720 + 0.320443)

Models_market_integration <- c("b1a", "b1a",
                               "b1b", "b1b",
                               "m1", "m1")
inclusive_exclusive2 <- c("exclusive", "inclusive",
                         "exclusive", "inclusive",
                         "exclusive", "inclusive")

graph_market_integration.df <- tibble::tibble(inclusive_exclusive2, Models_market_integration, average_score_market_integration)

plot_market_integration <- ggplot(data = graph_market_integration.df, aes(x = Models_market_integration, y = average_score_market_integration, fill = inclusive_exclusive2)) +
  geom_bar(stat="identity", position = "dodge") +
  geom_text(aes(label=average_score_market_integration),color="black", size = 3.5, nudge_x = c(-0.22, 0.22)) +
  labs(x = "Graph 2: Market Integration Attitude Models",
       y = "Average Attitude Score",
       title = "Attitudes towards Market Integration",
       caption = "Plotted using Eurobarometer 92.3 data") +
  guides(fill=guide_legend(title="Identity")) +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5)) 

plot_market_integration

ggsave(filename = "market_integration_plot.pdf", device = "pdf", dpi = "retina")

further political integration

average_score_further_political_integration <- c(3.5823,
               3.5823 + 0.8462,
               2.8661,
               2.8661 + 0.8197,
               1.9289235,
               1.9289235 + 0.6625305)

Models_further_political_integration <- c("b2a", "b2a",
                                          "b2b", "b2b",
                                          "m2", "m2")
inclusive_exclusive2 <- c("exclusive", "inclusive",
                          "exclusive", "inclusive",
                         "exclusive", "inclusive")

graph_further_political_integration.df <- tibble::tibble(inclusive_exclusive2, Models_further_political_integration, average_score_further_political_integration)

plot_further_political_integration <- ggplot(data = graph_further_political_integration.df, aes(x = Models_further_political_integration, y = average_score_further_political_integration, fill = inclusive_exclusive2)) +
  geom_bar(stat="identity", position = "dodge") +
  geom_text(aes(label=average_score_further_political_integration),color="black", size = 3.5, nudge_x = c(-0.22, 0.22)) +
  labs(x = "Graph 3: Further Politcal Integration Attitude Models",
       y = "Average Attitude Score",
       title = "Attitudes towards Further Political Integration",
       caption = "Plotted using Eurobarometer 92.3 data") +
  guides(fill=guide_legend(title="Identity")) +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5)) 

plot_further_political_integration

ggsave(filename = "furhter_integration_plot.pdf", device = "pdf", dpi = "retina")

freedom of movement plot

average_score_free_movement <- c( 2.4986,
               2.4986 + 0.3499,
               2.05910,
               2.05910 + 0.34578,
               1.4249458,
               1.4249458 + 0.2292343)

Models_free_movement <- c("b3a", "b3a",
                          "b3b", "b3b",
                          "m3", "m3")
inclusive_exclusive2 <- c("exclusive", "inclusive",
                          "exclusive", "inclusive",
                         "exclusive", "inclusive")

graph_free_movement.df <- tibble::tibble(inclusive_exclusive2, Models_free_movement, average_score_free_movement)

plot_freedom_of_movement <- ggplot(data = graph_free_movement.df, aes(x = Models_free_movement, y = average_score_free_movement, fill = inclusive_exclusive2)) +
  geom_bar(stat="identity", position = "dodge") +
  geom_text(aes(label=average_score_free_movement),color="black", size = 3.5, nudge_x = c(-0.22, 0.22)) +
  labs(x = "Graph 4: Freedom of Movement Attitude Models",
       y = "Average Attitude Score",
       title = "Attitudes towards Freedom of Movement within the EU",
       caption = "Plotted using Eurobarometer 92.3 data") +
  guides(fill=guide_legend(title="Identity")) +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5)) 

plot_freedom_of_movement

ggsave(filename = "freedom_of_movement_plot.pdf", device = "pdf", dpi = "retina")
max_length <- max(length(supranationalist.vc), 
                          length(cosmopolit.vc),
                          length(glocalist.vc),
                          length(nationalist.vc),
                          length(localist.vc),
                          length(apolide.vc))

table.df <- data.frame(supranationalist = c(supranationalist.vc, rep(NA, max_length - length(supranationalist.vc))),
                       cosmopolit = c(cosmopolit.vc, rep(NA, max_length - length(cosmopolit.vc))),
                       glocalist = c(glocalist.vc, rep(NA, max_length - length(glocalist.vc))),
                       nationalist = c(nationalist.vc, rep(NA, max_length - length(nationalist.vc))),
                       localist = c(localist.vc, rep(NA, max_length - length(localist.vc))),
                       apolide = c(apolide.vc, rep(NA, max_length - length(apolide.vc))))

typologytable.html <- table.df %>% addHtmlTableStyle(col.rgroup = c("none", "#F7F7F7")) %>% 
  htmlTable(
          caption = "Table 4",
          tfoot = "Typology after Kuhn and Nicoli 2020",
          ctable = "double")
typologytable.html
Table 4
supranationalist cosmopolit glocalist nationalist localist apolide
1 2 33 202 20 200 0
2 3 222 203 21 201 1
3 12 232 212 30 210 10
4 13 233 213 31 211 11
5 22 322 302 120 301 100
6 23 323 303 121 310 101
7 32 332 312 130 311 110
8 102 333 313 131 320 111
9 103 220 321
10 112 221
11 113 230
12 122 231
13 123 330
14 132 331
15 133
16 223
Typology after Kuhn and Nicoli 2020
htmltools::save_html(typologytable.html, file = "typology.html")
# some percentage calculations
0.32 / 0.786 * 100
## [1] 40.71247
0.32 / 2 * 100
## [1] 16
0.663 / 1.929 * 100
## [1] 34.37014
0.663 / 5 * 100
## [1] 13.26
0.229 / 1.425 * 100
## [1] 16.07018
0.229 / 3 * 100
## [1] 7.633333