TAS Descriptive statistics

We will be going through

Step 1: Loading Packages

library(tidyverse)
library(readxl)
library(ggplot2)
library (reshape2)
library(writexl)
library (lmerTest)
library(lme4)
library(dplyr)
library(ggpubr)
library(rstatix)
library(effectsize)
library(multcomp)
library(scales)

Step 2: Import the data

TAS_data_long_format_age <- read_excel("C:/ZZ_SherMay/BHP/TAS_data_long_format_age.xlsx") %>% unite("TAS_ID", c("1968 Interview Number", "Person Number")) %>% mutate(year_new = case_when(year == 2005 ~ -1, year == 2009 ~ 0,year == 2015 ~ 1))

Step 3: Preview the data

view(TAS_data_long_format_age)
knitr::kable(head(TAS_data_long_format_age))
TAS TAS05 TAS09 TAS15 TAS_ID Gender Individual is sample Year ID Number Sequence Number Relationship to Head Release Number B5A B5D B6C C2D C2E C2F D2D3_month D2D3_year E1_1st_mention E1_2nd_mention E1_3rd_mention E3 G1 G2_month G2_year G10 G11 G30A G41A G41B G41C G41H G41P H1 L7_1st_mention L7_2nd_mention L7_3rd_mention Age_17_graduate Age_18_graduate year year_new
2 1 1 NA 4_180 2 3 771 2 22 5 3 5 7 3 1 1 2 2005 1 6 0 0 2 0 0 5 0 7 7 7 7 7 6 3 1 0 0 2022 2023 2005 -1
2 1 1 NA 5_32 2 2 624 3 30 5 5 5 5 7 7 7 0 0 1 7 0 0 1 5 2002 1 1 7 7 6 6 7 5 2 1 0 0 20 21 2005 -1
2 1 1 NA 6_34 1 2 1202 51 30 5 2 2 6 1 1 1 0 0 7 0 0 5 1 5 2002 1 1 0 7 5 7 5 3 1 1 0 0 20 21 2005 -1
2 1 1 NA 14_30 1 2 736 51 30 5 4 4 4 2 1 1 0 0 2 0 0 0 1 6 2003 1 5 6 5 6 6 5 5 2 1 0 0 19 20 2005 -1
1 1 NA NA 18_38 2 2 5647 3 98 5 3 4 3 4 2 2 0 0 3 7 0 5 1 6 2004 1 5 6 5 5 5 7 5 2 1 0 0 18 19 2005 -1
2 1 1 NA 47_34 2 2 2516 3 30 5 4 5 6 4 5 2 0 0 1 0 0 0 1 5 2005 5 0 6 3 6 4 7 4 1 1 0 0 17 18 2005 -1
knitr::kable(TAS_data_long_format_age %>% count(year), align = "cc")
year n
2005 745
2009 1554
2015 1641
knitr::kable(TAS_data_long_format_age %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
18 465
19 504
20 366
21 287
22 331
23 256
24 208
25 121
26 33
27 16
28 1
29 1
32 1
2023 146
2027 264
2033 940
knitr::kable(TAS_data_long_format_age %>% group_by(year) %>%  count(Age_18_graduate) %>% ungroup(), align = "ccc")
year Age_18_graduate n
2005 18 179
2005 19 169
2005 20 164
2005 21 83
2005 22 2
2005 23 2
2005 2023 146
2009 18 195
2009 19 172
2009 20 166
2009 21 172
2009 22 183
2009 23 161
2009 24 153
2009 25 84
2009 26 2
2009 27 1
2009 28 1
2009 2027 264
2015 18 91
2015 19 163
2015 20 36
2015 21 32
2015 22 146
2015 23 93
2015 24 55
2015 25 37
2015 26 31
2015 27 15
2015 29 1
2015 32 1
2015 2033 940

Mean Age

mean_age <- TAS_data_long_format_age %>% group_by(year) %>% filter(Age_18_graduate <50) %>% summarize(mean_age = mean(Age_18_graduate, na.rm = TRUE)) %>% ungroup()
mean_age
## # A tibble: 3 × 2
##    year mean_age
##   <dbl>    <dbl>
## 1  2005     19.3
## 2  2009     21.2
## 3  2015     21.4

SD age

sd_age <- TAS_data_long_format_age %>% group_by(year) %>% filter(Age_18_graduate <50) %>% summarize(sd_age = sd(Age_18_graduate, na.rm = TRUE)) %>% ungroup()
sd_age
## # A tibble: 3 × 2
##    year sd_age
##   <dbl>  <dbl>
## 1  2005   1.07
## 2  2009   2.20
## 3  2015   2.54

###Education Status

TAS_data_long_format_age %>% group_by(year) %>% filter(G1 >0) %>% filter(G1<4) %>% count(G1) %>% ungroup()
## # A tibble: 9 × 3
##    year    G1     n
##   <dbl> <dbl> <int>
## 1  2005     1   601
## 2  2005     2    46
## 3  2005     3    96
## 4  2009     1  1292
## 5  2009     2   108
## 6  2009     3   153
## 7  2015     1   799
## 8  2015     2    52
## 9  2015     3    79

Attended College

TAS_data_long_format_age %>% group_by(year) %>% filter(G10 >0) %>% filter(G10<6) %>% count(G10) %>% ungroup()
## # A tibble: 6 × 3
##    year   G10     n
##   <dbl> <dbl> <int>
## 1  2005     1   487
## 2  2005     5   160
## 3  2009     1  1043
## 4  2009     5   352
## 5  2015     1   531
## 6  2015     5   348

Attending College

TAS_data_long_format_age %>% group_by(year) %>% filter(G11 >0) %>% filter(G11<6) %>% count(G11) %>% ungroup()
## # A tibble: 6 × 3
##    year   G11     n
##   <dbl> <dbl> <int>
## 1  2005     1   397
## 2  2005     5    90
## 3  2009     1   631
## 4  2009     5   412
## 5  2015     1   482
## 6  2015     5   704
TAS_data_long_format_age %>% group_by(year) %>% count(Gender) %>% ungroup()
## # A tibble: 6 × 3
##    year Gender     n
##   <dbl>  <dbl> <int>
## 1  2005      1   348
## 2  2005      2   397
## 3  2009      1   731
## 4  2009      2   823
## 5  2015      1   790
## 6  2015      2   851
TAS_data_long_format_age %>% group_by(year) %>% count(E3) %>% ungroup()
## # A tibble: 11 × 3
##     year    E3     n
##    <dbl> <dbl> <int>
##  1  2005     0   400
##  2  2005     1    86
##  3  2005     5   258
##  4  2005     9     1
##  5  2009     0   928
##  6  2009     1    96
##  7  2009     5   530
##  8  2015     0  1165
##  9  2015     1    51
## 10  2015     5   424
## 11  2015     9     1

2005 vs 2009 vs 2015 (between person; 18-19 y/o)

One-Way ANOVA

TAS_filtered_age <- TAS_data_long_format_age %>% group_by(TAS_ID) %>% mutate(Age_18_graduate = case_when(year == 2005 & Age_18_graduate == 2023 & any(year == 2009) ~ first(Age_18_graduate[year == 2009]) - 4, year == 2009 & Age_18_graduate == 2027 & any(year == 2005) ~ first(Age_18_graduate[year == 2005]) + 4, year == 2009 & Age_18_graduate == 2027 & any(year == 2015) ~ first(Age_18_graduate[year == 2015]) - 6, year == 2015 & Age_18_graduate == 2033 & any(year == 2009) ~ first(Age_18_graduate[year == 2009]) + 6,Age_18_graduate >= 1 & Age_18_graduate <= 50 ~ Age_18_graduate, TRUE ~ Age_18_graduate)) %>% ungroup() %>%  filter(Age_18_graduate == 18 | Age_18_graduate == 19) %>% mutate(year_new = factor(year_new, levels = c(-1, 0, 1), labels = c("2005", "2009", "2015")))
view(TAS_filtered_age)
knitr::kable(head(TAS_filtered_age[, 1:42]))
TAS TAS05 TAS09 TAS15 TAS_ID Gender Individual is sample Year ID Number Sequence Number Relationship to Head Release Number B5A B5D B6C C2D C2E C2F D2D3_month D2D3_year E1_1st_mention E1_2nd_mention E1_3rd_mention E3 G1 G2_month G2_year G10 G11 G30A G41A G41B G41C G41H G41P H1 L7_1st_mention L7_2nd_mention L7_3rd_mention Age_17_graduate Age_18_graduate year year_new
1 1 NA NA 18_38 2 2 5647 3 98 5 3 4 3 4 2 2 0 0 3 7 0 5 1 6 2004 1 5 6 5 5 5 7 5 2 1 0 0 18 19 2005 2005
2 1 1 NA 47_34 2 2 2516 3 30 5 4 5 6 4 5 2 0 0 1 0 0 0 1 5 2005 5 0 6 3 6 4 7 4 1 1 0 0 17 18 2005 2005
2 1 1 NA 53_36 2 2 1616 3 30 5 4 5 7 4 1 1 0 0 6 0 0 1 1 6 2005 1 5 7 7 7 5 7 6 2 1 0 0 17 18 2005 2005
2 1 1 NA 79_32 2 2 6520 2 30 5 3 4 6 7 5 3 0 0 1 7 0 0 1 5 2004 1 1 0 7 7 6 7 4 1 1 0 0 18 19 2005 2005
2 1 1 NA 88_35 1 2 3411 2 30 5 2 5 7 3 1 2 0 0 1 0 0 0 1 5 2005 1 1 7 2 6 5 6 7 2 1 0 0 17 18 2005 2005
2 1 1 NA 89_34 2 2 4527 3 30 5 2 4 5 2 3 1 0 0 3 7 0 5 1 5 2005 1 1 7 5 6 4 7 5 1 1 0 0 17 18 2005 2005
knitr::kable(TAS_filtered_age %>% group_by(year) %>% count(Age_18_graduate), align = "ccc")
year Age_18_graduate n
2005 18 185
2005 19 171
2009 18 196
2009 19 173
2015 18 91
2015 19 163

B5A: Responsibility for self

knitr::kable(TAS_filtered_age %>% count(B5A), align = "cc")
B5A n
1 48
2 202
3 243
4 318
5 167
9 1
B5A_filtered <- TAS_filtered_age %>% filter(B5A < 8) %>% filter(B5A >0)
B5A_Anova <- aov(B5A ~ year_new, data = B5A_filtered)
summary(B5A_Anova)
##              Df Sum Sq Mean Sq F value Pr(>F)
## year_new      2    4.7   2.336   1.826  0.162
## Residuals   975 1247.2   1.279
B5A_pairwise <-TukeyHSD(B5A_Anova)
B5A_pairwise
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = B5A ~ year_new, data = B5A_filtered)
## 
## $year_new
##                  diff         lwr       upr     p adj
## 2009-2005 -0.09379580 -0.29115264 0.1035610 0.5046582
## 2015-2005  0.08028842 -0.13776097 0.2983378 0.6629646
## 2015-2009  0.17408422 -0.04247977 0.3906482 0.1430000
B5A_glht <- glht(B5A_Anova, linfct = mcp(year_new = "Tukey")) 
summary(B5A_glht)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: aov(formula = B5A ~ year_new, data = B5A_filtered)
## 
## Linear Hypotheses:
##                  Estimate Std. Error t value Pr(>|t|)
## 2009 - 2005 == 0 -0.09380    0.08408  -1.116    0.504
## 2015 - 2005 == 0  0.08029    0.09289   0.864    0.663
## 2015 - 2009 == 0  0.17408    0.09226   1.887    0.143
## (Adjusted p values reported -- single-step method)
B5A_pairwise_t_test <- pairwise.t.test(B5A_filtered$B5A, B5A_filtered$year_new, p.adjust.method = "BH")
print(B5A_pairwise_t_test)
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  B5A_filtered$B5A and B5A_filtered$year_new 
## 
##      2005 2009
## 2009 0.39 -   
## 2015 0.39 0.18
## 
## P value adjustment method: BH
B5A_means <- B5A_filtered %>%  group_by(year_new) %>% summarise(Mean = mean(B5A),SD = sd(B5A),Count = n())
knitr::kable((B5A_means), align = "cccc")
year_new Mean SD Count
2005 3.376405 1.105125 356
2009 3.282609 1.151481 368
2015 3.456693 1.136918 254
B5A_filtered$predicted_B5A <- predict(B5A_Anova)
B5A_filtered$year_factor_B5A <- factor(B5A_filtered$year)
ggplot(B5A_filtered, aes(x = Age_18_graduate, y = B5A, color = year_factor_B5A)) + geom_point(aes(shape = year_factor_B5A), alpha = 0.5) + geom_line(aes(y = predicted_B5A), size = 1) +  labs(title = "Responsibility for Self (B5A) by Age and Year",x = "Age", y = "Responsibility for Self (B5A)", color = "Year", shape = "Year") + theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

ggplot(B5A_filtered, aes(x = year_factor_B5A, y = B5A, fill = year_factor_B5A)) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Box Plot of Responsibility for Self (B5A) in 2005, 2009 and 2015",x = "Year", y = "Responsibility for Self (B5A)", fill = "Year") + theme_minimal()

B6C: Money management skills

knitr::kable(TAS_filtered_age %>% count(B6C), align = "cc")
B6C n
1 9
2 23
3 52
4 122
5 276
6 239
7 258
B6C_filtered <- TAS_filtered_age %>% filter(B6C < 8) %>% filter(B6C >0)
B6C_Anova <- aov(B6C ~ year_new, data = B6C_filtered)
summary(B6C_Anova)
##              Df Sum Sq Mean Sq F value Pr(>F)
## year_new      2    4.6   2.297   1.271  0.281
## Residuals   976 1763.8   1.807
B6C_pairwise <-TukeyHSD(B6C_Anova)
B6C_pairwise
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = B6C ~ year_new, data = B6C_filtered)
## 
## $year_new
##                  diff        lwr       upr     p adj
## 2009-2005  0.12987577 -0.1045438 0.3642953 0.3952346
## 2015-2005 -0.02430771 -0.2834785 0.2348631 0.9736358
## 2015-2009 -0.15418347 -0.4114462 0.1030793 0.3377514
B6C_glht <- glht(B6C_Anova, linfct = mcp(year_new = "Tukey")) 
summary(B6C_glht)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: aov(formula = B6C ~ year_new, data = B6C_filtered)
## 
## Linear Hypotheses:
##                  Estimate Std. Error t value Pr(>|t|)
## 2009 - 2005 == 0  0.12988    0.09987   1.300    0.395
## 2015 - 2005 == 0 -0.02431    0.11041  -0.220    0.974
## 2015 - 2009 == 0 -0.15418    0.10960  -1.407    0.337
## (Adjusted p values reported -- single-step method)
B6C_pairwise_t_test <- pairwise.t.test(B6C_filtered$B6C, B6C_filtered$year_new, p.adjust.method = "BH")
print(B6C_pairwise_t_test)
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  B6C_filtered$B6C and B6C_filtered$year_new 
## 
##      2005 2009
## 2009 0.29 -   
## 2015 0.83 0.29
## 
## P value adjustment method: BH
B6C_means <- B6C_filtered %>%  group_by(year_new) %>% summarise(Mean = mean(B6C),SD = sd(B6C),Count = n())
knitr::kable((B6C_means), align = "cccc")
year_new Mean SD Count
2005 5.390449 1.434708 356
2009 5.520325 1.231491 369
2015 5.366142 1.370134 254
B6C_filtered$predicted_B6C <- predict(B6C_Anova)
B6C_filtered$year_factor_B6C <- factor(B6C_filtered$year)
ggplot(B6C_filtered, aes(x = Age_18_graduate, y = B6C, color = year_factor_B6C)) + geom_point(aes(shape = year_factor_B6C), alpha = 0.5) + geom_line(aes(y = predicted_B6C), size = 1) +  labs(title = "Money management skills (B6C) by Age and Year",x = "Age", y = "Money management skills (B6C)", color = "Year", shape = "Year") + theme_minimal()

ggplot(B6C_filtered, aes(x = year_factor_B6C, y = B6C, fill = year_factor_B6C)) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Box Plot of Money management skills (B6C) in 2005, 2009 and 2015",x = "Year", y = "Money management skills (B6C)", fill = "Year") + theme_minimal()

C2D: Worry about expenses

knitr::kable(TAS_filtered_age %>% count(C2D), align = "cc")
C2D n
1 165
2 158
3 159
4 171
5 144
6 84
7 98
C2D_filtered <- TAS_filtered_age %>% filter(C2D < 8) %>% filter(C2D >0)
C2D_Anova <- aov(C2D ~ year_new, data = C2D_filtered)
summary(C2D_Anova)
##              Df Sum Sq Mean Sq F value Pr(>F)
## year_new      2      8   4.105   1.146  0.318
## Residuals   976   3494   3.580
C2D_pairwise <-TukeyHSD(C2D_Anova)
C2D_pairwise
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = C2D ~ year_new, data = C2D_filtered)
## 
## $year_new
##                  diff        lwr       upr     p adj
## 2009-2005 -0.04100058 -0.3709610 0.2889599 0.9541902
## 2015-2005 -0.22586924 -0.5906686 0.1389302 0.3140844
## 2015-2009 -0.18486866 -0.5469824 0.1772451 0.4544183
C2D_glht <- glht(C2D_Anova, linfct = mcp(year_new = "Tukey")) 
summary(C2D_glht)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: aov(formula = C2D ~ year_new, data = C2D_filtered)
## 
## Linear Hypotheses:
##                  Estimate Std. Error t value Pr(>|t|)
## 2009 - 2005 == 0  -0.0410     0.1406  -0.292    0.954
## 2015 - 2005 == 0  -0.2259     0.1554  -1.453    0.314
## 2015 - 2009 == 0  -0.1849     0.1543  -1.198    0.454
## (Adjusted p values reported -- single-step method)
C2D_pairwise_t_test <- pairwise.t.test(C2D_filtered$C2D, C2D_filtered$year_new, p.adjust.method = "BH")
print(C2D_pairwise_t_test)
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  C2D_filtered$C2D and C2D_filtered$year_new 
## 
##      2005 2009
## 2009 0.77 -   
## 2015 0.35 0.35
## 
## P value adjustment method: BH
C2D_means <- C2D_filtered %>%  group_by(year_new) %>% summarise(Mean = mean(C2D),SD = sd(C2D),Count = n())
knitr::kable((C2D_means), align = "cccc")
year_new Mean SD Count
2005 3.702247 1.884285 356
2009 3.661247 1.925696 369
2015 3.476378 1.853699 254
C2D_filtered$predicted_C2D <- predict(C2D_Anova)
C2D_filtered$year_factor_C2D <- factor(C2D_filtered$year)
ggplot(C2D_filtered, aes(x = Age_18_graduate, y = C2D, color = year_factor_C2D)) + geom_point(aes(shape = year_factor_C2D), alpha = 0.5) + geom_line(aes(y = predicted_C2D), size = 1) +  labs(title = "Worry about expense (C2D) by Age and Year",x = "Age", y = "Worry about expense (C2D)", color = "Year", shape = "Year") + theme_minimal()

ggplot(C2D_filtered, aes(x = year_factor_C2D, y = C2D, fill = year_factor_C2D)) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Box Plot of Worry about expense (C2D) in 2005, 2009 and 2015",x = "Year", y = "Worry about expense (C2D)", fill = "Year") + theme_minimal()

C2E: Worry about future job

knitr::kable(TAS_filtered_age %>% count(C2E), align = "cc")
C2E n
1 174
2 175
3 158
4 139
5 133
6 88
7 112
C2E_filtered <- TAS_filtered_age %>% filter(C2E < 8) %>% filter(C2E >0)
C2E_Anova <- aov(C2E ~ year_new, data = C2E_filtered)
summary(C2E_Anova)
##              Df Sum Sq Mean Sq F value Pr(>F)
## year_new      2      1   0.433   0.112  0.894
## Residuals   976   3765   3.857
C2E_pairwise <-TukeyHSD(C2E_Anova)
C2E_pairwise
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = C2E ~ year_new, data = C2E_filtered)
## 
## $year_new
##                  diff        lwr       upr     p adj
## 2009-2005 0.061310557 -0.2811726 0.4037937 0.9072802
## 2015-2005 0.062505530 -0.3161388 0.4411499 0.9205857
## 2015-2009 0.001194973 -0.3746618 0.3770518 0.9999693
C2E_glht <- glht(C2E_Anova, linfct = mcp(year_new = "Tukey")) 
summary(C2E_glht)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: aov(formula = C2E ~ year_new, data = C2E_filtered)
## 
## Linear Hypotheses:
##                  Estimate Std. Error t value Pr(>|t|)
## 2009 - 2005 == 0 0.061311   0.145906   0.420    0.907
## 2015 - 2005 == 0 0.062506   0.161311   0.387    0.920
## 2015 - 2009 == 0 0.001195   0.160124   0.007    1.000
## (Adjusted p values reported -- single-step method)
C2E_pairwise_t_test <- pairwise.t.test(C2E_filtered$C2E, C2E_filtered$year_new, p.adjust.method = "BH")
print(C2E_pairwise_t_test)
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  C2E_filtered$C2E and C2E_filtered$year_new 
## 
##      2005 2009
## 2009 0.99 -   
## 2015 0.99 0.99
## 
## P value adjustment method: BH
C2E_means <- C2E_filtered %>%  group_by(year_new) %>% summarise(Mean = mean(C2E),SD = sd(C2E),Count = n())
knitr::kable((C2E_means), align = "cccc")
year_new Mean SD Count
2005 3.567416 1.945296 356
2009 3.628726 1.974109 369
2015 3.629921 1.975355 254
C2E_filtered$predicted_C2E <- predict(C2E_Anova)
C2E_filtered$year_factor_C2E <- factor(C2E_filtered$year)
ggplot(C2E_filtered, aes(x = Age_18_graduate, y = C2E, color = year_factor_C2E)) + geom_point(aes(shape = year_factor_C2E), alpha = 0.5) + geom_line(aes(y = predicted_C2E), size = 1) +  labs(title = "Worry about future job (C2E) by Age and Year",x = "Age", y = "Worry about future job (C2E)", color = "Year", shape = "Year") + theme_minimal()

ggplot(C2E_filtered, aes(x = year_factor_C2E, y = C2E, fill = year_factor_C2E)) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Box Plot of Worry about future job (C2E) in 2005, 2009 and 2015",x = "Year", y = "Worry about future job (C2E)", fill = "Year") + theme_minimal()

G41A: Importance of job status

knitr::kable(TAS_filtered_age %>% count(G41A), align = "cc")
G41A n
1 38
2 36
3 76
4 116
5 239
6 199
7 274
9 1
G41A_filtered <- TAS_filtered_age %>% filter(G41A < 8) %>% filter(G41A >0)
G41A_Anova <- aov(G41A ~ year_new, data = G41A_filtered)
summary(G41A_Anova)
##              Df Sum Sq Mean Sq F value   Pr(>F)    
## year_new      2   42.2  21.091   8.046 0.000342 ***
## Residuals   975 2555.8   2.621                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
G41A_pairwise <-TukeyHSD(G41A_Anova)
G41A_pairwise
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = G41A ~ year_new, data = G41A_filtered)
## 
## $year_new
##                  diff        lwr        upr     p adj
## 2009-2005 -0.03083781 -0.3133562  0.2516806 0.9644608
## 2015-2005 -0.48834380 -0.8004838 -0.1762038 0.0007404
## 2015-2009 -0.45750599 -0.7675196 -0.1474923 0.0016083
G41A_glht <- glht(G41A_Anova, linfct = mcp(year_new = "Tukey")) 
summary(G41A_glht)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: aov(formula = G41A ~ year_new, data = G41A_filtered)
## 
## Linear Hypotheses:
##                  Estimate Std. Error t value Pr(>|t|)    
## 2009 - 2005 == 0 -0.03084    0.12036  -0.256 0.964399    
## 2015 - 2005 == 0 -0.48834    0.13298  -3.672 0.000746 ***
## 2015 - 2009 == 0 -0.45751    0.13207  -3.464 0.001587 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
G41A_pairwise_t_test <- pairwise.t.test(G41A_filtered$G41A, G41A_filtered$year_new, p.adjust.method = "BH")
print(G41A_pairwise_t_test)
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  G41A_filtered$G41A and G41A_filtered$year_new 
## 
##      2005    2009   
## 2009 0.79784 -      
## 2015 0.00076 0.00083
## 
## P value adjustment method: BH
G41A_means <- G41A_filtered %>%  group_by(year_new) %>% summarise(Mean = mean(G41A),SD = sd(G41A),Count = n())
knitr::kable((G41A_means), align = "cccc")
year_new Mean SD Count
2005 5.362360 1.627454 356
2009 5.331522 1.530395 368
2015 4.874016 1.728588 254
G41A_filtered$predicted_G41A <- predict(G41A_Anova)
G41A_filtered$year_factor_G41A <- factor(G41A_filtered$year)
ggplot(G41A_filtered, aes(x = Age_18_graduate, y = G41A, color = year_factor_G41A)) + geom_point(aes(shape = year_factor_G41A), alpha = 0.5) + geom_line(aes(y = predicted_G41A), size = 1) +  labs(title = "Importance of job status (G41A) by Age and Year",x = "Age", y = "Importance of job status (G41A)", color = "Year", shape = "Year") + theme_minimal()

ggplot(G41A_filtered, aes(x = year_factor_G41A, y = G41A, fill = year_factor_G41A)) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Box Plot of Importance of job status (G41A) in 2005, 2009 and 2015",x = "Year", y = "Importance of job status (G41A)", fill = "Year") + theme_minimal()

2005 & 2009 & 2015 (between person; 18-19 y/o)

Demographics

Filter the data (2005 & 2009 & 2015)

Long_format_2005_2009_2015_new <-  TAS_data_long_format_age %>% filter(year==2005| year==2015| year == 2009) %>% filter(Age_18_graduate == 18|Age_18_graduate == 19) %>% mutate(year_new = case_when(year == 2005 ~ -1, year == 2009 ~ 0,year == 2015 ~ 1)) %>% mutate(year_new = case_when(year == 2005 ~ -1, year == 2009 ~ 0,year == 2015 ~ 1))
knitr::kable(head(Long_format_2005_2009_2015_new[, 1:42]))
TAS TAS05 TAS09 TAS15 TAS_ID Gender Individual is sample Year ID Number Sequence Number Relationship to Head Release Number B5A B5D B6C C2D C2E C2F D2D3_month D2D3_year E1_1st_mention E1_2nd_mention E1_3rd_mention E3 G1 G2_month G2_year G10 G11 G30A G41A G41B G41C G41H G41P H1 L7_1st_mention L7_2nd_mention L7_3rd_mention Age_17_graduate Age_18_graduate year year_new
1 1 NA NA 18_38 2 2 5647 3 98 5 3 4 3 4 2 2 0 0 3 7 0 5 1 6 2004 1 5 6 5 5 5 7 5 2 1 0 0 18 19 2005 -1
2 1 1 NA 47_34 2 2 2516 3 30 5 4 5 6 4 5 2 0 0 1 0 0 0 1 5 2005 5 0 6 3 6 4 7 4 1 1 0 0 17 18 2005 -1
2 1 1 NA 53_36 2 2 1616 3 30 5 4 5 7 4 1 1 0 0 6 0 0 1 1 6 2005 1 5 7 7 7 5 7 6 2 1 0 0 17 18 2005 -1
2 1 1 NA 79_32 2 2 6520 2 30 5 3 4 6 7 5 3 0 0 1 7 0 0 1 5 2004 1 1 0 7 7 6 7 4 1 1 0 0 18 19 2005 -1
2 1 1 NA 88_35 1 2 3411 2 30 5 2 5 7 3 1 2 0 0 1 0 0 0 1 5 2005 1 1 7 2 6 5 6 7 2 1 0 0 17 18 2005 -1
2 1 1 NA 89_34 2 2 4527 3 30 5 2 4 5 2 3 1 0 0 3 7 0 5 1 5 2005 1 1 7 5 6 4 7 5 1 1 0 0 17 18 2005 -1
knitr::kable(Long_format_2005_2009_2015_new %>% count(year), align = "cc")
year n
2005 348
2009 367
2015 254

Demographics

Year

knitr::kable(count(Long_format_2005_2009_2015_new, year), align = "cc")
year n
2005 348
2009 367
2015 254

Age

knitr::kable(count(Long_format_2005_2009_2015_new, Age_18_graduate), align = "cc")
Age_18_graduate n
18 465
19 504

Age by year (2005)

knitr::kable(Long_format_2005_2009_2015_new %>% filter(year == 2005) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
18 179
19 169

Age by year (2009)

knitr::kable(Long_format_2005_2009_2015_new %>% filter(year == 2009) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
18 195
19 172

Age by year (2015)

knitr::kable(Long_format_2005_2009_2015_new %>% filter(year == 2015) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
18 91
19 163

Gender [1 = Male; 2 = Female]

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(Gender), align = "ccc")
year Gender n
2005 1 169
2005 2 179
2009 1 165
2009 2 202
2015 1 119
2015 2 135

Years graduated high school (by year)

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(G2_year), align = "ccc")
year G2_year n
2005 2004 169
2005 2005 179
2009 2008 172
2009 2009 195
2015 2014 163
2015 2015 91
mean_year_graduation <- Long_format_2005_2009_2015_new %>% group_by(year) %>% summarize(mean_graduation = mean(G2_year, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_year_graduation), align = "cc")
year mean_graduation
2005 2004.514
2009 2008.531
2015 2014.358
sd_year_graduation <- Long_format_2005_2009_2015_new %>% group_by(year) %>% summarize(sd_graduation = sd(G2_year, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_year_graduation), align = "cc")
year sd_graduation
2005 0.5005132
2009 0.4996984
2015 0.4804380

Race – 1st mention [1 = White; 2 = Black, African-American, or Negro; 3 = American Indian or Alaska Native; 4 = Asian; 5 = Native Hawaiian or Pacific Islander; 7 = Some other race; 8 = DK;9 = NA]

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(L7_1st_mention), align = "ccc")
year L7_1st_mention n
2005 1 192
2005 2 129
2005 3 1
2005 4 5
2005 5 3
2005 7 4
2005 8 1
2005 9 13
2009 1 184
2009 2 139
2009 3 6
2009 4 10
2009 5 1
2009 7 25
2009 8 1
2009 9 1
2015 1 139
2015 2 99
2015 3 1
2015 4 3
2015 5 2
2015 7 9
2015 9 1

Race – 2nd mention

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(L7_2nd_mention), align = "ccc")
year L7_2nd_mention n
2005 0 341
2005 2 2
2005 3 2
2005 5 2
2005 7 1
2009 0 347
2009 1 8
2009 2 1
2009 3 6
2009 5 2
2009 7 3
2015 0 228
2015 1 4
2015 2 3
2015 3 15
2015 4 1
2015 5 1
2015 7 2

Race – 3rd mention

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(L7_3rd_mention), align = "ccc")
year L7_3rd_mention n
2005 0 348
2009 0 364
2009 3 3
2015 0 251
2015 1 2
2015 7 1

Widowed – year

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(D2D3_year), align = "ccc")
year D2D3_year n
2005 0 348
2009 0 367
2015 0 254

Employment status – 1st mention [1 = Working now, including military; 2 = Only temporarily laid off; sick or maternity leave; 3 = Looking for work, unemployed; 4 = Retired; 5 = Disabled, permanently or temporarily; 6 = Keeping house; 7 = Student; 8 = Other]

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(E1_1st_mention), align = "ccc")
year E1_1st_mention n
2005 1 163
2005 2 1
2005 3 38
2005 6 6
2005 7 136
2005 8 4
2009 1 149
2009 3 73
2009 6 5
2009 7 139
2009 99 1
2015 1 133
2015 2 1
2015 3 46
2015 6 7
2015 7 67

Employment status – 2nd mention

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(E1_2nd_mention), align = "ccc")
year E1_2nd_mention n
2005 0 261
2005 1 13
2005 3 5
2005 6 3
2005 7 66
2009 0 214
2009 1 19
2009 3 23
2009 6 4
2009 7 107
2015 0 158
2015 1 14
2015 3 10
2015 6 2
2015 7 70

Employment status – 3rd mention

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(E1_3rd_mention), align = "ccc")
year E1_3rd_mention n
2005 0 345
2005 1 1
2005 3 1
2005 7 1
2009 0 367
2015 0 254

Work for money [1 = Yes; 5 = No; 8 = DK; 9 = NA]

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(E3), align = "ccc")
year E3 n
2005 0 177
2005 1 45
2005 5 125
2005 9 1
2009 0 168
2009 1 18
2009 5 181
2015 0 149
2015 1 6
2015 5 99

Education status [1 = Graduated from high school; 2 = Got a GED; 3 = Neither]

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(G1), align = "ccc")
year G1 n
2005 1 348
2009 1 367
2015 1 254

Attended College [1 = Yes; 5 = No]

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(G10), align = "ccc")
year G10 n
2005 1 255
2005 5 92
2005 9 1
2009 1 265
2009 5 102
2015 0 1
2015 1 173
2015 5 80

Attending College [1 = Yes; 5 = No]

knitr::kable(Long_format_2005_2009_2015_new %>% group_by(year) %>% count(G11), align = "ccc")
year G11 n
2005 0 93
2005 1 221
2005 5 34
2009 0 102
2009 1 242
2009 5 23
2015 0 80
2015 1 139
2015 5 35


2005 & 2009 (within person)

t-test (2005 & 2009)

Filter the data (2005 & 2009)

Long_format_2005_2009 <- TAS_data_long_format_age %>% filter(year < 2010) %>% filter (TAS05 == 1) %>%  filter (TAS09 == 1) %>% mutate(year_new = case_when(year == 2005 ~ -1, year == 2009 ~ 0,year == 2015 ~ 1)) %>%  group_by(TAS_ID) %>% mutate(Age_18_graduate = case_when(Age_18_graduate == 2027 ~ Age_18_graduate[year == 2005] + 4, Age_18_graduate == 2023 ~ Age_18_graduate[year == 2009] - 4, TRUE ~ Age_18_graduate)) %>% ungroup() %>% filter (Age_18_graduate <100) %>%  group_by(TAS_ID) %>% mutate(age_difference = Age_18_graduate[year == 2009] - Age_18_graduate[year == 2005]) %>% filter(age_difference < 6) %>% filter(age_difference > 2) %>% ungroup()
view(Long_format_2005_2009)
knitr::kable(head(Long_format_2005_2009[, 1:43]))
TAS TAS05 TAS09 TAS15 TAS_ID Gender Individual is sample Year ID Number Sequence Number Relationship to Head Release Number B5A B5D B6C C2D C2E C2F D2D3_month D2D3_year E1_1st_mention E1_2nd_mention E1_3rd_mention E3 G1 G2_month G2_year G10 G11 G30A G41A G41B G41C G41H G41P H1 L7_1st_mention L7_2nd_mention L7_3rd_mention Age_17_graduate Age_18_graduate year year_new age_difference
2 1 1 NA 5_32 2 2 624 3 30 5 5 5 5 7 7 7 0 0 1 7 0 0 1 5 2002 1 1 7 7 6 6 7 5 2 1 0 0 20 21 2005 -1 4
2 1 1 NA 6_34 1 2 1202 51 30 5 2 2 6 1 1 1 0 0 7 0 0 5 1 5 2002 1 1 0 7 5 7 5 3 1 1 0 0 20 21 2005 -1 4
2 1 1 NA 14_30 1 2 736 51 30 5 4 4 4 2 1 1 0 0 2 0 0 0 1 6 2003 1 5 6 5 6 6 5 5 2 1 0 0 19 20 2005 -1 4
2 1 1 NA 47_34 2 2 2516 3 30 5 4 5 6 4 5 2 0 0 1 0 0 0 1 5 2005 5 0 6 3 6 4 7 4 1 1 0 0 17 18 2005 -1 4
2 1 1 NA 53_35 2 2 1392 3 33 5 4 5 5 3 1 1 0 0 1 0 0 0 1 6 2002 1 1 7 6 7 7 7 5 1 1 0 0 20 21 2005 -1 4
2 1 1 NA 53_36 2 2 1616 3 30 5 4 5 7 4 1 1 0 0 6 0 0 1 1 6 2005 1 5 7 7 7 5 7 6 2 1 0 0 17 18 2005 -1 4
knitr::kable(count(Long_format_2005_2009, year), align = "cc")
year n
2005 542
2009 542
knitr::kable(count(Long_format_2005_2009, Age_18_graduate), align = "ccc")
Age_18_graduate n
14 1
17 7
18 166
19 150
20 141
21 83
22 167
23 150
24 140
25 76
26 2
27 1

Age count - 2005

knitr::kable(Long_format_2005_2009 %>% filter(year == 2005) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
14 1
17 7
18 165
19 150
20 141
21 76
22 1
23 1

Age count - 2009

knitr::kable(Long_format_2005_2009 %>% filter(year == 2009) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
18 1
21 7
22 166
23 149
24 140
25 76
26 2
27 1

data_2005 <- Long_format_2005_2009 %>% filter(year_new == -1)
data_2009 <- Long_format_2005_2009 %>% filter(year_new == 0)

B5A: Responsibility for self

B5A_t_test_05_09 <- t.test(data_2005$B5A, data_2009$B5A, paired = TRUE)
B5A_t_test_05_09
## 
##  Paired t-test
## 
## data:  data_2005$B5A and data_2009$B5A
## t = -14.895, df = 541, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -0.9376670 -0.7191595
## sample estimates:
## mean difference 
##      -0.8284133
knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(B5A), align = "ccc")
year B5A n
2005 1 25
2005 2 105
2005 3 119
2005 4 167
2005 5 126
2009 1 11
2009 2 29
2009 3 47
2009 4 146
2009 5 309
mean_B5A_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(average_B5A = mean(B5A, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_B5A_0509), align = "cc")
year average_B5A
2005 3.487085
2009 4.315498
sd_B5A_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(sd_B5A = sd(B5A, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_B5A_0509), align = "cc")
year sd_B5A
2005 1.1753865
2009 0.9776143
Long_format_2005_2009 %>% ggplot(aes(x = factor(year), y = B5A, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Responsibility for Self (B5A) in 2005 and 2009", x = "Year", y = "Responsibility for Self (B5A)") + scale_fill_manual(values = c("2005" = "skyblue", "2009" = "salmon")) + theme_minimal()

effect_size_B5A_05_09 <- cohens_d(data_2005$B5A, data_2009$B5A, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_B5A_05_09
## Cohen's d |         95% CI
## --------------------------
## -0.64     | [-0.73, -0.55]

B6C: Money management skills

B6C_t_test_05_09 <- t.test(data_2005$B6C, data_2009$B6C, paired = TRUE)
B6C_t_test_05_09
## 
##  Paired t-test
## 
## data:  data_2005$B6C and data_2009$B6C
## t = -1.4667, df = 541, p-value = 0.143
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -0.20285228  0.02942055
## sample estimates:
## mean difference 
##     -0.08671587
knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(B6C), align = "ccc")
year B6C n
2005 1 9
2005 2 21
2005 3 30
2005 4 71
2005 5 163
2005 6 115
2005 7 133
2009 1 4
2009 2 10
2009 3 22
2009 4 88
2009 5 163
2009 6 134
2009 7 121
mean_B6C_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(average_B6C = mean(B6C, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_B6C_0509), align = "cc")
year average_B6C
2005 5.278598
2009 5.365314
sd_B6C_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(sd_B6C = sd(B6C, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_B6C_0509), align = "cc")
year sd_B6C
2005 1.444559
2009 1.272246
Long_format_2005_2009 %>% ggplot(aes(x = factor(year), y = B6C, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Money management skills (B6C) in 2005 and 2009", x = "Year", y = "Money management skills (B6C)") + scale_fill_manual(values = c("2005" = "skyblue", "2009" = "salmon")) + theme_minimal()

effect_size_B6C_05_09 <- cohens_d(data_2005$B6C, data_2009$B6C, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_B6C_05_09
## Cohen's d |        95% CI
## -------------------------
## -0.06     | [-0.15, 0.02]

C2D: Worry about expenses

C2D_t_test_05_09 <- t.test(data_2005$C2D, data_2009$C2D, paired = TRUE)
C2D_t_test_05_09
## 
##  Paired t-test
## 
## data:  data_2005$C2D and data_2009$C2D
## t = -3.0212, df = 541, p-value = 0.002636
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -0.46582598 -0.09874967
## sample estimates:
## mean difference 
##      -0.2822878
knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(C2D), align = "ccc")
year C2D n
2005 1 82
2005 2 87
2005 3 96
2005 4 98
2005 5 81
2005 6 48
2005 7 50
2009 1 60
2009 2 85
2009 3 90
2009 4 97
2009 5 82
2009 6 62
2009 7 66
mean_C2D_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(average_C2D = mean(C2D, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_C2D_0509), align = "cc")
year average_C2D
2005 3.651292
2009 3.933579
sd_C2D_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(sd_C2D = sd(C2D, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_C2D_0509), align = "cc")
year sd_C2D
2005 1.843756
2009 1.869894
ggplot(Long_format_2005_2009, aes(x = factor(year), y = C2D, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Worry about expenses (C2D) in 2005 and 2009", x = "Year", y = "Worry about expenses (C2D)") + scale_fill_manual(values = c("2005" = "skyblue", "2009" = "salmon")) + theme_minimal()

effect_size_C2D_05_09 <- cohens_d(data_2005$C2D, data_2009$C2D, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_C2D_05_09
## Cohen's d |         95% CI
## --------------------------
## -0.13     | [-0.21, -0.05]

C2E: Worry about future job

C2E_t_test_05_09 <- t.test(data_2005$C2E, data_2009$C2E, paired = TRUE)
C2E_t_test_05_09
## 
##  Paired t-test
## 
## data:  data_2005$C2E and data_2009$C2E
## t = -2.5726, df = 541, p-value = 0.01036
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -0.42299611 -0.05670869
## sample estimates:
## mean difference 
##      -0.2398524
knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(C2E), align = "ccc")
year C2E n
2005 1 103
2005 2 101
2005 3 89
2005 4 65
2005 5 86
2005 6 59
2005 7 39
2009 1 75
2009 2 100
2009 3 90
2009 4 90
2009 5 64
2009 6 67
2009 7 56
mean_C2E_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(average_C2E = mean(C2E, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_C2E_0509), align = "cc")
year average_C2E
2005 3.485240
2009 3.725092
sd_C2E_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(sd_C2E = sd(C2E, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_C2E_0509), align = "cc")
year sd_C2E
2005 1.898234
2009 1.903416
ggplot(Long_format_2005_2009, aes(x = factor(year), y = C2E, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Worry about future job (C2E) in 2005 and 2009", x = "Year", y = "Worry about future job (C2E)") + scale_fill_manual(values = c("2005" = "skyblue", "2009" = "salmon")) + theme_minimal()

effect_size_C2E_05_09 <- cohens_d(data_2005$C2E, data_2009$C2E, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_C2E_05_09
## Cohen's d |         95% CI
## --------------------------
## -0.11     | [-0.19, -0.03]

G41A: Importance of job status

G41A_t_test_05_09 <- t.test(data_2005$G41A, data_2009$G41A, paired = TRUE)
G41A_t_test_05_09
## 
##  Paired t-test
## 
## data:  data_2005$G41A and data_2009$G41A
## t = 8.1936, df = 541, p-value = 1.841e-15
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  0.4614852 0.7525369
## sample estimates:
## mean difference 
##       0.6070111
knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(G41A), align = "ccc")
year G41A n
2005 1 22
2005 2 24
2005 3 37
2005 4 61
2005 5 127
2005 6 117
2005 7 154
2009 1 48
2009 2 42
2009 3 42
2009 4 84
2009 5 140
2009 6 85
2009 7 101
mean_G41A_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(average_G41A = mean(G41A, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_G41A_0509), align = "cc")
year average_G41A
2005 5.239852
2009 4.632841
sd_G41A_0509 <- Long_format_2005_2009 %>% group_by(year) %>% summarize(sd_G41A = sd(G41A, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_G41A_0509), align = "cc")
year sd_G41A
2005 1.653328
2009 1.831101
ggplot(Long_format_2005_2009, aes(x = factor(year), y = G41A, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Importance of job status (G41A) in 2005 and 2009", x = "Year", y = "Importance of job status (G41A)") + scale_fill_manual(values = c("2005" = "skyblue", "2009" = "salmon")) + theme_minimal()

effect_size_G41A_05_09 <- cohens_d(data_2005$G41A, data_2009$G41A, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_G41A_05_09
## Cohen's d |       95% CI
## ------------------------
## 0.35      | [0.27, 0.44]

Demographics (2005 & 2009) (within person)

Filter the data (2005 & 2009)

Long_format_2005_2009 <- TAS_data_long_format_age %>% filter(year < 2010) %>% filter (TAS05 == 1) %>%  filter (TAS09 == 1) %>% mutate(year_new = case_when(year == 2005 ~ -1, year == 2009 ~ 0,year == 2015 ~ 1)) %>%  group_by(TAS_ID) %>% mutate(Age_18_graduate = case_when(Age_18_graduate == 2027 ~ Age_18_graduate[year == 2005] + 4, Age_18_graduate == 2023 ~ Age_18_graduate[year == 2009] - 4, TRUE ~ Age_18_graduate)) %>% ungroup() %>% filter (Age_18_graduate <100) %>%  group_by(TAS_ID) %>% mutate(age_difference = Age_18_graduate[year == 2009] - Age_18_graduate[year == 2005]) %>% filter(age_difference < 6) %>% filter(age_difference > 2) %>% ungroup()
view(Long_format_2005_2009)
knitr::kable(head(Long_format_2005_2009[, 1:43]))
TAS TAS05 TAS09 TAS15 TAS_ID Gender Individual is sample Year ID Number Sequence Number Relationship to Head Release Number B5A B5D B6C C2D C2E C2F D2D3_month D2D3_year E1_1st_mention E1_2nd_mention E1_3rd_mention E3 G1 G2_month G2_year G10 G11 G30A G41A G41B G41C G41H G41P H1 L7_1st_mention L7_2nd_mention L7_3rd_mention Age_17_graduate Age_18_graduate year year_new age_difference
2 1 1 NA 5_32 2 2 624 3 30 5 5 5 5 7 7 7 0 0 1 7 0 0 1 5 2002 1 1 7 7 6 6 7 5 2 1 0 0 20 21 2005 -1 4
2 1 1 NA 6_34 1 2 1202 51 30 5 2 2 6 1 1 1 0 0 7 0 0 5 1 5 2002 1 1 0 7 5 7 5 3 1 1 0 0 20 21 2005 -1 4
2 1 1 NA 14_30 1 2 736 51 30 5 4 4 4 2 1 1 0 0 2 0 0 0 1 6 2003 1 5 6 5 6 6 5 5 2 1 0 0 19 20 2005 -1 4
2 1 1 NA 47_34 2 2 2516 3 30 5 4 5 6 4 5 2 0 0 1 0 0 0 1 5 2005 5 0 6 3 6 4 7 4 1 1 0 0 17 18 2005 -1 4
2 1 1 NA 53_35 2 2 1392 3 33 5 4 5 5 3 1 1 0 0 1 0 0 0 1 6 2002 1 1 7 6 7 7 7 5 1 1 0 0 20 21 2005 -1 4
2 1 1 NA 53_36 2 2 1616 3 30 5 4 5 7 4 1 1 0 0 6 0 0 1 1 6 2005 1 5 7 7 7 5 7 6 2 1 0 0 17 18 2005 -1 4

Demographics

Year

knitr::kable(count(Long_format_2005_2009, year), align = "cc")
year n
2005 542
2009 542

Age

knitr::kable(count(Long_format_2005_2009, Age_18_graduate), align = "cc")
Age_18_graduate n
14 1
17 7
18 166
19 150
20 141
21 83
22 167
23 150
24 140
25 76
26 2
27 1

Age by year(2005)

knitr::kable(Long_format_2005_2009 %>% filter(year == 2005) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
14 1
17 7
18 165
19 150
20 141
21 76
22 1
23 1

Age by year (2009)

knitr::kable(Long_format_2005_2009 %>% filter(year == 2009) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
18 1
21 7
22 166
23 149
24 140
25 76
26 2
27 1

Gender [1 = Male; 2 = Female]

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(Gender), align = "ccc")
year Gender n
2005 1 245
2005 2 297
2009 1 245
2009 2 297

Years graduated high school

knitr::kable(Long_format_2005_2009 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% count(G2_year) %>% ungroup(), align = "ccc")
year G2_year n
2005 2001 1
2005 2002 76
2005 2003 139
2005 2004 145
2005 2005 157
2009 2001 2
2009 2002 76
2009 2003 138
2009 2004 144
2009 2005 158
knitr::kable(Long_format_2005_2009 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% count(year), align = "cc")
year n
2005 518
2009 518
mean_year_graduation <- Long_format_2005_2009 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(mean_graduation = mean(G2_year, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_year_graduation), align = "cc")
year mean_graduation
2005 2003.736
2009 2003.734
sd_year_graduation <- Long_format_2005_2009 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(sd_graduation = sd(G2_year, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_year_graduation), align = "cc")
year sd_graduation
2005 1.052552
2009 1.060305

Race – 1st mention [1 = White; 2 = Black, African-American, or Negro; 3 = American Indian or Alaska Native; 4 = Asian; 5 = Native Hawaiian or Pacific Islander; 7 = Some other race; 8 = DK; 9 = NA]

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(L7_1st_mention), align = "ccc")
year L7_1st_mention n
2005 1 293
2005 2 208
2005 3 3
2005 4 6
2005 5 3
2005 7 6
2005 8 2
2005 9 21
2009 1 306
2009 2 206
2009 3 5
2009 4 7
2009 7 17
2009 9 1

Race – 2nd mention

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(L7_2nd_mention), align = "ccc")
year L7_2nd_mention n
2005 0 529
2005 1 1
2005 2 4
2005 3 4
2005 5 2
2005 7 2
2009 0 514
2009 1 1
2009 2 6
2009 3 17
2009 4 1
2009 7 3

Race – 3rd mention

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(L7_3rd_mention), align = "ccc")
year L7_3rd_mention n
2005 0 540
2005 3 1
2005 5 1
2009 0 536
2009 3 3
2009 5 1
2009 7 2

Widowed – year

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(D2D3_year), align = "ccc")
year D2D3_year n
2005 0 542
2009 0 538
2009 2006 2
2009 2007 1
2009 2009 1

Employment status – 1st mention [1 = Working now, including military; 2 = Only temporarily laid off; sick or maternity leave; 3 = Looking for work, unemployed; 4 = Retired; 5 = Disabled, permanently or temporarily; 6 = Keeping house; 7 = Student; 8 = Other]

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(E1_1st_mention), align = "ccc")
year E1_1st_mention n
2005 1 260
2005 2 3
2005 3 50
2005 5 1
2005 6 10
2005 7 213
2005 8 5
2009 1 376
2009 2 1
2009 3 77
2009 5 2
2009 6 20
2009 7 65
2009 8 1

Employment status – 2nd mention

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(E1_2nd_mention), align = "ccc")
year E1_2nd_mention n
2005 0 399
2005 1 27
2005 3 8
2005 5 1
2005 6 2
2005 7 105
2009 0 405
2009 1 23
2009 3 10
2009 5 2
2009 6 10
2009 7 91
2009 8 1

Employment status – 3rd mention

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(E1_3rd_mention), align = "ccc")
year E1_3rd_mention n
2005 0 538
2005 1 1
2005 3 1
2005 6 1
2005 7 1
2009 0 541
2009 1 1

Work for money [1 = Yes; 5 = No; 8 = DK; 9 = NA]

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(E3), align = "ccc")
year E3 n
2005 0 290
2005 1 71
2005 5 180
2005 9 1
2009 0 401
2009 1 20
2009 5 121

Education status [1 = Graduated from high school; 2 = Got a GED; 3 = Neither]

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(G1), align = "ccc")
year G1 n
2005 1 526
2005 2 1
2005 3 13
2005 9 2
2009 1 537
2009 2 4
2009 3 1

Attended College [1 = Yes; 5 = No]

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(G10), align = "ccc")
year G10 n
2005 0 14
2005 1 414
2005 5 113
2005 9 1
2009 0 1
2009 1 443
2009 5 98

Attending College [1 = Yes; 5 = No]

knitr::kable(Long_format_2005_2009 %>% group_by(year) %>% count(G11), align = "ccc")
year G11 n
2005 0 128
2005 1 347
2005 5 67
2009 0 99
2009 1 166
2009 5 277


2009 & 2015 (within person)

t-test (2009 & 2015)

Filter the data (2009 & 2015)

Long_format_2009_2015 <- TAS_data_long_format_age %>% filter (TAS09 == 1) %>%  filter (TAS15 == 1) %>% mutate(year_new = case_when(year == 2005 ~ -1, year == 2009 ~ 0,year == 2015 ~ 1)) %>%  group_by(TAS_ID) %>% mutate(Age_18_graduate = case_when(Age_18_graduate == 2033 ~ Age_18_graduate[year == 2009] + 6, Age_18_graduate == 2027 ~ Age_18_graduate[year == 2015] - 6, TRUE ~ Age_18_graduate)) %>% ungroup() %>% filter (Age_18_graduate <100) %>%  group_by(TAS_ID) %>% mutate(age_difference = Age_18_graduate[year == 2015] - Age_18_graduate[year == 2009]) %>% filter(age_difference < 8) %>% filter(age_difference > 4) %>% ungroup()
view(Long_format_2009_2015)
knitr::kable(head(Long_format_2009_2015[, 1:43]))
TAS TAS05 TAS09 TAS15 TAS_ID Gender Individual is sample Year ID Number Sequence Number Relationship to Head Release Number B5A B5D B6C C2D C2E C2F D2D3_month D2D3_year E1_1st_mention E1_2nd_mention E1_3rd_mention E3 G1 G2_month G2_year G10 G11 G30A G41A G41B G41C G41H G41P H1 L7_1st_mention L7_2nd_mention L7_3rd_mention Age_17_graduate Age_18_graduate year year_new age_difference
2 NA 1 1 4_39 2 2 13 3 60 3 4 5 4 6 7 5 0 0 1 0 0 0 1 5 2008 1 5 5 6 5 2 7 6 2 1 0 0 18 19 2009 0 6
2 NA 1 1 7_40 2 2 3836 2 22 3 2 2 7 7 3 4 0 0 6 0 0 5 1 6 2007 5 0 5 5 2 5 6 5 3 1 0 0 19 20 2009 0 6
2 NA 1 1 7_41 1 2 576 2 30 3 3 4 7 4 5 4 0 0 3 0 0 5 1 5 2009 5 0 7 5 6 5 7 5 2 1 0 0 17 18 2009 0 6
2 NA 1 1 10_34 2 2 3276 3 30 3 4 5 6 4 1 1 0 0 1 0 0 0 1 6 2008 1 5 7 7 5 4 7 5 2 2 0 0 18 19 2009 0 6
2 NA 1 1 14_31 2 2 713 1 10 3 5 5 7 4 4 4 0 0 1 0 0 0 1 6 2005 5 0 6 5 7 6 7 2 4 1 0 0 21 22 2009 0 6
2 NA 1 1 22_30 2 2 907 2 30 3 5 1 4 3 1 1 0 0 1 0 0 0 1 5 2006 1 1 7 6 6 6 6 6 1 2 0 0 20 21 2009 0 6
knitr::kable(count(Long_format_2009_2015, year), align = "cc")
year n
2009 515
2015 515
knitr::kable(count(Long_format_2009_2015, Age_18_graduate), align = "ccc")
Age_18_graduate n
15 1
18 154
19 134
20 136
21 89
22 2
24 155
25 134
26 136
27 87
28 2

Age count - 2009

knitr::kable(Long_format_2009_2015 %>% filter(year == 2009) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
15 1
18 154
19 134
20 136
21 88
22 2

Age count - 2015

knitr::kable(Long_format_2009_2015 %>% filter(year == 2015) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
21 1
24 155
25 134
26 136
27 87
28 2

data_2009 <- Long_format_2009_2015 %>% filter(year_new == 0)
data_2015 <- Long_format_2009_2015 %>% filter(year_new == 1)

B5A: Responsibility for self (SPECIAL)

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(B5A), align = "ccc")
year B5A n
2009 1 34
2009 2 94
2009 3 113
2009 4 157
2009 5 116
2009 9 1
2015 1 12
2015 2 15
2015 3 35
2015 4 92
2015 5 359
2015 8 2
remove_id_B5A_09 <- Long_format_2009_2015 %>% filter(year_new == 0,B5A > 7) %>% pull(TAS_ID)
remove_id_B5A_15 <- Long_format_2009_2015 %>% filter(year_new == 1, B5A > 7) %>% pull(TAS_ID)
data_2009_B5A <- Long_format_2009_2015 %>% filter(year_new == 0) %>% filter(B5A < 7) %>% filter(!(TAS_ID %in% remove_id_B5A_15))
data_2015_B5A <- Long_format_2009_2015 %>% filter(year_new == 1) %>% filter(B5A < 7) %>% filter(!(TAS_ID %in% remove_id_B5A_09))
B5A_t_test_09_15 <- t.test(data_2009_B5A$B5A, data_2015_B5A$B5A, paired = TRUE)
B5A_t_test_09_15
## 
##  Paired t-test
## 
## data:  data_2009_B5A$B5A and data_2015_B5A$B5A
## t = -17.111, df = 511, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -1.1823174 -0.9387764
## sample estimates:
## mean difference 
##       -1.060547
knitr::kable(Long_format_2009_2015 %>% filter(B5A < 7) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% count(B5A), align = "ccc")
year B5A n
2009 1 34
2009 2 94
2009 3 111
2009 4 157
2009 5 116
2015 1 12
2015 2 15
2015 3 35
2015 4 91
2015 5 359
knitr::kable(Long_format_2009_2015 %>% filter(B5A < 7) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% count(year), align = "cc")
year n
2009 512
2015 512
mean_B5A_0915 <- Long_format_2009_2015 %>% filter(B5A < 7) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(average_B5A = mean(B5A, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_B5A_0915), align = "cc")
year average_B5A
2009 3.443359
2015 4.503906
sd_B5A_0915 <- Long_format_2009_2015 %>% filter(B5A < 7) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(sd_B5A = sd(B5A, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_B5A_0915), align = "cc")
year sd_B5A
2009 1.2117796
2015 0.9194487
Long_format_2009_2015 %>% filter(B5A < 7) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% ggplot(aes(x = factor(year), y = B5A, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Responsibility for Self (B5A) in 2009 and 2015", x = "Year", y = "Responsibility for Self (B5A)") + scale_fill_manual(values = c("2009" = "skyblue", "2015" = "salmon")) + theme_minimal()

effect_size_B5A_09_15 <- cohens_d(data_2009_B5A$B5A, data_2015_B5A$B5A, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_B5A_09_15
## Cohen's d |         95% CI
## --------------------------
## -0.76     | [-0.85, -0.66]

B6C: Money management skills

B6C_t_test_09_15 <- t.test(data_2009$B6C, data_2015$B6C, paired = TRUE)
B6C_t_test_09_15
## 
##  Paired t-test
## 
## data:  data_2009$B6C and data_2015$B6C
## t = 1.5235, df = 514, p-value = 0.1282
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -0.02586079  0.20450156
## sample estimates:
## mean difference 
##      0.08932039
knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(B6C), align = "ccc")
year B6C n
2009 1 4
2009 2 11
2009 3 17
2009 4 62
2009 5 154
2009 6 139
2009 7 128
2015 1 4
2015 2 7
2015 3 27
2015 4 74
2015 5 140
2015 6 157
2015 7 106
mean_B6C_0915 <- Long_format_2009_2015 %>% group_by(year) %>% summarize(average_B6C = mean(B6C, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_B6C_0915), align = "cc")
year average_B6C
2009 5.485437
2015 5.396116
sd_B6C_0915 <- Long_format_2009_2015 %>% group_by(year) %>% summarize(sd_B6C = sd(B6C, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_B6C_0915), align = "cc")
year sd_B6C
2009 1.265096
2015 1.254713
ggplot(Long_format_2009_2015, aes(x = factor(year), y = B6C, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Money management skills (B6C) in 2009 and 2015", x = "Year", y = "Money management skills (B6C)") + scale_fill_manual(values = c("2009" = "skyblue", "2015" = "salmon")) + theme_minimal()

effect_size_B6C_09_15 <- cohens_d(data_2009$B6C, data_2015$B6C, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_B6C_09_15
## Cohen's d |        95% CI
## -------------------------
## 0.07      | [-0.02, 0.15]

C2D: Worry about expenses

C2D_t_test_09_15 <- t.test(data_2009$C2D, data_2015$C2D, paired = TRUE)
C2D_t_test_09_15
## 
##  Paired t-test
## 
## data:  data_2009$C2D and data_2015$C2D
## t = 3.2447, df = 514, p-value = 0.001252
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  0.1256330 0.5112602
## sample estimates:
## mean difference 
##       0.3184466
knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(C2D), align = "ccc")
year C2D n
2009 1 77
2009 2 97
2009 3 65
2009 4 89
2009 5 79
2009 6 49
2009 7 59
2015 1 98
2015 2 99
2015 3 84
2015 4 78
2015 5 73
2015 6 46
2015 7 37
mean_C2D_0915 <- Long_format_2009_2015 %>% group_by(year) %>% summarize(average_C2D = mean(C2D, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_C2D_0915), align = "cc")
year average_C2D
2009 3.735922
2015 3.417476
sd_C2D_0915 <- Long_format_2009_2015 %>% group_by(year) %>% summarize(sd_C2D = sd(C2D, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_C2D_0915), align = "cc")
year sd_C2D
2009 1.930749
2015 1.859481
ggplot(Long_format_2009_2015, aes(x = factor(year), y = C2D, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Worry about expenses (C2D) in 2009 and 2015", x = "Year", y = "Worry about expenses (C2D)") + scale_fill_manual(values = c("2009" = "skyblue", "2015" = "salmon")) + theme_minimal()

effect_size_C2D_09_15 <- cohens_d(data_2009$C2D, data_2015$C2D, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_C2D_09_15
## Cohen's d |       95% CI
## ------------------------
## 0.14      | [0.06, 0.23]

C2E: Worry about future job

C2E_t_test_09_15 <- t.test(data_2009$C2E, data_2015$C2E, paired = TRUE)
C2E_t_test_09_15
## 
##  Paired t-test
## 
## data:  data_2009$C2E and data_2015$C2E
## t = 5.1874, df = 514, p-value = 3.073e-07
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  0.2907333 0.6451890
## sample estimates:
## mean difference 
##       0.4679612
knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(C2E), align = "ccc")
year C2E n
2009 1 89
2009 2 89
2009 3 77
2009 4 86
2009 5 76
2009 6 36
2009 7 62
2015 1 109
2015 2 111
2015 3 96
2015 4 74
2015 5 67
2015 6 25
2015 7 33
mean_C2E_0915 <- Long_format_2009_2015 %>% group_by(year) %>% summarize(average_C2E = mean(C2E, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_C2E_0915), align = "cc")
year average_C2E
2009 3.634952
2015 3.166990
sd_C2E_0915 <- Long_format_2009_2015 %>% group_by(year) %>% summarize(sd_C2E = sd(C2E, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_C2E_0915), align = "cc")
year sd_C2E
2009 1.944448
2015 1.779498
ggplot(Long_format_2009_2015, aes(x = factor(year), y = C2E, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Worry about future job (C2E) in 2009 and 2015", x = "Year", y = "Worry about future job (C2E)") + scale_fill_manual(values = c("2009" = "skyblue", "2015" = "salmon")) + theme_minimal()

effect_size_C2E_09_15 <- cohens_d(data_2009$C2E, data_2015$C2E, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_C2E_09_15
## Cohen's d |       95% CI
## ------------------------
## 0.23      | [0.14, 0.32]

G41A: Importance of job status (SPECIAL)

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(G41A), align = "ccc")
year G41A n
2009 1 30
2009 2 14
2009 3 39
2009 4 70
2009 5 128
2009 6 89
2009 7 144
2009 9 1
2015 1 54
2015 2 50
2015 3 50
2015 4 73
2015 5 115
2015 6 75
2015 7 98
remove_id_G41A <- Long_format_2009_2015 %>% filter(year_new == 0,G41A == 9) %>% pull(TAS_ID)
data_2009_G41A <- Long_format_2009_2015 %>% filter(year_new == 0) %>% filter(G41A != 9) 
data_2015_G41A <- Long_format_2009_2015 %>% filter(year_new == 1) %>% filter(!(TAS_ID %in% remove_id_G41A))
knitr::kable(Long_format_2009_2015 %>% filter(G41A != 9) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% count(G41A), align = "ccc")
year G41A n
2009 1 30
2009 2 14
2009 3 39
2009 4 70
2009 5 128
2009 6 89
2009 7 144
2015 1 54
2015 2 50
2015 3 50
2015 4 73
2015 5 115
2015 6 74
2015 7 98
knitr::kable(Long_format_2009_2015 %>% filter(G41A != 9) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% count(year), align = "cc")
year n
2009 514
2015 514
G41A_t_test_09_15 <- t.test(data_2009_G41A$G41A, data_2015_G41A$G41A, paired = TRUE)
G41A_t_test_09_15
## 
##  Paired t-test
## 
## data:  data_2009_G41A$G41A and data_2015_G41A$G41A
## t = 8.2779, df = 513, p-value = 1.093e-15
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  0.4985536 0.8088394
## sample estimates:
## mean difference 
##       0.6536965
mean_G41A_0915 <- Long_format_2009_2015 %>% filter(G41A != 9) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(average_G41A = mean(G41A, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_G41A_0915), align = "cc")
year average_G41A
2009 5.130350
2015 4.476654
sd_G41A_0915 <- Long_format_2009_2015 %>% filter(G41A != 9) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(sd_G41A = sd(G41A, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_G41A_0915), align = "cc")
year sd_G41A
2009 1.703263
2015 1.930680
Long_format_2009_2015 %>% filter(G41A != 9) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% ggplot(aes(x = factor(year), y = G41A, fill = factor(year))) + geom_boxplot() + stat_summary(fun = "mean", geom = "crossbar", width = 0.75, color = "black", size = 0.2, linetype = "dashed") + labs(title = "Boxplot of Importance of job status (G41A) in 2009 and 2015", x = "Year", y = "Importance of job status (G41A)") + scale_fill_manual(values = c("2009" = "skyblue", "2015" = "salmon")) + theme_minimal()

effect_size_G41A_09_15 <- cohens_d(data_2009_G41A$G41A, data_2015_G41A$G41A, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
effect_size_G41A_09_15
## Cohen's d |       95% CI
## ------------------------
## 0.37      | [0.28, 0.45]

##2009 & 2015

Demographics (2009 & 2015) (within person)

Filter the data (2009 & 2015)

Long_format_2009_2015 <- TAS_data_long_format_age %>% filter (TAS09 == 1) %>%  filter (TAS15 == 1) %>% mutate(year_new = case_when(year == 2005 ~ -1, year == 2009 ~ 0,year == 2015 ~ 1)) %>%  group_by(TAS_ID) %>% mutate(Age_18_graduate = case_when(Age_18_graduate == 2033 ~ Age_18_graduate[year == 2009] + 6, Age_18_graduate == 2027 ~ Age_18_graduate[year == 2015] - 6, TRUE ~ Age_18_graduate)) %>% ungroup() %>% filter (Age_18_graduate <100) %>%  group_by(TAS_ID) %>% mutate(age_difference = Age_18_graduate[year == 2015] - Age_18_graduate[year == 2009]) %>% filter(age_difference < 8) %>% filter(age_difference > 4) %>% ungroup()
view(Long_format_2009_2015)
knitr::kable(head(Long_format_2009_2015[, 1:43]))
TAS TAS05 TAS09 TAS15 TAS_ID Gender Individual is sample Year ID Number Sequence Number Relationship to Head Release Number B5A B5D B6C C2D C2E C2F D2D3_month D2D3_year E1_1st_mention E1_2nd_mention E1_3rd_mention E3 G1 G2_month G2_year G10 G11 G30A G41A G41B G41C G41H G41P H1 L7_1st_mention L7_2nd_mention L7_3rd_mention Age_17_graduate Age_18_graduate year year_new age_difference
2 NA 1 1 4_39 2 2 13 3 60 3 4 5 4 6 7 5 0 0 1 0 0 0 1 5 2008 1 5 5 6 5 2 7 6 2 1 0 0 18 19 2009 0 6
2 NA 1 1 7_40 2 2 3836 2 22 3 2 2 7 7 3 4 0 0 6 0 0 5 1 6 2007 5 0 5 5 2 5 6 5 3 1 0 0 19 20 2009 0 6
2 NA 1 1 7_41 1 2 576 2 30 3 3 4 7 4 5 4 0 0 3 0 0 5 1 5 2009 5 0 7 5 6 5 7 5 2 1 0 0 17 18 2009 0 6
2 NA 1 1 10_34 2 2 3276 3 30 3 4 5 6 4 1 1 0 0 1 0 0 0 1 6 2008 1 5 7 7 5 4 7 5 2 2 0 0 18 19 2009 0 6
2 NA 1 1 14_31 2 2 713 1 10 3 5 5 7 4 4 4 0 0 1 0 0 0 1 6 2005 5 0 6 5 7 6 7 2 4 1 0 0 21 22 2009 0 6
2 NA 1 1 22_30 2 2 907 2 30 3 5 1 4 3 1 1 0 0 1 0 0 0 1 5 2006 1 1 7 6 6 6 6 6 1 2 0 0 20 21 2009 0 6

Demographics

Year

knitr::kable(count(Long_format_2009_2015, year), align = "cc")
year n
2009 515
2015 515

Age

knitr::kable(count(Long_format_2009_2015, Age_18_graduate), align = "cc")
Age_18_graduate n
15 1
18 154
19 134
20 136
21 89
22 2
24 155
25 134
26 136
27 87
28 2

Age by year(2009)

knitr::kable(Long_format_2009_2015 %>% filter(year == 2009) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
15 1
18 154
19 134
20 136
21 88
22 2

Age by year (2015)

knitr::kable(Long_format_2009_2015 %>% filter(year == 2015) %>% count(Age_18_graduate), align = "cc")
Age_18_graduate n
21 1
24 155
25 134
26 136
27 87
28 2

Gender [1 = Male; 2 = Female]

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(Gender), align = "ccc")
year Gender n
2009 1 219
2009 2 296
2015 1 219
2015 2 296

Years graduated high school

knitr::kable(Long_format_2009_2015 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% count(G2_year) %>% ungroup(), align = "ccc") 
year G2_year n
2009 2006 14
2009 2007 29
2009 2008 32
2009 2009 49
2015 2006 13
2015 2007 29
2015 2008 32
2015 2009 50
knitr::kable(Long_format_2009_2015 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% count(year), align = "ccc") 
year n
2009 124
2015 124
mean_year_graduation <- Long_format_2009_2015 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(mean_graduation = mean(G2_year, na.rm = TRUE)) %>% ungroup()
knitr::kable((mean_year_graduation), align = "cc")
year mean_graduation
2009 2007.935
2015 2007.960
sd_year_graduation <- Long_format_2009_2015 %>% filter(G2_year != 0) %>% group_by(TAS_ID) %>% filter(n_distinct(year) == 2) %>% ungroup() %>% group_by(year) %>% summarize(sd_graduation = sd(G2_year, na.rm = TRUE)) %>% ungroup()
knitr::kable((sd_year_graduation), align = "cc")
year sd_graduation
2009 1.041746
2015 1.031214

Race – 1st mention [1 = White; 2 = Black, African-American, or Negro; 3 = American Indian or Alaska Native; 4 = Asian; 5 = Native Hawaiian or Pacific Islander; 7 = Some other race; 8 = DK; 9 = NA]

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(L7_1st_mention), align = "ccc")
year L7_1st_mention n
2009 1 261
2009 2 198
2009 3 7
2009 4 10
2009 7 37
2009 8 1
2009 9 1
2015 1 274
2015 2 195
2015 3 8
2015 4 8
2015 7 26
2015 9 4

Race – 2nd mention

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(L7_2nd_mention), align = "ccc")
year L7_2nd_mention n
2009 0 489
2009 1 8
2009 2 3
2009 3 10
2009 4 1
2009 5 2
2009 7 2
2015 0 497
2015 1 4
2015 2 4
2015 3 8
2015 4 2

Race – 3rd mention

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(L7_3rd_mention), align = "ccc")
year L7_3rd_mention n
2009 0 513
2009 3 2
2015 0 513
2015 1 1
2015 3 1

Widowed – year

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(D2D3_year), align = "ccc")
year D2D3_year n
2009 0 512
2009 2009 3
2015 0 503
2015 2009 2
2015 2012 3
2015 2014 7

Employment status – 1st mention [1 = Working now, including military; 2 = Only temporarily laid off; sick or maternity leave; 3 = Looking for work, unemployed; 4 = Retired; 5 = Disabled, permanently or temporarily; 6 = Keeping house; 7 = Student; 8 = Other]

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(E1_1st_mention), align = "ccc")
year E1_1st_mention n
2009 1 242
2009 3 93
2009 6 12
2009 7 167
2009 99 1
2015 1 406
2015 2 2
2015 3 49
2015 5 4
2015 6 22
2015 7 32

Employment status – 2nd mention

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(E1_2nd_mention), align = "ccc")
year E1_2nd_mention n
2009 0 301
2009 1 35
2009 2 1
2009 3 28
2009 6 3
2009 7 147
2015 0 445
2015 1 6
2015 3 4
2015 6 16
2015 7 44

E1: Employment status – 3rd mention

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(E1_3rd_mention), align = "ccc")
year E1_3rd_mention n
2009 0 514
2009 6 1
2015 0 515

Work for money [1 = Yes; 5 = No; 8 = DK; 9 = NA]

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(E3), align = "ccc")
year E3 n
2009 0 277
2009 1 31
2009 5 207
2015 0 414
2015 1 8
2015 5 93

Education status [1 = Graduated from high school; 2 = Got a GED; 3 = Neither]

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(G1), align = "ccc")
year G1 n
2009 1 511
2009 2 3
2009 3 1
2015 0 370
2015 1 139
2015 2 5
2015 3 1

Attended College [1 = Yes; 5 = No]

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(G10), align = "ccc")
year G10 n
2009 0 1
2009 1 385
2009 5 129
2015 0 403
2015 1 35
2015 5 77

Attending College [1 = Yes; 5 = No]

knitr::kable(Long_format_2009_2015 %>% group_by(year) %>% count(G11), align = "ccc")
year G11 n
2009 0 130
2009 1 323
2009 5 62
2015 0 79
2015 1 86
2015 5 350

2005 vs 2009 vs 2015 (between person; 18-19 y/o)

df_long <- bind_rows(
  mutate(B5A_means, Variable = "B5A"),
  mutate(B6C_means, Variable = "B6C"),
  mutate(C2D_means, Variable = "C2D"),
  mutate(C2E_means, Variable = "C2E"),
  mutate(G41A_means, Variable = "G41A"))
year_colors <- c("2005" = "#990000", "2009" = "#0A2240", "2015" = "#BEBEBE")
knitr::kable(df_long, align = "ccccc")
year_new Mean SD Count Variable
2005 3.376405 1.105125 356 B5A
2009 3.282609 1.151481 368 B5A
2015 3.456693 1.136918 254 B5A
2005 5.390449 1.434708 356 B6C
2009 5.520325 1.231491 369 B6C
2015 5.366142 1.370134 254 B6C
2005 3.702247 1.884285 356 C2D
2009 3.661247 1.925696 369 C2D
2015 3.476378 1.853699 254 C2D
2005 3.567416 1.945296 356 C2E
2009 3.628726 1.974109 369 C2E
2015 3.629921 1.975355 254 C2E
2005 5.362360 1.627454 356 G41A
2009 5.331522 1.530395 368 G41A
2015 4.874016 1.728588 254 G41A
ggplot(df_long, aes(x = Variable, y = Mean, fill = year_new, group = year_new)) + geom_bar(stat = "identity", position = position_dodge(width = 0.8), color = "black", width = 0.5) + geom_errorbar(aes(ymin = Mean - SD, ymax = Mean + SD), position = position_dodge(width = 0.8), width = 0.25, colour = "#000000", size = 1) + scale_fill_manual(values = year_colors) + labs(title = "2005 vs 2009 vs 2015 (between person; 18-19 y/o)", x = "Variables", y = "Mean Value", fill = "Year") + theme_minimal() + theme(axis.text.x = element_text(angle = 0, hjust = 0.5, vjust = 0.5), axis.ticks.length = unit(0.3, "cm")) + theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),plot.title = element_text(size = 16, face = "bold"),axis.title.x = element_text(vjust = -2)) + scale_x_discrete(labels = c("B5A" = "B5A: \n Responsibility \n for Self", "B6C" = "B6C:\n Money Management \n Skills", "C2D" = "C2D:\n Worry about \n Expenses", "C2E" = "C2E:\n Worry about \n Future Job", "G41A" = "G41A:\n Importance of \n Job Status")) + scale_y_continuous(breaks = seq(1, 7, by = 1), expand = c(0, 0)) + coord_cartesian(ylim = c(1, 9))  + 
 
   geom_segment(aes(x = 5 - 0.28, xend = 5 + 0.28, y = 8.3, yend = 8.3), color = "black") + 
  annotate("text", x = 5, y = 8.65, label = "p = 0.001", size = 3.2) + 
  geom_segment(aes(x = 5 - 0.28, xend = 5 - 0.28, y = 8.3, yend = 8), color = "black") + 
  geom_segment(aes(x = 5 + 0.28, xend = 5 + 0.28, y = 8.3, yend = 8), color = "black") +
  
  geom_segment(aes(x = 5.15 - 0.17, xend = 5.15 + 0.17, y = 7.4, yend = 7.4), color = "black") + 
  annotate("text", x = 5.15, y = 7.7, label = "p = 0.002", size = 3.2) + 
  geom_segment(aes(x = 5.15 - 0.17, xend = 5.15 - 0.17, y = 7.4, yend = 7.1), color = "black") + 
  geom_segment(aes(x = 5.15 + 0.17, xend = 5.15 + 0.17, y = 7.4, yend = 7.1), color = "black")

2005 vs 2009 (within person)

df_long_0509_mess <- bind_rows(mutate(mean_B5A_0509, SD = sd_B5A_0509$sd_B5A, Variable = "B5A"), mutate(mean_B6C_0509, SD = sd_B6C_0509$sd_B6C, Variable = "B6C"), mutate(mean_C2D_0509, SD = sd_C2D_0509$sd_C2D, Variable = "C2D"), mutate(mean_C2E_0509, SD = sd_C2E_0509$sd_C2E, Variable = "C2E"), mutate(mean_G41A_0509, SD = sd_G41A_0509$sd_G41A, Variable = "G41A")) %>% gather(key = "Measure", value = "Average", average_B5A, average_B6C, average_C2D, average_C2E, average_G41A)
df_long_0509 <- df_long_0509_mess %>% filter(!is.na(Average), !is.na(SD)) %>% filter(Average >= 0 & Average <= 7)
year_colors_0509 <- c("2005" = "#990000", "2009" = "#0A2240")
knitr::kable(df_long_0509, align = "ccccc")
year SD Variable Measure Average
2005 1.1753865 B5A average_B5A 3.487085
2009 0.9776143 B5A average_B5A 4.315498
2005 1.4445587 B6C average_B6C 5.278598
2009 1.2722460 B6C average_B6C 5.365314
2005 1.8437556 C2D average_C2D 3.651292
2009 1.8698942 C2D average_C2D 3.933579
2005 1.8982344 C2E average_C2E 3.485240
2009 1.9034159 C2E average_C2E 3.725092
2005 1.6533276 G41A average_G41A 5.239852
2009 1.8311009 G41A average_G41A 4.632841
ggplot(df_long_0509, aes(x = Variable, y = Average, fill = as.factor(year), group = year)) + geom_bar(stat = "identity", position = position_dodge(width = 0.8), color = "black", width = 0.5) + geom_errorbar(aes(ymin = Average - SD, ymax = Average + SD), position = position_dodge(width = 0.8), width = 0.25, colour = "#000000", size = 1) + scale_fill_manual(values = year_colors_0509) + labs(title = "2005 vs 2009 (within person)", x = "Variables", y = "Mean Value", fill = "Year") + theme_minimal() + theme(axis.text.x = element_text(angle = 0, hjust = 0.5, vjust = 0.5), axis.ticks.length = unit(0.3, "cm"))+ theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),plot.title = element_text(size = 16, face = "bold"),axis.title.x = element_text(vjust = -2)) + scale_x_discrete(labels = c("B5A" = "B5A: \n Responsibility \n for Self", "B6C" = "B6C:\n Money Management \n Skills", "C2D" = "C2D:\n Worry about \n Expenses", "C2E" = "C2E:\n Worry about \n Future Job", "G41A" = "G41A:\n Importance of \n Job Status")) + scale_y_continuous(breaks = seq(1, 7, by = 1), expand = c(0, 0)) + coord_cartesian(ylim = c(1, 9))  +
  
  geom_segment(aes(x = 1 - 0.24, xend = 1 + 0.24, y = 5.8, yend = 5.8), color = "black") + 
  annotate("text", x = 1, y = 6.15, label = "p = 0.000", size = 3.2) + 
  geom_segment(aes(x = 1 - 0.24, xend = 1 - 0.24, y = 5.8, yend = 5.5), color = "black") + 
  geom_segment(aes(x = 1 + 0.24, xend = 1 + 0.24, y = 5.8, yend = 5.5), color = "black") +

  geom_segment(aes(x = 3 - 0.24, xend = 3 + 0.24, y = 6.4, yend = 6.4), color = "black") + 
  annotate("text", x = 3, y = 6.75, label = "p = 0.003", size = 3.2) + 
  geom_segment(aes(x = 3 - 0.24, xend = 3 - 0.24, y = 6.4, yend = 6.1), color = "black") + 
  geom_segment(aes(x = 3 + 0.24, xend = 3 + 0.24, y = 6.4, yend = 6.1), color = "black") +

  geom_segment(aes(x = 4 - 0.24, xend = 4 + 0.24, y = 6.2, yend = 6.2), color = "black") + 
  annotate("text", x = 4, y = 6.55, label = "p = 0.010", size = 3.2) + 
  geom_segment(aes(x = 4 - 0.24, xend = 4 - 0.24, y = 6.2, yend = 5.9), color = "black") + 
  geom_segment(aes(x = 4 + 0.24, xend = 4 + 0.24, y = 6.2, yend = 5.9), color = "black") +

  geom_segment(aes(x = 5 - 0.24, xend = 5 + 0.24, y = 7.5, yend = 7.5), color = "black") + 
  annotate("text", x = 5, y = 7.85, label = "p = 0.000", size = 3.2) + 
  geom_segment(aes(x = 5 - 0.24, xend = 5 - 0.24, y = 7.5, yend = 7.2), color = "black") + 
  geom_segment(aes(x = 5 + 0.24, xend = 5 + 0.24, y = 7.5, yend = 7.2), color = "black")

2009 vs 2015 (within person)

df_long_0915_mess <- bind_rows(mutate(mean_B5A_0915, SD = sd_B5A_0915$sd_B5A, Variable = "B5A"),mutate(mean_B6C_0915, SD = sd_B6C_0915$sd_B6C, Variable = "B6C"), mutate(mean_C2D_0915, SD = sd_C2D_0915$sd_C2D, Variable = "C2D"),mutate(mean_C2E_0915, SD = sd_C2E_0915$sd_C2E, Variable = "C2E"), mutate(mean_G41A_0915, SD = sd_G41A_0915$sd_G41A, Variable = "G41A")) %>%  gather(key = "Measure", value = "Average", average_B5A, average_B6C, average_C2D, average_C2E, average_G41A)
df_long_0915 <- df_long_0915_mess %>% filter(!is.na(Average), !is.na(SD)) %>% filter(Average >= 0 & Average <= 7)
year_colors_0915 <- c("2009" = "#990000", "2015" = "#0A2240")
knitr::kable(df_long_0915, align = "ccccc")
year SD Variable Measure Average
2009 1.2117796 B5A average_B5A 3.443359
2015 0.9194487 B5A average_B5A 4.503906
2009 1.2650962 B6C average_B6C 5.485437
2015 1.2547127 B6C average_B6C 5.396116
2009 1.9307493 C2D average_C2D 3.735922
2015 1.8594813 C2D average_C2D 3.417476
2009 1.9444478 C2E average_C2E 3.634952
2015 1.7794978 C2E average_C2E 3.166990
2009 1.7032629 G41A average_G41A 5.130350
2015 1.9306797 G41A average_G41A 4.476654
ggplot(df_long_0915, aes(x = Variable, y = Average, fill = as.factor(year), group = year)) + geom_bar(stat = "identity", position = position_dodge(width = 0.8), color = "black", width = 0.5) + geom_errorbar(aes(ymin = Average - SD, ymax = Average + SD), position = position_dodge(width = 0.8), width = 0.25, colour = "#000000", size = 1) + scale_fill_manual(values = year_colors_0915) + labs(title = "2009 vs 2015 (within person)", x = "Variables", y = "Mean Value", fill = "Year") + theme_minimal() + theme(axis.text.x = element_text(angle = 0, hjust = 0.5, vjust = 0.5), axis.ticks.length = unit(0.3, "cm")) + theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),plot.title = element_text(size = 16, face = "bold"),axis.title.x = element_text(vjust = -2)) + scale_x_discrete(labels = c("B5A" = "B5A: \n Responsibility \n for Self", "B6C" = "B6C:\n Money Management \n Skills", "C2D" = "C2D:\n Worry about \n Expenses", "C2E" = "C2E:\n Worry about \n Future Job", "G41A" = "G41A:\n Importance of \n Job Status")) + scale_y_continuous(breaks = seq(1, 7, by = 1), expand = c(0, 0)) + coord_cartesian(ylim = c(1, 9))  +

geom_segment(aes(x = 1 - 0.24, xend = 1 + 0.24, y = 6, yend = 6), color = "black") + 
  annotate("text", x = 1, y = 6.33, label = "p = 0.000", size = 3.2) + 
  geom_segment(aes(x = 1 - 0.24, xend = 1 - 0.24, y = 6, yend = 5.7), color = "black") + 
  geom_segment(aes(x = 1 + 0.24, xend = 1 + 0.24, y = 6, yend = 5.7), color = "black") +
  
  geom_segment(aes(x = 3 - 0.24, xend = 3 + 0.24, y = 6.4, yend = 6.4), color = "black") + 
  annotate("text", x = 3, y = 6.75, label = "p = 0.001", size = 3.2) + 
  geom_segment(aes(x = 3 - 0.24, xend = 3 - 0.24, y = 6.4, yend = 6.1), color = "black") + 
  geom_segment(aes(x = 3 + 0.24, xend = 3 + 0.24, y = 6.4, yend = 6.1), color = "black") +
  
  geom_segment(aes(x = 4 - 0.24, xend = 4 + 0.24, y = 6.2, yend = 6.2), color = "black") + 
  annotate("text", x = 4, y = 6.55, label = "p = 0.000", size = 3.2) + 
  geom_segment(aes(x = 4 - 0.24, xend = 4 - 0.24, y = 6.2, yend = 5.9), color = "black") + 
  geom_segment(aes(x = 4 + 0.24, xend = 4 + 0.24, y = 6.2, yend = 5.9), color = "black") +
  
  geom_segment(aes(x = 5 - 0.24, xend = 5 + 0.24, y = 7.5, yend = 7.5), color = "black") + 
  annotate("text", x = 5, y = 7.85, label = "p = 0.000", size = 3.2) + 
  geom_segment(aes(x = 5 - 0.24, xend = 5 - 0.24, y = 7.5, yend = 7.2), color = "black") + 
  geom_segment(aes(x = 5 + 0.24, xend = 5 + 0.24, y = 7.5, yend = 7.2), color = "black")