-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain_code_part1.Rmd
651 lines (542 loc) · 31 KB
/
Main_code_part1.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
---
title: "Attitudes toward equality - part 1"
author: "Pamela Inostroza Fernández"
date: "November 2020"
output:
html_document:
keep_md: true
toc: TRUE
toc_depth: 1
toc_float:
collapsed: true
number_sections: true
theme: united
highlight: tango
editor_options:
chunk_output_type: console
---
# Files analyzed
The present document has the finality of summarize some of the analysis that can be done using CIVED/ICCS data set to study the scales regarding Attitudes toward diverse social groups, such as **Attitudes toward equal rights for all ethnic/racial groups**, **Attitudes toward gender equality** and **Attitudes toward equal rights for immigrants**. Three cycles are available and multiple countries participate in each one of them.
This summary include the following selected countries and years (cycle) in the analysis.
```{r setup, echo = FALSE, message = FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
#knitr::opts_knit$set(root.dir = 'C:/Users/pamel/OneDrive - KU Leuven/Master in Statistics/Master Thesis')
library(haven)
library(readxl)
library(tidyverse)
options(scipen = 999)
options(knitr.kable.NA = '')
#setwd("C:/Users/pamel/OneDrive - KU Leuven/Master in Statistics/Master Thesis/")
```
**Participant countries**
The participant countries were divided in 5 groups:
a. Nordic Countries: Denmark, Finland, Norway, Sweden.
b. Western European Countries: Belgium (Flemish), The Netherlands.
c. Central and Eastern European Countries: Bulgaria, Estonia, Latvia, Lithuania, Croatia, Slovenia.
d. Southern European Countries: Italy, Malta.
e. Latin American Countries: Chile, Peru, Colombia, Dominican Republic, Mexico.
```{r data}
Countries <- read_xlsx("Metadata.xlsx", sheet = "CNT")
Files <- read_xlsx("Metadata.xlsx", sheet = "Files")
CNTa <- c("DNK", "FIN", "NOR", "SWE")
CNTb <- c("BFL", "NLD")
CNTc <- c("BGR", "EST", "LVA", "LTU", "HRV", "SVN")
CNTd <- c("ITA", "MLT")
CNTe <- c("CHL", "PER", "COL", "DOM", "MEX")
CNT <- c(CNTa, CNTb, CNTc, CNTd, CNTe)
# c(AUS", "BFL", "BGR", "CHE", "CHL", "COL", "CYP", "CZE", "DEU", "DNK", "DOM", "ENG", "ESP", "EST", "FIN", "FRA", "GRC", "HKG", "HRV", "HUN", "ISR", "ITA", "KOR", "LTU", "LVA", "MEX", "MLT", "NLD", "NOR", "PER", "POL", "PRT", "ROM", "RUS", "SRB", "SVK", "SVN", "SWE", "TWN", "USA") CNTb #
Itemdesc <- read_xlsx("Items scales.xlsx", sheet = "Scales")
years <- Countries %>% filter(AlphaCode %in% CNT & !is.na(Part)) %>% dplyr::select(Country, AlphaCode, year)
```
```{r namesfiles, comment="", eval=FALSE}
filenames <- NULL
cat("Countries selected and year participation in CIVED/ICCS: \n")
for (cnt in CNT) {
yearf <- years %>% filter(AlphaCode == cnt & year != 22) %>% arrange(as.numeric(year))
cat(paste0(unique(yearf$Country), " : ", paste(sort(ifelse(yearf$year == "99", paste0("19",yearf$year), paste0("20",yearf$year))), collapse = " ")),' \n')
for (yearn in yearf$year) {
CountryEU <- Countries %>% filter(year == yearn & !is.na(EUQ)) %>% dplyr::select(AlphaCode)
CountryLA <- Countries %>% filter(year == yearn & !is.na(LAQ)) %>% dplyr::select(AlphaCode)
Teacher <- Countries %>% filter(year == yearn & !is.na(ITG)) %>% dplyr::select(AlphaCode)
School <- Countries %>% filter(year == yearn & !is.na(ICG)) %>% dplyr::select(AlphaCode)
if (yearn == "99") Folder <- paste0("CivED19",yearn,"_IDB_SPSS_G8") else
Folder <- paste0("ICCS20",yearn,"_IDB_SPSS")
File <- Files %>% filter(!is.na(ToUse)) %>% dplyr::select(Filename)
if (yearn == "99") cycle = "f2" else if (yearn == "09") cycle = "C2" else if (yearn == "16") cycle = "C3" else
if (yearn == "22") cycle = "C4"
if (yearn == "99") {
filenames <- c(filenames, paste0(Folder, "/Data/", "bs_", tolower(cnt), cycle,".sav"))
if (cnt %in% Teacher$AlphaCode) filenames <- c(filenames, paste0(Folder, "/Data/", "bt_", tolower(cnt), cycle,".sav"))
if (cnt %in% School$AlphaCode) filenames <- c(filenames, paste0(Folder, "/Data/", "bc_", tolower(cnt), cycle,".sav"))
} else {
if (cnt %in% CountryLA$AlphaCode) filenames <- c(filenames, paste0(Folder, "/Data/", "ISL",cnt,cycle,".sav"))
if (cnt %in% CountryEU$AlphaCode) filenames <- c(filenames, paste0(Folder, "/Data/", "ISE",cnt,cycle,".sav"))
filenames <- c(filenames, paste0(Folder, "/Data/", "ISG",cnt,cycle,".sav"))
if (cnt %in% Teacher$AlphaCode) filenames <- c(filenames, paste0(Folder, "/Data/", "ITG",cnt,cycle,".sav"))
if (cnt %in% School$AlphaCode) filenames <- c(filenames, paste0(Folder, "/Data/", "ICG",cnt,cycle,".sav"))
}
}
}
#order by questionnaire and cycle
filenames <- filenames[order(substr(filenames,24,26),substr(filenames,30,31))]
rm(list = c("yearf", "cnt", "cycle", "Folder", "yearn", "File", "CountryEU", "CountryLA"))
```
```{r read_spss, eval=FALSE}
ICGC1 <- NULL
ICGC2 <- NULL
ICGC3 <- NULL
ITGC1 <- NULL
ITGC2 <- NULL
ITGC3 <- NULL
ISGC1 <- NULL
ISGC2 <- NULL
ISGC3 <- NULL
ISEC2 <- NULL
ISEC3 <- NULL
ISLC2 <- NULL
ISLC3 <- NULL
for (nc in 1:length(filenames)) {
print(paste("nc:",filenames[nc]))
if (substr(filenames[nc],24,26) == "ICG" | substr(filenames[nc],28,30) == "bc_") {
if (substr(filenames[nc],34,35) == "f2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
dataset_r <- dataset %>% rename_at(vars(colnames(dataset)), ~ toupper(colnames(dataset)))
ICGC1 <- rbind(ICGC1, dataset_r)
} else if (substr(filenames[nc],30,31) == "C2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ICGC2 <- rbind(ICGC2, dataset)
} else if (substr(filenames[nc],30,31) == "C3") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ICGC3 <- rbind(ICGC3, dataset)
}
}
if (substr(filenames[nc],24,26) == "ITG" | substr(filenames[nc],28,30) == "bt_"){
if (substr(filenames[nc],34,35) == "f2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
dataset_r <- dataset %>% rename_at(vars(colnames(dataset)), ~ toupper(colnames(dataset)))
ITGC1 <- rbind(ITGC1, dataset_r)
} else if (substr(filenames[nc],30,31) == "C2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ITGC2 <- rbind(ITGC2, dataset)
} else if (substr(filenames[nc],30,31) == "C3") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ITGC3 <- rbind(ITGC3, dataset)
}
}
if (substr(filenames[nc],24,26) == "ISG" | substr(filenames[nc],28,30) == "bs_"){
if (substr(filenames[nc],34,35) == "f2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
dataset_r <- dataset %>% rename_at(vars(colnames(dataset)), ~ toupper(colnames(dataset)))
dataset_r$IMMIGMLE <- labelled(dataset_r$IMMIGMLE, labels = c(INVALID = 97, OMITTED = 99), label = attr(dataset_r$IMMIGMLE, "label"))
dataset_r$WOMRTMLE <- labelled(dataset_r$WOMRTMLE, labels = c(INVALID = 97, OMITTED = 99), label = attr(dataset_r$WOMRTMLE, "label"))
ISGC1 <- rbind(ISGC1, dataset_r)
} else if (substr(filenames[nc],30,31) == "C2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ISGC2 <- rbind(ISGC2, dataset)
} else if (substr(filenames[nc],30,31) == "C3") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ISGC3 <- rbind(ISGC3, dataset)
}
}
if (substr(filenames[nc],24,26) == "ISE") {
if (substr(filenames[nc],30,31) == "C2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ISEC2 <- rbind(ISEC2, dataset)
} else if (substr(filenames[nc],30,31) == "C3") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ISEC3 <- rbind(ISEC3, dataset)
}
}
if (substr(filenames[nc],24,26) == "ISL") {
if (substr(filenames[nc],30,31) == "C2") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ISLC2 <- rbind(ISLC2, dataset)
} else if (substr(filenames[nc],30,31) == "C3") {
dataset <- read_sav(file.path("Data", filenames[nc]))
ISLC3 <- rbind(ISLC3, dataset)
}
}
}
ISGC1$cycle <- "C1"
ISGC2$cycle <- "C2"
ISGC3$cycle <- "C3"
ISEC2$cycle <- "C2"
ISEC3$cycle <- "C3"
ISLC2$cycle <- "C2"
ISLC3$cycle <- "C3"
ITGC1$cycle <- "C1"
ITGC2$cycle <- "C2"
ITGC3$cycle <- "C3"
ICGC1$cycle <- "C1"
ICGC2$cycle <- "C2"
ICGC3$cycle <- "C3"
ISGC1$questG <- "ISG"
ISGC2$questG <- "ISG"
ISGC3$questG <- "ISG"
ISEC2$questE <- "ISE"
ISEC3$questE <- "ISE"
ISLC2$questL <- "ISL"
ISLC3$questL <- "ISL"
ITGC1$questT <- "ITG"
ITGC2$questT <- "ITG"
ITGC3$questT <- "ITG"
ICGC1$questC <- "ICG"
ICGC2$questC <- "ICG"
ICGC3$questC <- "ICG"
ISGC1 <- ISGC1 %>% rename_at(vars(c("TOTWGT","SENWGT", "JKZONE")), ~ c("TOTWGT_Gc1", "SENWGT_Gc1", "JKZONES"))
ISGC2 <- ISGC2 %>% rename_at(vars(c("TOTWGTS","SENWGTS", "HOMELIT")), ~ c("TOTWGT_Gc2", "SENWGT_Gc2","SHOMELIT"))
ISGC3 <- ISGC3 %>% rename_at(vars(c("TOTWGTS")), ~ c("TOTWGT_Gc3"))
ISEC2 <- ISEC2 %>% rename_at(vars(c("TOTWGTS","SENWGTS")), ~ c("TOTWGT_Ec2", "SENWGT_Ec2"))
ISEC3 <- ISEC3 %>% rename_at(vars(c("TOTWGTS")), ~ c("TOTWGT_Ec3"))
ISLC2 <- ISLC2 %>% rename_at(vars(c("TOTWGTS","SENWGTS")), ~ c("TOTWGT_Lc2", "SENWGT_Lc2"))
ISLC3 <- ISLC3 %>% rename_at(vars(c("TOTWGTS")), ~ c("TOTWGT_Lc3"))
#ITGC1 <- ITGC1 %>% rename_at(vars(c()), ~ c("TOTWGT_Tc1", "SENWGT_Tc1"))
ITGC2 <- ITGC2 %>% rename_at(vars(c("TOTWGTT","SENWGTT")), ~ c("TOTWGT_Tc2", "SENWGT_Tc2"))
ITGC3 <- ITGC3 %>% rename_at(vars(c("TOTWGTT")), ~ c("TOTWGT_Tc3"))
ICGC1 <- ICGC1 %>% rename_at(vars(c("SCHWGT","STDWGT")), ~ c("TOTWGT_Cc1", "SENWGT_Cc1"))
ICGC2 <- ICGC2 %>% rename_at(vars(c("TOTWGTC")), ~ c("TOTWGT_Cc2"))
ICGC3 <- ICGC3 %>% rename_at(vars(c("TOTWGTC")), ~ c("TOTWGT_Cc3"))
#rm(list = c("dataset","nc","filenames"))
#---------------------------------------------
#---------------------------------------------
#---------------------------------------------
#------Summary sample Cycle 1 ----------------
#------Student general questionnaire ---------
ISGC1 %>% dplyr::select(TOTWGT_Gc1,SENWGT_Gc1, JKZONES, COUNTRY, IDSCHOOL, cycle, questG) %>%
group_by(COUNTRY, cycle, questG) %>%
summarise(W99 = sum(TOTWGT_Gc1, na.rm = TRUE),
WS99 = round(sum(SENWGT_Gc1, na.rm = TRUE),0),
nStr99 = n_distinct(JKZONES),
nSch99 = n_distinct(IDSCHOOL),
nStu99 = n()) %>% knitr::kable()
#------Stratum with only one school------------
ISGC1 %>% dplyr::select(JKZONES, COUNTRY, IDSCHOOL, cycle, questG) %>% group_by(COUNTRY, cycle, questG, JKZONES) %>%
summarise(n_schools = n_distinct(IDSCHOOL)) %>% group_by(cycle, COUNTRY, n_schools) %>% count() %>% filter(n_schools == 1)
#------Teacher general questionnaire ---------
# ITGC1 <- ITGC1 %>% group_by(COUNTRY, cycle, questT) %>%
# mutate(SENWGT_Tc1 = (TOTWGT_Tc1/sum(TOTWGT_Tc1))*1000) %>% ungroup()
# ITGC1 %>% dplyr::select(TOTWGT_Tc1,SENWGT_Tc1, COUNTRY, cycle, questT) %>%
# group_by(COUNTRY, cycle, questT) %>%
# summarise(w99 = round(sum(TOTWGT_Tc1, na.rm = TRUE),2),
# WS99 = round(sum(SENWGT_Tc1, na.rm = TRUE),0),
# n = n()) %>% knitr::kable()
#------School general questionnaire ---------
ICGC1 <- ICGC1 %>% group_by(COUNTRY, cycle, questC) %>%
mutate(SENWGT_Cc1 = (TOTWGT_Cc1/sum(TOTWGT_Cc1))*1000) %>% ungroup()
ICGC1 %>% dplyr::select(TOTWGT_Cc1,SENWGT_Cc1, COUNTRY, cycle, questC) %>%
group_by(COUNTRY, cycle, questC) %>%
summarise(w99 = round(sum(TOTWGT_Cc1, na.rm = TRUE),2),
WS99 = round(sum(SENWGT_Cc1, na.rm = TRUE),0),
n = n()) %>% knitr::kable()
#---------------------------------------------
#------Summary sample Cycle 2 ----------------
#------Student general questionnaire ---------
ISGC2 <- ISGC2 %>% group_by(COUNTRY, cycle, questG) %>%
mutate(SENWGT_Gc2 = (TOTWGT_Gc2/sum(TOTWGT_Gc2))*1000) %>% ungroup()
ISGC2 %>% dplyr::select(TOTWGT_Gc2, SENWGT_Gc2, JKZONES, COUNTRY, IDSCHOOL, cycle, questG) %>%
group_by(COUNTRY, cycle, questG) %>%
summarise(W09 = sum(TOTWGT_Gc2, na.rm = TRUE),
WS09 =sum(SENWGT_Gc2, na.rm = TRUE),
nStr09 = n_distinct(JKZONES),
nSch09 = n_distinct(IDSCHOOL),
nStu09 = n()) %>% knitr::kable()
#------Student European questionnaire ---------
ISEC2 <- ISEC2 %>% group_by(COUNTRY, cycle, questE) %>%
mutate(SENWGT_Ec2 = (TOTWGT_Ec2/sum(TOTWGT_Ec2))*1000) %>% ungroup()
ISEC2 %>% dplyr::select(TOTWGT_Ec2,SENWGT_Ec2, JKZONES,COUNTRY, cycle, questE) %>%
group_by(COUNTRY, cycle, questE) %>%
summarise(W09 = round(sum(TOTWGT_Ec2, na.rm = TRUE),2),
WS09 = round(sum(SENWGT_Ec2, na.rm = TRUE),0),
nStr09 = n_distinct(JKZONES),
nSch09 = n_distinct(IDSCHOOL),
nStu09 = n()) %>% knitr::kable()
#------Student Latinam questionnaire ---------
ISLC2 <- ISLC2 %>% group_by(COUNTRY, cycle, questL) %>%
mutate(SENWGT_Lc2 = (TOTWGT_Lc2/sum(TOTWGT_Lc2))*1000) %>% ungroup()
ISLC2 %>% dplyr::select(TOTWGT_Lc2,SENWGT_Lc2, JKZONES, COUNTRY, cycle, questL) %>%
group_by(COUNTRY, cycle, questL) %>%
summarise(W09 = round(sum(TOTWGT_Lc2, na.rm = TRUE),2),
WS09 = round(sum(SENWGT_Lc2, na.rm = TRUE),0),
nStr09 = n_distinct(JKZONES),
nSch09 = n_distinct(IDSCHOOL),
nStu09 = n()) %>% knitr::kable()
#------Stratus with only one school------------
ISGC2 %>% dplyr::select(JKZONES, COUNTRY, IDSCHOOL, cycle, questG) %>% group_by(COUNTRY, cycle, questG, JKZONES) %>%
summarise(n_schools = n_distinct(IDSCHOOL)) %>% group_by(cycle, COUNTRY, n_schools) %>% count() %>% filter(n_schools == 1)
#------Teacher general questionnaire ---------
ITGC2 <- ITGC2 %>% group_by(COUNTRY, cycle, questT) %>%
mutate(SENWGT_Tc2 = (TOTWGT_Tc2/sum(TOTWGT_Tc2))*1000) %>% ungroup()
ITGC2 %>% dplyr::select(TOTWGT_Tc2,SENWGT_Tc2, COUNTRY, cycle, questT) %>%
group_by(COUNTRY, cycle, questT) %>%
summarise(w09 = round(sum(TOTWGT_Tc2, na.rm = TRUE),2),
WS09 = round(sum(SENWGT_Tc2, na.rm = TRUE),0),
n = n()) %>% knitr::kable()
#------School general questionnaire ---------
ICGC2 <- ICGC2 %>% group_by(COUNTRY, cycle, questC) %>%
mutate(SENWGT_Cc2 = (TOTWGT_Cc2/sum(TOTWGT_Cc2))*1000) %>% ungroup()
ICGC2 %>% dplyr::select(TOTWGT_Cc2, SENWGT_Cc2, COUNTRY, cycle, questC) %>%
group_by(COUNTRY, cycle, questC) %>%
summarise(w09 = round(sum(TOTWGT_Cc2, na.rm = TRUE),2),
WS09 = round(sum(SENWGT_Cc2, na.rm = TRUE),0),
n = n()) %>% knitr::kable()
#---------------------------------------------
#------Summary sample Cycle 3 ----------------
#------Student general questionnaire ---------
ISGC3 <- ISGC3 %>% group_by(COUNTRY, cycle, questG) %>%
mutate(SENWGT_Gc3 = (TOTWGT_Gc3/sum(TOTWGT_Gc3))*1000) %>% ungroup()
ISGC3 %>% dplyr::select(TOTWGT_Gc3, SENWGT_Gc3, JKZONES, COUNTRY, IDSCHOOL, cycle, questG) %>%
group_by(COUNTRY, cycle, questG) %>%
summarise(W16 = sum(TOTWGT_Gc3, na.rm = TRUE),
WS16 = sum(SENWGT_Gc3, na.rm = TRUE),
nStr16 = n_distinct(JKZONES),
nSch16 = n_distinct(IDSCHOOL),
nStu16 = n()) %>% knitr::kable()
#------Student European questionnaire ---------
ISEC3 <- ISEC3 %>% group_by(COUNTRY, cycle, questE) %>%
mutate(SENWGT_Ec3 = (TOTWGT_Ec3/sum(TOTWGT_Ec3))*1000) %>% ungroup()
ISEC3 %>% dplyr::select(TOTWGT_Ec3, SENWGT_Ec3, JKZONES, COUNTRY, cycle, questE) %>%
group_by(COUNTRY, cycle, questE) %>%
summarise(W16 = round(sum(TOTWGT_Ec3, na.rm = TRUE),2),
WS16 = round(sum(SENWGT_Ec3, na.rm = TRUE),0),
JK16 = n_distinct(JKZONES),
n = n()) %>% knitr::kable()
#------Student Latinam questionnaire ---------
ISLC3 <- ISLC3 %>% group_by(COUNTRY, cycle, questL) %>%
mutate(SENWGT_Lc3 = (TOTWGT_Lc3/sum(TOTWGT_Lc3))*1000) %>% ungroup()
ISLC3 %>% dplyr::select(TOTWGT_Lc3, SENWGT_Lc3, JKZONES, COUNTRY, cycle, questL) %>%
group_by(COUNTRY, cycle, questL) %>%
summarise(W16 = round(sum(TOTWGT_Lc3, na.rm = TRUE),2),
WS16 = round(sum(SENWGT_Lc3, na.rm = TRUE),0),
JK16 = n_distinct(JKZONES),
n = n()) %>% knitr::kable()
#------Stratus with only one school------------
ISGC3 %>% dplyr::select(JKZONES, COUNTRY, IDSCHOOL, cycle, questG) %>% group_by(COUNTRY, cycle, questG, JKZONES) %>%
summarise(n_schools = n_distinct(IDSCHOOL)) %>% group_by(cycle, COUNTRY, n_schools) %>% count() %>% filter(n_schools == 1)
#------Teacher general questionnaire ---------
ITGC3 <- ITGC3 %>% group_by(COUNTRY, cycle, questT) %>%
mutate(SENWGT_Tc3 = (TOTWGT_Tc3/sum(TOTWGT_Tc3))*1000) %>% ungroup()
ITGC3 %>% dplyr::select(TOTWGT_Tc3, SENWGT_Tc3, COUNTRY, cycle, questT) %>%
group_by(COUNTRY, cycle, questT) %>%
summarise(w16 = round(sum(TOTWGT_Tc3, na.rm = TRUE),2),
WS16 = round(sum(SENWGT_Tc3, na.rm = TRUE),0),
n = n()) %>% knitr::kable()
#------School general questionnaire ---------
ICGC3 <- ICGC3 %>% group_by(COUNTRY, cycle, questC) %>%
mutate(SENWGT_Cc3 = (TOTWGT_Cc3/sum(TOTWGT_Cc3))*1000) %>% ungroup()
ICGC3 %>% dplyr::select(TOTWGT_Cc3, SENWGT_Cc3, COUNTRY, cycle, questC) %>%
group_by(COUNTRY, cycle, questC) %>%
summarise(w16 = round(sum(TOTWGT_Cc3, na.rm = TRUE),2),
WS16 = round(sum(SENWGT_Cc3, na.rm = TRUE),0),
n = n()) %>% knitr::kable()
```
```{r codebooks, eval=FALSE}
#Joining Questionnaires for Students
tabISG3 <- read_xlsx("ICCS2016MS_Codebook.xlsx", sheet = "ISGC3")
tabISG3 <- tabISG3 %>% dplyr::select(ID,VariableC3, VariableC2, VariableC1, VariableName, Domain, Construct, Label, `Value Scheme Detailed`) %>% mutate(Dataset = "ISG")
tabISE3 <- read_xlsx("ICCS2016MS_Codebook.xlsx", sheet = "ISEC3")
tabISE3 <- tabISE3 %>% dplyr::select(ID,VariableC3, VariableC2, VariableC1, VariableName, Domain, Construct, Label, `Value Scheme Detailed`) %>% mutate(Dataset = "ISE")
tabISL3 <- read_xlsx("ICCS2016MS_Codebook.xlsx", sheet = "ISLC3")
tabISL3 <- tabISL3 %>% dplyr::select(ID,VariableC3, VariableC2, VariableC1, VariableName, Domain, Construct, Label, `Value Scheme Detailed`) %>% mutate(Dataset = "ISL")
tabITG3 <- read_xlsx("ICCS2016MS_Codebook.xlsx", sheet = "ITGC3")
tabITG3 <- tabITG3 %>% dplyr::select(ID,VariableC3, VariableC2, VariableC1, VariableName, Domain, Construct, Label, `Value Scheme Detailed`) %>% mutate(Dataset = "ITG")
tabICG3 <- read_xlsx("ICCS2016MS_Codebook.xlsx", sheet = "ICGC3")
tabICG3 <- tabICG3 %>% dplyr::select(ID,VariableC3, VariableC2, VariableC1, VariableName, Domain, Construct, Label, `Value Scheme Detailed`) %>% mutate(Dataset = "ICG")
VarsToUse <- tabISG3 %>% rbind(tabISE3) %>% rbind(tabISL3) %>% rbind(tabITG3) %>% rbind(tabICG3)
VarsToUse <- VarsToUse %>% filter(!is.na(Construct))
rm("tabISG3", "tabISE3", "tabISL3", "tabITG3", "tabICG3")
idS <- VarsToUse %>% filter(Dataset == "ISG" & Construct == "ID Variables" & !VariableName %in% c("IDGRADE", "IDPOP", "IDBOOK")) %>% dplyr::select(VariableName) %>% pull()
idT <- VarsToUse %>% filter(Dataset == "ITG" & Construct == "ID Variables" & !VariableName %in% c("IDGRADE")) %>% dplyr::select(VariableName) %>% pull()
idC <- VarsToUse %>% filter(Dataset == "ICG" & Construct == "ID Variables" & !VariableName %in% c("IDGRADE")) %>% dplyr::select(VariableName) %>% pull()
```
```{r mergedata, eval=FALSE}
repet <- c("SAGE", "SGENDER", "S_GENDER", "S_AGE") # repeated in datasets
addvar <- c( "cycle", "questG", "questL", "questE", "questT", "questC", #created variables added to dataset
"TOTWGT_Gc1", "SENWGT_Gc1", "TOTWGT_Gc2", "SENWGT_Gc2", "TOTWGT_Gc3", "SENWGT_Gc3",
"TOTWGT_Ec2", "SENWGT_Ec2", "TOTWGT_Ec3", "SENWGT_Ec3",
"TOTWGT_Lc2", "SENWGT_Lc2", "TOTWGT_Lc3", "SENWGT_Lc3",
"TOTWGT_Tc2", "SENWGT_Tc2", "TOTWGT_Tc3", "SENWGT_Tc3",
"TOTWGT_Cc1", "SENWGT_Cc1", "TOTWGT_Cc2", "SENWGT_Cc2", "TOTWGT_Cc3", "SENWGT_Cc3", "JKZONES")
#Merging student questionnaires same cycle, General + European + Latin American
varsC1 <- VarsToUse %>% filter(!is.na(VariableC1) & Dataset %in% c("ISG", "ISE", "ISL")) %>% dplyr::select(VariableC1) %>% pull()
varsC2 <- VarsToUse %>% filter(!is.na(VariableC2) & Dataset %in% c("ISG", "ISE", "ISL")) %>% dplyr::select(VariableC2) %>% pull()
varsC3 <- VarsToUse %>% filter(!is.na(VariableC3) & Dataset %in% c("ISG", "ISE", "ISL")) %>% dplyr::select(VariableC3) %>% pull()
if (is.data.frame(ISGC1)) ISC1 <- ISGC1[, colnames(ISGC1) %in% c(varsC1,addvar)]
if (is.data.frame(ISGC2) & is.data.frame(ISEC2)) {
ISC2 <- ISGC2[, colnames(ISGC2) %in% c(varsC2, addvar)] %>%
full_join(ISEC2[, colnames(ISEC2) %in% c(varsC2[!varsC2 %in% repet], addvar)], by = c(idS)) #repeated added only in first cycle
}
if (is.data.frame(ISC2) & is.data.frame(ISLC2)) {
ISC2 <- ISC2 %>%
full_join(ISLC2[, colnames(ISLC2) %in% c(varsC2[!varsC2 %in% repet], addvar)], by = c(idS))
}
if (is.data.frame(ISGC3) & is.data.frame(ISEC3)) {
ISC3 <- ISGC3[, colnames(ISGC3) %in% c(varsC3, addvar)] %>%
full_join(ISEC3[, colnames(ISEC3) %in% c(varsC3[!varsC3 %in% repet], addvar)], by = c(idS))
}
if (is.data.frame(ISC3) & is.data.frame(ISLC3)) {
ISC3 <- ISC3 %>%
full_join(ISLC3[, colnames(ISLC3) %in% c(varsC3[!varsC3 %in% repet], addvar)], by = c(idS))
}
#######Student files
# ISC2_r <- rename_cycle(ISC2)
# ISC3_r <- rename_cycle(ISC3)
#Setting (row bind) cycles for Students Questionnaires
if (!exists("ISC1")) ISC1 <- NULL
if (!exists("ISC2")) ISC2 <- NULL
if (!exists("ISC3")) ISC3 <- NULL
ISC <- ISC1 %>%
sjmisc::add_rows(ISC2) %>%
sjmisc::add_rows(ISC3)
#######Teacher file
#Setting (row bind) cycles for Teacher Questionnaires
# ITGC2_r <- rename_cycle(ITGC2)
# ITGC3_r <- rename_cycle(ITGC3)
varsC1 <- VarsToUse %>% filter(!is.na(VariableC1) & Dataset == "ITG") %>% dplyr::select(VariableC1) %>% pull()
varsC2 <- VarsToUse %>% filter(!is.na(VariableC2) & Dataset == "ITG") %>% dplyr::select(VariableC2) %>% pull()
varsC3 <- VarsToUse %>% filter(!is.na(VariableC3) & Dataset == "ITG") %>% dplyr::select(VariableC3) %>% pull()
if (!is.data.frame(ITGC1)) ITGC1 <- NULL else ITGC1 <- ITGC1[, colnames(ITGC1) %in% c(varsC1, addvar)]
if (!is.data.frame(ITGC2)) ITGC2 <- NULL else ITGC2 <- ITGC2[, colnames(ITGC2) %in% c(varsC2, addvar)]
if (!is.data.frame(ITGC3)) ITGC3 <- NULL else ITGC3 <- ITGC3[, colnames(ITGC3) %in% c(varsC3, addvar)]
ITG <- ITGC1 %>%
sjmisc::add_rows(ITGC2) %>%
sjmisc::add_rows(ITGC3)
########School file
#Merging cycles for School Questionnaires
# ICGC2_r <- rename_cycle(ICGC2)
# ICGC3_r <- rename_cycle(ICGC3)
varsC1 <- VarsToUse %>% filter(!is.na(VariableC1) & Dataset == "ICG") %>% dplyr::select(VariableC1) %>% pull()
varsC2 <- VarsToUse %>% filter(!is.na(VariableC2) & Dataset == "ICG") %>% dplyr::select(VariableC2) %>% pull()
varsC3 <- VarsToUse %>% filter(!is.na(VariableC3) & Dataset == "ICG") %>% dplyr::select(VariableC3) %>% pull()
if (!is.data.frame(ICGC1)) ICGC1 <- NULL else ICGC1 <- ICGC1[, colnames(ICGC1) %in% c(varsC1, addvar)]
if (!is.data.frame(ICGC2)) ICGC2 <- NULL else ICGC2 <- ICGC2[, colnames(ICGC2) %in% c(varsC2, addvar)]
if (!is.data.frame(ICGC3)) ICGC3 <- NULL else ICGC3 <- ICGC3[, colnames(ICGC3) %in% c(varsC3, addvar)]
ICG <- ICGC1 %>%
sjmisc::add_rows(ICGC2) %>%
sjmisc::add_rows(ICGC3)
#ICCS <- ISC %>% full_join(ITG, by = c("cycle", idC)) %>% full_join(ICG, by = c("cycle", idC))
# rm(list = c("ISGC1","ISGC2","ISEC2","ISLC2","ISGC3","ISEC3","ISLC3"))
# rm(list = c("ISC1","ISC2", "ISC3"))
# rm(list = c("ITGC1","ITGC2", "ITGC3"))
# rm(list = c("ICGC1","ICGC2", "ICGC3"))
# rm(list = c("repet","idT", "idC", "idS"))
#rm(list = c("ISC2_r", "ISC3_r"))
#rm(list = c("ITGC2_r", "ITGC3_r"))
#rm(list = c("ICGC2_r", "ICGC3_r"))
```
**Weights and sample size**
The number of observations available for each cycle is in the following tables for each questionnaire, Student, Teacher and School.
*n\** corresponds to the effective sample size, *w\** to the total weight and *w\*s* the senate weight (sum up 1000 for each country).
```{r Saveddata, results='asis'}
#save(VarsToUse, ISC, ITG, ICG, file = "ICCSAll.RData")
rm(list=setdiff(ls(), c("Itemdesc", "years")))
load("ICCSAll.RData")
Scales <- c(VarsToUse %>% filter(Domain == "Scales" & Dataset %in% c("ISG","ISE")) %>% select(VariableC1) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Domain == "Scales" & Dataset %in% c("ISG","ISE")) %>% select(VariableC2) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Domain == "Scales" & Dataset %in% c("ISG","ISE")) %>% select(VariableC3) %>% na.omit() %>% pull())
Indices <- c(VarsToUse %>% filter(Domain == "Indice" & Dataset %in% c("ISG","ISE")) %>% select(VariableC1) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Domain == "Indice" & Dataset %in% c("ISG","ISE")) %>% select(VariableC2) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Domain == "Indice" & Dataset %in% c("ISG","ISE")) %>% select(VariableC3) %>% na.omit() %>% pull())
Id <- VarsToUse %>% filter(Construct == "ID Variables" & Dataset == "ISG") %>% select(VariableName) %>% na.omit() %>% pull()
Gender <- c(VarsToUse %>% filter(Construct %in% "Student gender") %>% select(VariableC1) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Construct %in% "Student gender") %>% select(VariableC2) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Construct %in% "Student gender") %>% select(VariableC3) %>% na.omit() %>% pull())
Sample <- c(VarsToUse %>% filter(Construct %in% "Weights" & Dataset == "ISG") %>% select(VariableC1) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Construct %in% "Weights" & Dataset == "ISG") %>% select(VariableC2) %>% na.omit() %>% pull(),
VarsToUse %>% filter(Construct %in% "Weights" & Dataset == "ISG") %>% select(VariableC3) %>% na.omit() %>% pull())
cat(' \n')
cat("\n")
ISC %>% dplyr::select(TOTWGT_Gc1, SENWGT_Gc1, IDSCHOOL, JKZONES, COUNTRY, cycle, questG) %>%
filter(!is.na(TOTWGT_Gc1)) %>%
group_by(COUNTRY, questG) %>%
summarise(w99 = round(sum(TOTWGT_Gc1, na.rm = TRUE),0),
w99s =round(sum(SENWGT_Gc1, na.rm = TRUE),0),
nStr99 = n_distinct(JKZONES),
nSch99 = n_distinct(IDSCHOOL),
nStu99 = n()
) %>%
full_join(ISC %>% dplyr::select(TOTWGT_Gc2, SENWGT_Gc2, IDSCHOOL, JKZONES, COUNTRY, cycle, questG) %>%
filter(!is.na(TOTWGT_Gc2)) %>%
group_by(COUNTRY, questG) %>%
summarise(w09 = round(sum(TOTWGT_Gc2, na.rm = TRUE),0),
w09s =sum(SENWGT_Gc2, na.rm = TRUE),
nStr09 = n_distinct(JKZONES),
nSch09 = n_distinct(IDSCHOOL),
nStu09 = n()),by = c("COUNTRY", "questG")) %>%
full_join(ISC %>% dplyr::select(TOTWGT_Gc3, SENWGT_Gc3, IDSCHOOL, JKZONES, COUNTRY, cycle, questG) %>%
filter(!is.na(TOTWGT_Gc3)) %>%
group_by(COUNTRY, questG) %>%
summarise(w16 = round(sum(TOTWGT_Gc3, na.rm = TRUE),0),
w16s =sum(SENWGT_Gc3, na.rm = TRUE),
nStr16 = n_distinct(JKZONES),
nSch16 = n_distinct(IDSCHOOL),
nStu16 = n()),by = c("COUNTRY", "questG")) %>%
arrange(COUNTRY) %>%
knitr::kable(caption = "Student questionnaires")
cat(' \n')
cat("\n")
ITG %>% dplyr::select(TOTWGT_Tc2,SENWGT_Tc2, IDSCHOOL, COUNTRY, cycle, questT) %>%
filter(!is.na(TOTWGT_Tc2)) %>%
group_by(COUNTRY, questT) %>%
summarise(nTea99 = NA,
nSch99 = NA,
w99 = NA,
w99s =NA,
nTea09 = n(),
nSch09 = n_distinct(IDSCHOOL),
w09 = sum(TOTWGT_Tc2, na.rm = TRUE),
w09s =sum(SENWGT_Tc2, na.rm = TRUE)) %>%
full_join(ITG %>% dplyr::select(TOTWGT_Tc3, SENWGT_Tc3, IDSCHOOL, COUNTRY, cycle, questT) %>%
filter(!is.na(TOTWGT_Tc3)) %>%
group_by(COUNTRY, questT) %>%
summarise(nTea16 = n(),
nSch16 = n_distinct(IDSCHOOL),
w16 = sum(TOTWGT_Tc3, na.rm = TRUE),
w16s =sum(SENWGT_Tc3, na.rm = TRUE)),by = c("COUNTRY", "questT")) %>%
arrange(COUNTRY) %>%
knitr::kable(caption = "Teacher questionnaires")
cat(' \n')
cat("\n")
ICG %>% dplyr::select(TOTWGT_Cc1,SENWGT_Cc1, COUNTRY, cycle, questC) %>%
filter(!is.na(TOTWGT_Cc1)) %>%
group_by(COUNTRY, questC) %>%
summarise(nSch99 = n(),
w99 = sum(TOTWGT_Cc1, na.rm = TRUE),
w99s =round(sum(SENWGT_Cc1, na.rm = TRUE),0)) %>%
full_join(ICG %>% dplyr::select(TOTWGT_Cc2, SENWGT_Cc2, COUNTRY, cycle, questC) %>%
filter(!is.na(TOTWGT_Cc2)) %>%
group_by(COUNTRY, questC) %>%
summarise(nSch09 = n(),
w09 = sum(TOTWGT_Cc2, na.rm = TRUE),
w09s =sum(SENWGT_Cc2, na.rm = TRUE)), by = c("COUNTRY", "questC")) %>%
full_join(ICG %>% dplyr::select(TOTWGT_Cc3, SENWGT_Cc3, COUNTRY, cycle, questC) %>%
filter(!is.na(TOTWGT_Cc3)) %>%
group_by(COUNTRY, questC) %>%
summarise(nSch16 = n(),
w16 = sum(TOTWGT_Cc3, na.rm = TRUE),
w16s =sum(SENWGT_Cc3, na.rm = TRUE)), by = c("COUNTRY", "questC")) %>%
arrange(COUNTRY) %>%
knitr::kable(caption = "School questionnaires")
#colnames(ISC)
```
# Description of variables {.tabset .tabset-fade .tabset-pills}
In this section items available in each data set regarding the constructs of interest are described. Barplots are drawn by country using their respective weights. The frequencies are differentiated by Gender and Total sample.
The indexed of each respective scale are also plotted in a violin diagram, orderer by the weighted mean of each country. The boxplot of the distribution of the data is also included. Dotted line represent the weighted mean for each subgroup and Total.
Each cycle can be seen in each tab in this section.
```{r descriptive, fig.height = 8, fig.width = 7, results = 'asis', fig.show='asis'}
ISC_desc <- ISC %>% select(all_of(Id), all_of(Scales), all_of(Indices), all_of(Sample), all_of(Gender))
source("1.Descriptive_Analysis.R")
rm(ISC_desc)
```
# Confirmatory Factor Analysis (CFA) {.tabset .tabset-fade .tabset-pills}
In this section, a confirmatory factor analysis for the three scales analysed is performed, using weights and complexity of the sample was taken into account. Invariance analysis was also performed to Gender groups and Country groups. The loading od each country in the specific scale are plot with their respective confidence interval.
Each cycle can be seen in each tab in this section. Finally, last tab show the scores obtained by each model, which are saved and used in the following sections. Latin American countries questionnaires did not include Immigration scale in 2016, the model for this countries only include remaining two scales.
```{r cfa, fig.height = 11, fig.width = 9, results = 'asis'}
ISC$IDJK <- factor(paste0(ISC$IDCNTRY, ISC$JKZONES))
ISC$IDCL <- factor(paste0(ISC$IDCNTRY, ISC$JKZONES, ISC$IDSCHOOL))
sampleID <- c("IDJK", "IDCL", Sample)
ISC_cfa <- ISC %>% select(all_of(Id), all_of(Scales), all_of(Sample), all_of(sampleID), all_of(Gender))
source("2.cfa.R")
ISC_lv <- ISC[,!colnames(ISC) %in% Scales] %>% left_join(ISC_cfa, by = all_of(Id))
#save(ISC_lv, VarsToUse, file = "ICCSAll_lv.RData")
rm(ISC_cfa)
```