Subsetting to country

 switzerland_data <- ess %>%
  filter(cntry == "CH")
df <- switzerland_data
df$year <- NA
replacements <- c(2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016, 2018, 2020)
for (i in 1:10) {
  df$year[df$essround == i] <- replacements[i]
}

Creating/cleaning main outcome variable.

Create our tables

## Warning: The histogram argument is only supported for (a) output types "default",
##   "html", "kableExtra", or "gt"; (b) writing to file paths with extensions
##   ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents
##   compiled to PDF (via kableExtra)  or HTML (via kableExtra or gt). Use
##   `histogram=FALSE` to silence this warning.

Unique (#)

Missing (%)

Mean

SD

Min

Median

Max

happy

11

0

69.0

1.4

67.0

69.0

76.0

health

5

0

5.1

0.8

2.0

5.0

6.0

stflife

11

0

8.0

1.7

0.0

8.0

10.0

trstprl

11

0

5.7

2.0

0.0

6.0

10.0

edulvla

5

0

3.3

1.2

1.0

3.0

5.0

## Warning: The histogram argument is only supported for (a) output types "default",
##   "html", "kableExtra", or "gt"; (b) writing to file paths with extensions
##   ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents
##   compiled to PDF (via kableExtra)  or HTML (via kableExtra or gt). Use
##   `histogram=FALSE` to silence this warning.
Table 1. Descriptive statistics of main variables

Unique (#)

Missing (%)

Mean

SD

Min

Median

Max

How happy are you

11

0

69.0

1.4

67.0

69.0

76.0

Subjective general health

5

0

5.1

0.8

2.0

5.0

6.0

How satisfied with life as a whole

11

0

8.0

1.7

0.0

8.0

10.0

Trust in country's parliament

11

0

5.7

2.0

0.0

6.0

10.0

Highest level of education

5

0

3.3

1.2

1.0

3.0

5.0

In all three models, the education level showed a coefficient of -7.828, -7.297, and -7.747 which are quite similar and all showed a negative relationship with the age of death. This means that education could not et people live longer in Switzerland. For stflife, the negative coefficient -4.543 means a bad relationship or no relationship between satisfaction with life as a whole and the age of death. In the health coefficient, a positive number of 13.797 showed that there is a high relationship between health and the exact age of death. The more healthy a person is, the longer he/she will live. It could be said that of all the factors related to the of death, health must be one of the most important. In the factor of happiness, it showed a coefficient of 6.151 and it means people feel happy will live longer.

Finding

df <- df %>%
  mutate(
    edulvla = edulvla %>%
      na_if(55) %>%
      na_if(88),
    edulvlb = edulvlb %>%
      na_if(5555) %>%
      na_if(7777) %>%
      na_if(8888), 

educ.ba = case_when(
    essround < 5 & edulvla == 5 ~ 1,
    essround >= 5 & edulvlb > 600 ~ 1,
    TRUE ~ 0))
table(df$edulvla)
## 
##    1    2    3    4    5 
##  292 1324 3616  134 1967
df <- df %>% filter(!is.na(educ.ba))
d <- df %>%
  # Convert factors/characters to numeric
  mutate(
    educ_ba_num = as.numeric(educ.ba),
  )
table2 <- datasummary_skim(d  %>% dplyr::select(educ_ba_num, life_expectancy), output = "flextable")
## Warning: The histogram argument is only supported for (a) output types "default",
##   "html", "kableExtra", or "gt"; (b) writing to file paths with extensions
##   ".html", ".jpg", or ".png"; and (c) Rmarkdown, knitr or Quarto documents
##   compiled to PDF (via kableExtra)  or HTML (via kableExtra or gt). Use
##   `histogram=FALSE` to silence this warning.
table2

Unique (#)

Missing (%)

Mean

SD

Min

Median

Max

educ_ba_num

2

0

0.3

0.4

0.0

0.0

1.0

life_expectancy

34

0

30.9

10.7

0.0

30.6

100.0

Hypothesis testing with infer

## Message: The independence null hypothesis does not inform calculation of the
## observed statistic (a correlation) and will be ignored.
## Response: life_expectancy (numeric)
## Explanatory: educ.ba (numeric)
## Null Hypothesis: independence
## # A tibble: 1,000 × 2
##    replicate     stat
##        <int>    <dbl>
##  1         1 -0.00380
##  2         2 -0.0119 
##  3         3  0.00449
##  4         4  0.0217 
##  5         5  0.00983
##  6         6  0.0104 
##  7         7  0.00720
##  8         8 -0.00468
##  9         9  0.00744
## 10        10  0.0327 
## # ℹ 990 more rows
## # A tibble: 1 × 1
##   p_value
##     <dbl>
## 1       1

We notice that it is a normal distribution which means the data in the graph is useful and could prove that H0 is wrong. They indeed have a relationship.

Do some modelling
 (1)   (2)   (3)
educ.ba −7.8 (0.3)*** −7.3 (0.2)*** −7.5 (0.2)***
stflife −4.5 (0.0)***
health 13.8 (3.9)***
happy 6.2 (0.3)***
health × happy −0.2 (0.1)**
Num.Obs. 7333 7333 7333
R2 0.102 0.611 0.600
R2 Adj. 0.102 0.611 0.600
AIC 55435.8 49299.2 49509.4
BIC 55456.5 49326.8 49550.8
Log.Lik. −27714.917 −24645.575 −24748.715
RMSE 10.16 6.68 6.76

Health *happy in model 3 provided information about the people who think they are healthy and happy, and their age of death was lower than the prediction in a coefficient of 0.177(-0.177) The number of Observations is the same across all models, ensuring a fair comparison. 0.600 in model 3 (bigger than 0.102 in model 1) means it will lead to a mix of the factors that will make it better. R^2 did not it change after the adjustment, so it will not be more convincible after the change. AIC and BIC in model 3 are smaller so they fit well. log. Lik has a smaller negative part, so it fits well.

Visual

## 
##  health*happy effect
##       happy
## health       67       70       72       74       77
##      2 14.32593 31.71640 43.31005 54.90370 72.29418
##      3 16.26902 33.12872 44.36852 55.60832 72.46801
##      4 18.21212 34.54104 45.42698 56.31293 72.64185
##      5 20.15521 35.95335 46.48545 57.01754 72.81568
##      6 22.09831 37.36567 47.54391 57.72216 72.98952
Model 1  Model 2  Model 3
(Intercept) 32.719 69.172 −399.651
(0.136) (0.383) (19.869)
educ.ba −7.828 −7.297 −7.471
(0.272) (0.179) (0.182)
stflife −4.543
(0.046)
health 13.797
(3.926)
happy 6.151
(0.286)
health × happy −0.177
(0.057)
Num.Obs. 7333 7333 7333
R2 0.102 0.611 0.600
R2 Adj. 0.102 0.611 0.600
AIC 55435.8 49299.2 49509.4
BIC 55456.5 49326.8 49550.8
Log.Lik. −27714.917 −24645.575 −24748.715
RMSE 10.16 6.68 6.76
Model 1  Model 2  Model 3
(Intercept) 32.719 69.172 −399.651
(0.157) (0.555) (28.812)
educ.ba −7.828 −7.297 −7.471
(0.273) (0.181) (0.183)
stflife −4.543
(0.067)
health 13.797
(5.932)
happy 6.151
(0.416)
health × happy −0.177
(0.086)
Num.Obs. 7333 7333 7333
R2 0.102 0.611 0.600
R2 Adj. 0.102 0.611 0.600
AIC 55435.8 49299.2 49509.4
BIC 55456.5 49326.8 49550.8
Log.Lik. −27714.917 −24645.575 −24748.715
RMSE 10.16 6.68 6.76
Std.Errors HC3 HC3 HC3
Table 2. Regression models predicting authoritarian attitudes (0 to 100)
Model 1  Model 2  Model 3
(Intercept) 32.7 (0.1)*** 69.2 (0.4)*** −399.7 (19.9)***
educ.ba −7.8 (0.3)*** −7.3 (0.2)*** −7.5 (0.2)***
stflife −4.5 (0.0)***
health 13.8 (3.9)***
happy 6.2 (0.3)***
health × happy −0.2 (0.1)**
Num.Obs. 7333 7333 7333
R2 0.102 0.611 0.600
R2 Adj. 0.102 0.611 0.600
AIC 55435.8 49299.2 49509.4
BIC 55456.5 49326.8 49550.8
Log.Lik. −27714.917 −24645.575 −24748.715
RMSE 10.16 6.68 6.76