-
Notifications
You must be signed in to change notification settings - Fork 1
/
Indiana_Data_LONG_2021.R
149 lines (100 loc) · 6.07 KB
/
Indiana_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
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
###########################################################################################
###
### Script for creating Indiana LONG data set for 2021
###
###########################################################################################
### Load SGP Package:
require(data.table)
### Load base data files
Indiana_Data_LONG_2021 <- fread("Data/Base_Files/ILEARN_2021_Damian_Export_20210625.csv", colClasses=rep("character", 7))
Indiana_Demographics_2021 <- fread("Data/Base_Files/ILEARN_2021_demographics.csv", colClasses=rep("character", 5))
Indiana_Gender <- fread("Data/Base_Files/ILEARN_2019_and_2021_Gender_Demo.txt", colClasses=rep("character", 4))
### Prepare Data
setnames(Indiana_Data_LONG_2021, c("IDOE_CORPORATION_ID", "IDOE_SCHOOL_ID", "STN", "STUDENT_ID", "GRADE_ID", "ELA_SCALE", "MATH_SCALE"))
Indiana_Data_LONG_2021[,"STN":=NULL]
Indiana_Data_LONG_2021 <- rbindlist(list(Indiana_Data_LONG_2021[,c(1:5), with=FALSE], Indiana_Data_LONG_2021[,c(1:4,6), with=FALSE]), use.names=FALSE)
setnames(Indiana_Data_LONG_2021, "ELA_SCALE", "SCALE_SCORE")
Indiana_Data_LONG_2021[,CONTENT_AREA:=rep(c("ELA", "MATHEMATICS"), each=dim(Indiana_Data_LONG_2021)[1]/2)]
Indiana_Data_LONG_2021[,VALID_CASE:="VALID_CASE"]
Indiana_Data_LONG_2021[,SCHOOL_YEAR:="2021"]
Indiana_Data_LONG_2021[,SCALE_SCORE:=as.numeric(SCALE_SCORE)]
### INVALIDATE cases with missing SCALE_SCORE
Indiana_Data_LONG_2021[is.na(SCALE_SCORE), VALID_CASE:="INVALID_CASE"]
### Prepare Indiana_Demographics_2021
setnames(Indiana_Demographics_2021, c("STUDENT_ID", "ETHNICITY", "SPECIAL_EDUCATION_STATUS", "SOCIO_ECONOMIC_STATUS", "ENGLISH_LANGUAGE_LEARNER_STATUS"))
Indiana_Demographics_2021[,SCHOOL_YEAR:="2021"][,VALID_CASE:="VALID_CASE"]
setkey(Indiana_Demographics_2021, VALID_CASE, SCHOOL_YEAR, STUDENT_ID)
setkey(Indiana_Data_LONG_2021, VALID_CASE, SCHOOL_YEAR, STUDENT_ID)
### Merge in demographics
Indiana_Data_LONG_2021 <- Indiana_Demographics_2021[Indiana_Data_LONG_2021]
### Prepare Indiana_Gender_2021
Indiana_Gender[,STN:=NULL]
setnames(Indiana_Gender, c("SCHOOL_YEAR", "STUDENT_ID", "GENDER"))
Indiana_Gender[GENDER=="F", GENDER:="Female"]
Indiana_Gender[GENDER=="M", GENDER:="Male"]
Indiana_Gender_2021 <- Indiana_Gender[SCHOOL_YEAR=="2021"]
Indiana_Gender_2021[, VALID_CASE:="VALID_CASE"]
setkey(Indiana_Gender_2021, VALID_CASE, SCHOOL_YEAR, STUDENT_ID)
### Merge in demographics
Indiana_Data_LONG_2021 <- Indiana_Gender_2021[Indiana_Data_LONG_2021]
setcolorder(Indiana_Data_LONG_2021, c(4,13,1,11,2,12,10,9,3,5,6,7,8))
### Take highest score for duplicates
setkey(Indiana_Data_LONG_2021, VALID_CASE, SCHOOL_YEAR, CONTENT_AREA, GRADE_ID, STUDENT_ID, SCALE_SCORE)
setkey(Indiana_Data_LONG_2021, VALID_CASE, SCHOOL_YEAR, CONTENT_AREA, GRADE_ID, STUDENT_ID)
Indiana_Data_LONG_2021[which(duplicated(Indiana_Data_LONG_2021, by=key(Indiana_Data_LONG_2021)))-1, VALID_CASE:="INVALID_CASE"]
setkey(Indiana_Data_LONG_2021, VALID_CASE, SCHOOL_YEAR, CONTENT_AREA, GRADE_ID, STUDENT_ID)
### Save results
save(Indiana_Data_LONG_2021, file="Data/Indiana_Data_LONG_2021.Rdata")
################################################################################
### Merge in 2019 demographics into Indiana_SGP object (ONE TIME OPERATION)
################################################################################
### Load 2019 Demographic data
#Indiana_Demographics_2019 <- fread("Data/Base_Files/ILEARN_2019_demographics.csv", colClasses=rep("character", 5))
### Prepare Indiana_Demographics_2019
#setnames(Indiana_Demographics_2019, c("ID", "ETHNICITY", "SPECIAL_EDUCATION_STATUS", "SOCIO_ECONOMIC_STATUS", "ENGLISH_LANGUAGE_LEARNER_STATUS"))
#Indiana_Demographics_2019[,YEAR:="2019"][,VALID_CASE:="VALID_CASE"]
#setkey(Indiana_Demographics_2019, VALID_CASE, YEAR, ID)
#load("Data/Base_Files/Indiana_SGP.Rdata")
#tmp.2019 <- copy(Indiana_SGP@Data[YEAR=="2019"])
#tmp.other.years <- copy(Indiana_SGP@Data[YEAR!="2019"])
#tmp.2019[,c("ETHNICITY", "SPECIAL_EDUCATION_STATUS", "SOCIO_ECONOMIC_STATUS", "ENGLISH_LANGUAGE_LEARNER_STATUS"):=NULL]
#setkey(tmp.2019, VALID_CASE, YEAR, ID)
#tmp.2019 <- Indiana_Demographics_2019[tmp.2019]
#tmp.all <- rbindlist(list(tmp.other.years, tmp.2019), use.names=TRUE)
#Indiana_SGP@Data <- tmp.all
#setkey(Indiana_SGP@Data, VALID_CASE, CONTENT_AREA, YEAR, GRADE, ID)
### GENDER merge into SGP object
#Indiana_Gender <- fread("Data/Base_Files/ILEARN_2019_and_2021_Gender_Demo.txt", colClasses=rep("character", 4))
#Indiana_Gender[,STN:=NULL]
#setnames(Indiana_Gender, c("YEAR", "ID", "GENDER"))
#Indiana_Gender[GENDER=="F", GENDER:="Female"]
#Indiana_Gender[GENDER=="M", GENDER:="Male"]
#Indiana_Gender[,VALID_CASE:="VALID_CASE"]
#setkey(Indiana_Gender, VALID_CASE, YEAR, ID)
#tmp.2019_2021 <- copy(Indiana_SGP@Data[YEAR>="2019"])
#tmp.other.years <- copy(Indiana_SGP@Data[YEAR<"2019"])
#tmp.2019_2021[,"GENDER":=NULL]
#setkey(tmp.2019_2021, VALID_CASE, YEAR, ID)
#tmp.2019_2021 <- Indiana_Gender[tmp.2019_2021]
#tmp.all <- rbindlist(list(tmp.other.years, tmp.2019_2021), use.names=TRUE)
#Indiana_SGP@Data <- tmp.all
#setkey(Indiana_SGP@Data, VALID_CASE, CONTENT_AREA, YEAR, GRADE, ID)
#save(Indiana_SGP, file="Data/Indiana_SGP.Rdata")
###########################################################################################
### Merge in 2021 Mode of Instruction
###########################################################################################
#require(data.table)
#load("Data/Indiana_SGP.Rdata")
#tmp.mode.of.instruction.2021 <- fread("Data/Base_Files/Student_Level_Mode_of_Instruction_20210715.csv")
#setnames(tmp.mode.of.instruction.2021, c("ID", "MODE_OF_INSTRUCTION"))
#table(nchar(Indiana_SGP@Data[YEAR=="2021"]$ID))
#tmp.mode.of.instruction.2021[,ID:=as.character(ID)]
#tmp.mode.of.instruction.2021[,YEAR:="2021"]
#tmp.mode.of.instruction.2021[,VALID_CASE:="VALID_CASE"]
#setkey(tmp.mode.of.instruction.2021, VALID_CASE, YEAR, ID)
#tmp.SGP.data <- copy(Indiana_SGP@Data)
#setkey(tmp.SGP.data, VALID_CASE, YEAR, ID)
#tmp.SGP.data <- tmp.mode.of.instruction.2021[tmp.SGP.data]
#setcolorder(tmp.SGP.data, c(4, 5, 3, 8, 1, 9:40, 6, 7, 41:75, 2))
#setkey(tmp.SGP.data, VALID_CASE, CONTENT_AREA, YEAR, GRADE, ID)
#Indiana_SGP@Data <- tmp.SGP.data