Setting Up

# List of packages
packages <- c("tidyverse", "infer", "fst", "modelsummary", "effects") # add any you need here

# Install packages if they aren't installed already
new_packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages)

# Load the packages
lapply(packages, library, character.only = TRUE)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Warning: package 'infer' was built under R version 4.2.3
## Warning: package 'fst' was built under R version 4.2.3
## Warning: package 'modelsummary' was built under R version 4.2.3
## Warning in !is.null(rmarkdown::metadata$output) && rmarkdown::metadata$output
## %in% : 'length(x) = 2 > 1' in coercion to 'logical(1)'
## Warning: package 'effects' was built under R version 4.2.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.2.3
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
## [[1]]
##  [1] "lubridate" "forcats"   "stringr"   "dplyr"     "purrr"     "readr"    
##  [7] "tidyr"     "tibble"    "ggplot2"   "tidyverse" "stats"     "graphics" 
## [13] "grDevices" "utils"     "datasets"  "methods"   "base"     
## 
## [[2]]
##  [1] "infer"     "lubridate" "forcats"   "stringr"   "dplyr"     "purrr"    
##  [7] "readr"     "tidyr"     "tibble"    "ggplot2"   "tidyverse" "stats"    
## [13] "graphics"  "grDevices" "utils"     "datasets"  "methods"   "base"     
## 
## [[3]]
##  [1] "fst"       "infer"     "lubridate" "forcats"   "stringr"   "dplyr"    
##  [7] "purrr"     "readr"     "tidyr"     "tibble"    "ggplot2"   "tidyverse"
## [13] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
## [19] "base"     
## 
## [[4]]
##  [1] "modelsummary" "fst"          "infer"        "lubridate"    "forcats"     
##  [6] "stringr"      "dplyr"        "purrr"        "readr"        "tidyr"       
## [11] "tibble"       "ggplot2"      "tidyverse"    "stats"        "graphics"    
## [16] "grDevices"    "utils"        "datasets"     "methods"      "base"        
## 
## [[5]]
##  [1] "effects"      "carData"      "modelsummary" "fst"          "infer"       
##  [6] "lubridate"    "forcats"      "stringr"      "dplyr"        "purrr"       
## [11] "readr"        "tidyr"        "tibble"       "ggplot2"      "tidyverse"   
## [16] "stats"        "graphics"     "grDevices"    "utils"        "datasets"    
## [21] "methods"      "base"
ess <- read_fst("All-ESS-Data.fst")
## Warning: package 'fstcore' was built under R version 4.2.3

Selecting Variables in Dataset

# Filter for Israel 
israel_data <- ess %>%
  filter(cntry == "IL")

israel_dataset <- ess[ess$cntry == "IL", ]

# Cleaning Israel's dataset
israel_clean <- israel_dataset %>%
  select(eduail1, hinctnta, happy, essround) %>%
  mutate(
    happy = ifelse(happy %in% c(77, 88, 99), NA, happy),
    eduail1 = ifelse(eduail1 %in% c(4444, 5555, 7777, 8888, 9999), NA, eduail1),
    hinctnta = ifelse(hinctnta %in% c(77, 88, 99), NA, hinctnta),
    year = case_when(essround == 1 ~ 2002,
                         essround == 2 ~ 2004,
                         essround == 3 ~ 2006,
                         essround == 4 ~ 2008,
                         essround == 5 ~ 2010,
                         essround == 6 ~ 2012,
                         essround == 7 ~ 2014,
                         essround == 8 ~ 2016,
                         essround == 9 ~ 2018,
                         essround == 10 ~ 2020) 
  ) %>%
  filter(!is.na(happy) & !is.na(eduail1) & !is.na(hinctnta))

Modelling of Education Level and Happiness Levels in Israel

model1_IL <- lm(happy ~ eduail1, data = israel_clean)
model2_IL <- lm(happy ~ eduail1 + hinctnta, data = israel_clean)
model3_IL <- lm(happy ~ eduail1 + hinctnta + eduail1*hinctnta, data = israel_clean)
modelsummary(
  list(model1_IL, model2_IL, model3_IL))
 (1)   (2)   (3)
(Intercept) 7.150 6.735 6.473
(0.068) (0.079) (0.133)
eduail1 0.058 0.020 0.057
(0.008) (0.008) (0.017)
hinctnta 0.141 0.199
(0.014) (0.028)
eduail1 × hinctnta −0.007
(0.003)
Num.Obs. 3301 3301 3301
R2 0.018 0.045 0.047
R2 Adj. 0.017 0.045 0.046
AIC 13694.3 13601.4 13597.4
BIC 13712.6 13625.8 13627.9
Log.Lik. −6844.149 −6796.686 −6793.718
RMSE 1.92 1.90 1.89
# Adding Stars
modelsummary(
  list(model1_IL, model2_IL, model3_IL),
  fmt = 1,
  estimate  = c( "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}",
                "{estimate} ({std.error}){stars}"),
  statistic = NULL,
  coef_omit = "Intercept")
 (1)   (2)   (3)
eduail1 0.1 (0.0)*** 0.0 (0.0)* 0.1 (0.0)**
hinctnta 0.1 (0.0)*** 0.2 (0.0)***
eduail1 × hinctnta 0.0 (0.0)*
Num.Obs. 3301 3301 3301
R2 0.018 0.045 0.047
R2 Adj. 0.017 0.045 0.046
AIC 13694.3 13601.4 13597.4
BIC 13712.6 13625.8 13627.9
Log.Lik. −6844.149 −6796.686 −6793.718
RMSE 1.92 1.90 1.89