Warning: package 'tidyverse' was built under R version 4.4.3
Warning: package 'ggplot2' was built under R version 4.4.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ 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
library(sjstats)
Warning: package 'sjstats' was built under R version 4.4.3
library(lme4)
Loading required package: Matrix
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
library(arm)
Loading required package: MASS
Attaching package: 'MASS'
The following object is masked from 'package:dplyr':
select
arm (Version 1.14-4, built: 2024-4-1)
Working directory is C:/Users/Admin/Downloads
library(haven)library(stargazer)
Please cite as:
Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(dplyr)
Hypothesis:
The higher the financial satisfaction, the higher the life satisfaction. The higher the health satisfaction, the higher the life satisfaction.
I expect developing countries, such as Iraq, Kenya, Libya, Mexico, and Malaysia, will have lower overall life satisfaction than developed countries like Germany, Japan, Russia, and the United States. However, after increasing financial and health satisfaction, overall life satisfaction will increase more among developing countries.
Control Variable:
I choose sex and immigration status as they are demographic variables.
###Varying Intercept Model - For Interclass Correlation mlm <-lmer(satisfaction_with_life ~1+ (1|country_code), data = wvs)summary(mlm)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ 1 + (1 | country_code)
Data: wvs
REML criterion at convergence: 59111
Scaled residuals:
Min 1Q Median 3Q Max
-3.5279 -0.6041 0.1189 0.7184 2.7337
Random effects:
Groups Name Variance Std.Dev.
country_code (Intercept) 1.31 1.144
Residual 4.09 2.022
Number of obs: 13907, groups: country_code, 9
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.8514 0.3819 17.94
icc<-1.266/(1.266+4.552)print(icc)
[1] 0.2176006
Interpretation
To start, we often fit an unconditional means model that provides us information about how much of the total variance in the outcome variable is within-person variance and how much is between-person variance.
This is an unconditional means model that provides information about how much of the total variance in the outcome variable is in people’s satisfaction with life. 21.7% is between cluster variation, while 78.3% is within cluster variation. The ICC is small, which means less impact on the estimated standard errors, and the Type I error rate is increased.
Varying Intercept
mlm_1 <-lmer(satisfaction_with_life ~ satisfaction_with_personal_finances+ biological_sex+ immigrant_or_not+(1|country_code), data = wvs)summary(mlm_1)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +
biological_sex + immigrant_or_not + (1 | country_code)
Data: wvs
REML criterion at convergence: 53123.3
Scaled residuals:
Min 1Q Median 3Q Max
-5.1924 -0.4929 0.1042 0.5087 3.6152
Random effects:
Groups Name Variance Std.Dev.
country_code (Intercept) 0.5759 0.7589
Residual 2.8055 1.6750
Number of obs: 13712, groups: country_code, 9
Fixed effects:
Estimate Std. Error t value
(Intercept) 3.871926 0.270753 14.301
satisfaction_with_personal_finances 0.489749 0.006235 78.545
biological_sex 0.045913 0.028707 1.599
immigrant_or_not -0.009008 0.073133 -0.123
Correlation of Fixed Effects:
(Intr) sts___ blgcl_
stsfctn_w__ -0.142
biologcl_sx -0.162 0.012
immgrnt_r_n -0.281 0.009 0.002
modelsummary::msummary(list("VI Only"= mlm_1,"VIVS"= mlm_2), coef_rename =c("satisfaction_with_personal_finances"="Satisfaction with personal finances", "biological_sex"="Biological sex","immigrant_or_not"="Immigrant or not","SD (Intercept country_code)"="Country RE Intercept SD","SD (satisfaction_with_personal_finances country_code)"="Country RE Satisfaction with personal finances SD", "Cor (Intercept~satisfaction_with_personal_finances country_code)"="Correlation RE Satisfaction with personal finances","SD (Observations)"="Observations RE SD"))
VI Only
VIVS
(Intercept)
3.872
3.763
(0.271)
(0.582)
Satisfaction with personal finances
0.490
0.529
(0.006)
(0.067)
Biological sex
0.046
0.046
(0.029)
(0.028)
Immigrant or not
-0.009
-0.024
(0.073)
(0.072)
Country RE Intercept SD
0.759
1.723
Country RE Satisfaction with personal finances SD
0.199
Correlation RE Satisfaction with personal finances
-0.978
Observations RE SD
1.675
1.639
Num.Obs.
13712
13712
R2 Marg.
0.294
0.333
R2 Cond.
0.414
0.455
AIC
53135.3
52578.0
BIC
53180.4
52638.2
ICC
0.2
0.2
RMSE
1.67
1.64
Interpretation
The Varying Intercept Model shows a “fixed effects” model where the relationship between people’s satisfaction with life and personal finances is assumed to be the same at different country levels. According to the results, when one level of people’s satisfaction with personal finance, people’s satisfaction with life will increase by 0.49. It also means that this model only measures one coefficient. However, the intercept, which predicts people’s satisfaction with life under the circumstance that people’s satisfaction with personal finance is zero, varies. When financial satisfaction equals zero, Mexico has the highest level of life satisfaction, which is 4.740, and Iraq has the lowest life satisfaction, which is 2.231. The average for the coefficient is 0.49, and the average for the intercept is 3.872. The average error is 0.006 for the coefficient and 0.271 for the intercept.
Varying Intercept, Varying Slopes Model allows Independent variables to influence dependent variables at different rates based on the different group levels that individual is in. In this case, people’s satisfaction with personal finance will influence their satisfaction with life based on the country they are in. Accordingly, when increasing one level of people’s satisfaction about their finances satisfaction, people from Iraq will increase the highest about their life satisfaction, which is 0.999, while Mexico will increase lower about their life satisfaction, which is 0.325. When financial satisfaction equals zero, Iraq people’s life satisfaction is lowest, which is -0.033, and Mexico people’s life satisfaction is highest, which is 5.876. The average for the coefficient is 0.529 and for the intercept is 3.763. The average error for the coefficient is 0.067 and for the intercept is 0.582.
Regarding the control variable sex and immigration status, the coefficient is solid in two models. About sex, in the Varying Intercept Model, the coefficient is solid at 0.046, which is the same for the Varying Intercept-Varying Slopes Model. Regarding immigration status, the coefficient for the Varying Intercept Model is -0.009, while for the Varying Intercept-Varying Slopes Model is -0.024.
Varying Slopes
mlm_slop <-lmer(satisfaction_with_life ~ satisfaction_with_personal_finances+biological_sex+immigrant_or_not +(0+satisfaction_with_personal_finances|country_code), data = wvs)summary(mlm_slop)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +
biological_sex + immigrant_or_not + (0 + satisfaction_with_personal_finances |
country_code)
Data: wvs
REML criterion at convergence: 53987.4
Scaled residuals:
Min 1Q Median 3Q Max
-5.1393 -0.5521 0.0264 0.5620 3.3327
Random effects:
Groups Name Variance Std.Dev.
country_code satisfaction_with_personal_finances 0.01034 0.1017
Residual 2.98870 1.7288
Number of obs: 13712, groups: country_code, 9
Fixed effects:
Estimate Std. Error t value
(Intercept) 3.70890 0.09918 37.395
satisfaction_with_personal_finances 0.49721 0.03451 14.407
biological_sex 0.04241 0.02963 1.431
immigrant_or_not 0.06135 0.07508 0.817
Correlation of Fixed Effects:
(Intr) sts___ blgcl_
stsfctn_w__ -0.075
biologcl_sx -0.456 0.002
immgrnt_r_n -0.789 0.003 0.001
(Intercept) satisfaction_with_personal_finances biological_sex
DEU 3.709 0.537 0.042
IRQ 3.709 0.269 0.042
JPN 3.709 0.496 0.042
KEN 3.709 0.426 0.042
LBY 3.709 0.603 0.042
MEX 3.709 0.597 0.042
MYS 3.709 0.512 0.042
RUS 3.709 0.492 0.042
USA 3.709 0.543 0.042
immigrant_or_not
DEU 0.061
IRQ 0.061
JPN 0.061
KEN 0.061
LBY 0.061
MEX 0.061
MYS 0.061
RUS 0.061
USA 0.061
Interpretation
When the intercept is the same, or the life satisfaction baseline for each country is the same, increasing one level of financial satisfaction, Iraq has the lowest increase in life satisfaction, and Libya has the highest increase in life satisfaction.
Part 2
The next two models show adding the index GDP to see if it influences satisfaction with life. This variable will not vary at the individual level and may not be included in the regular regression mode.
modelsummary::msummary(list("VI + GDP"= mlm_3,"VIVS+GDP"= mlm_4), coef_rename =c("satisfaction_with_personal_finances"="Satisfaction with personal finances", "biological_sex"="Biological sex","immigrant_or_not"="Immigrant or not","scale(gdp_per_capita)"="GDP per Capita","SD (Intercept country_code)"="Country RE Intercept SD","SD (satisfaction_with_personal_finances country_code)"="Country RE Satisfaction with personal finances SD", "Cor (Intercept~satisfaction_with_personal_finances country_code)"="Correlation RE Satisfaction with personal finances","SD (Observations)"="Observations RE SD"))
VI + GDP
VIVS+GDP
(Intercept)
3.915
3.772
(0.279)
(0.581)
Satisfaction with personal finances
0.490
0.529
(0.006)
(0.067)
Biological sex
0.046
0.046
(0.029)
(0.028)
Immigrant or not
-0.010
-0.025
(0.073)
(0.072)
GDP per Capita
0.238
0.050
(0.272)
(0.137)
Country RE Intercept SD
0.771
1.718
Country RE Satisfaction with personal finances SD
0.199
Correlation RE Satisfaction with personal finances
-0.975
Observations RE SD
1.675
1.639
Num.Obs.
13712
13712
R2 Marg.
0.313
0.335
R2 Cond.
0.433
0.458
AIC
53137.3
52582.0
BIC
53190.0
52649.8
ICC
0.2
0.2
RMSE
1.67
1.64
Interpretation
After adding the GDP index, for the Varying Intercept Model, Libya becomes the highest life satisfaction country when the people’s financial satisfaction is zero, and Iraq is still the country that has the lowest life satisfaction. For the Varying Intercept-Varying Slopes Model, when one level of financial satisfaction increases, Iraq is still the country that increases the most life satisfaction, which is 0.999, and Mexico is the country that increases least, which is 0.325.
Varying Slopes
mlm_slop_gdp <-lmer(satisfaction_with_life ~ satisfaction_with_personal_finances+biological_sex+immigrant_or_not+scale(gdp_per_capita)++(0+satisfaction_with_personal_finances|country_code), data = wvs)summary(mlm_slop_gdp)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +
biological_sex + immigrant_or_not + scale(gdp_per_capita) +
+(0 + satisfaction_with_personal_finances | country_code)
Data: wvs
REML criterion at convergence: 53903.2
Scaled residuals:
Min 1Q Median 3Q Max
-5.2066 -0.5360 0.0157 0.5721 3.5739
Random effects:
Groups Name Variance Std.Dev.
country_code satisfaction_with_personal_finances 0.00814 0.09022
Residual 2.97000 1.72337
Number of obs: 13712, groups: country_code, 9
Fixed effects:
Estimate Std. Error t value
(Intercept) 3.822679 0.099610 38.376
satisfaction_with_personal_finances 0.502217 0.030773 16.320
biological_sex 0.038116 0.029543 1.290
immigrant_or_not 0.004776 0.075085 0.064
scale(gdp_per_capita) 0.362682 0.038359 9.455
Correlation of Fixed Effects:
(Intr) sts___ blgcl_ immg__
stsfctn_w__ -0.082
biologcl_sx -0.455 0.002
immgrnt_r_n -0.790 0.002 0.002
scl(gdp_p_) 0.122 0.017 -0.015 -0.080
(Intercept) satisfaction_with_personal_finances biological_sex
DEU 3.823 0.482 0.038
IRQ 3.823 0.337 0.038
JPN 3.823 0.466 0.038
KEN 3.823 0.500 0.038
LBY 3.823 0.639 0.038
MEX 3.823 0.622 0.038
MYS 3.823 0.517 0.038
RUS 3.823 0.498 0.038
USA 3.823 0.459 0.038
immigrant_or_not scale(gdp_per_capita)
DEU 0.005 0.363
IRQ 0.005 0.363
JPN 0.005 0.363
KEN 0.005 0.363
LBY 0.005 0.363
MEX 0.005 0.363
MYS 0.005 0.363
RUS 0.005 0.363
USA 0.005 0.363
Interpretation
After adding the GDP index, the Varying Slopes outcome is similar to the one that not adding the GDP index. The finding is increasing one level of financial satisfaction, Iraq has the lowest increase in life satisfaction, and Libya has the highest increase in life satisfaction.
Different Independent variables
This part measures another independent variable, health satisfaction.
(Intercept) personal_health_status biological_sex immigrant_or_not
DEU 4.880 0.679 0.056 -0.115
IRQ 3.458 0.394 0.056 -0.115
JPN 3.509 0.891 0.056 -0.115
KEN 4.297 0.513 0.056 -0.115
LBY 5.050 0.736 0.056 -0.115
MEX 6.234 0.558 0.056 -0.115
MYS 3.397 0.971 0.056 -0.115
RUS 3.775 0.823 0.056 -0.115
USA 2.982 0.967 0.056 -0.115
scale(gdp_per_capita)
DEU 0.34
IRQ 0.34
JPN 0.34
KEN 0.34
LBY 0.34
MEX 0.34
MYS 0.34
RUS 0.34
USA 0.34
modelsummary::msummary(list( "VI"=mlm_5,"VIVS"= mlm_6,"VI + GDP"= mlm_7,"VIVS+GDP"= mlm_8), coef_rename =c("personal_health_status"="Personal health status", "biological_sex"="Biological sex","immigrant_or_not"="Immigrant or not","scale(gdp_per_capita)"="GDP per Capita", "SD (Intercept country_code)"="Country RE Intercept SD","SD (personal_health_status country_code)"="Country RE Satisfaction with personal health SD", "Cor (Intercept~personal_health_status country_code)"="Correlation RE Satisfaction with personal health","SD (Observations)"="Observations RE SD"))
VI
VIVS
VI + GDP
VIVS+GDP
(Intercept)
4.079
4.116
4.173
4.176
(0.383)
(0.357)
(0.365)
(0.399)
Personal health status
0.730
0.726
0.731
0.726
(0.019)
(0.074)
(0.019)
(0.074)
Biological sex
0.066
0.056
0.066
0.056
(0.033)
(0.033)
(0.033)
(0.033)
Immigrant or not
-0.114
-0.114
-0.115
-0.115
(0.084)
(0.084)
(0.084)
(0.084)
GDP per Capita
0.534
0.340
(0.357)
(0.353)
Country RE Intercept SD
1.086
0.999
1.010
1.120
Country RE Satisfaction with personal health SD
0.214
0.214
Correlation RE Satisfaction with personal health
-0.283
-0.459
Observations RE SD
1.926
1.918
1.926
1.918
Num.Obs.
13803
13803
13803
13803
R2 Marg.
0.077
0.076
0.121
0.093
R2 Cond.
0.300
0.309
0.311
0.304
AIC
57339.4
57246.5
57339.5
57248.2
BIC
57384.6
57306.8
57392.2
57316.0
ICC
0.2
0.3
0.2
0.2
RMSE
1.92
1.92
1.92
1.92
Interpretation
Before adding the GDP indicator, in the Varying Intercept Model, the result is similar to financial satisfaction, which is that Iraq has the lowest life satisfaction and Mexico has the highest satisfaction. Things are interesting in the Varying Intercept, Varying Slopes Model. Americans have the highest increase in life satisfaction when increasing one level of health satisfaction, and Iraq is the country that has the lowest increase in life satisfaction when increasing one level of health satisfaction. When adding the GDP indicator, the result is the same as in the Varying Intercept Model before adding this indicator. In the Varying Intercept, Varying Slopes Model, Malaysia has the highest increase in life satisfaction when increasing one level of health satisfaction.
Conclusion
It is interesting to see that some developing countries, like Mexico, have high levels of life satisfaction and will not be impacted much when increase financial and health satisfaction. Accordingly, my hypothesis of use developing and developed countries to classify the level of life satisfaction. Besides, health satisfaction is a crucial indicator for the United States. After increasing it, the overall life satisfaction will be increased.