-
Notifications
You must be signed in to change notification settings - Fork 0
/
WIDA_IN_Data_LONG_2021.R
72 lines (49 loc) · 2.54 KB
/
WIDA_IN_Data_LONG_2021.R
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
#################################################################################
###
### Data preparation script for WIDA IN data 2021
###
#################################################################################
### Load Packages
require(SGP)
require(data.table)
### Utility function
strtail <- function (s, n = 1) {
if (n < 0)
substring(s, 1 - n)
else substring(s, nchar(s) - n + 1)
}
strhead <- function (s, n) {
if (n < 0)
substr(s, 1, nchar(s) + n)
else substr(s, 1, n)
}
### Load Data
WIDA_IN_Data_LONG_2021 <- fread("Data/Base_Files/WIDA_ACCESS_IN_2020_2021_FINAL.csv")
### Clean Up Data
WIDA_IN_Data_LONG_2021[,STN:=NULL]
WIDA_IN_Data_LONG_2021[,school_year_id:=NULL]
old.names <- c("IDOE_CORPORATION_ID", "IDOE_SCHOOL_ID", "STUDENT_ID", "Grade", "Composite_Overall_Scale Score", "Composite_Overall_Proficiency Level")
setnames(WIDA_IN_Data_LONG_2021, c("DISTRICT_NUMBER", "SCHOOL_NUMBER", "ID", "GRADE", "SCALE_SCORE", "ACHIEVEMENT_LEVEL_ORIGINAL"))
WIDA_IN_Data_LONG_2021[,YEAR := "2021"]
WIDA_IN_Data_LONG_2021[,ID := as.character(ID)]
WIDA_IN_Data_LONG_2021[GRADE=="KG", GRADE:="0"]
WIDA_IN_Data_LONG_2021[,GRADE:=as.character(as.numeric(GRADE))]
WIDA_IN_Data_LONG_2021[,SCALE_SCORE:=as.numeric(SCALE_SCORE)]
WIDA_IN_Data_LONG_2021[,ACHIEVEMENT_LEVEL := as.character(ACHIEVEMENT_LEVEL_ORIGINAL)]
WIDA_IN_Data_LONG_2021[,ACHIEVEMENT_LEVEL := strhead(ACHIEVEMENT_LEVEL, 1)]
WIDA_IN_Data_LONG_2021[ACHIEVEMENT_LEVEL_ORIGINAL %in% c("4.2", "4.3", "4.4"), ACHIEVEMENT_LEVEL:="4.2"]
WIDA_IN_Data_LONG_2021[ACHIEVEMENT_LEVEL_ORIGINAL %in% c("4.5", "4.6", "4.7", "4.8", "4.9"), ACHIEVEMENT_LEVEL:="4.5"]
WIDA_IN_Data_LONG_2021[!is.na(ACHIEVEMENT_LEVEL),ACHIEVEMENT_LEVEL := paste("WIDA Level", ACHIEVEMENT_LEVEL)]
WIDA_IN_Data_LONG_2021[,VALID_CASE := "VALID_CASE"]
WIDA_IN_Data_LONG_2021[,CONTENT_AREA := "READING"]
### Check for duplicates
setkey(WIDA_IN_Data_LONG_2021, VALID_CASE, CONTENT_AREA, YEAR, GRADE, ID, SCALE_SCORE)
setkey(WIDA_IN_Data_LONG_2021, VALID_CASE, CONTENT_AREA, YEAR, GRADE, ID)
WIDA_IN_Data_LONG_2021[which(duplicated(WIDA_IN_Data_LONG_2021, by=key(WIDA_IN_Data_LONG_2021)))-1, VALID_CASE := "INVALID_CASE"]
setkey(WIDA_IN_Data_LONG_2021, VALID_CASE, CONTENT_AREA, YEAR, GRADE, ID)
### Reorder
setcolorder(WIDA_IN_Data_LONG_2021, c(9, 10, 7, 4, 3, 5, 8, 6, 1, 2))
### INVALIDATE cases
WIDA_IN_Data_LONG_2021[is.na(GRADE), VALID_CASE:="INVALID_CASE"]
### Save data
save(WIDA_IN_Data_LONG_2021, file="Data/WIDA_IN_Data_LONG_2021.Rdata")