-
Notifications
You must be signed in to change notification settings - Fork 0
/
US_Virgin_Islands_Data_LONG.R
71 lines (46 loc) · 3.2 KB
/
US_Virgin_Islands_Data_LONG.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
##############################################################################
###
### Long data preparation script for US Virgin Islands
###
##############################################################################
### Load packages
require(data.table)
require(SGP)
### Load Data
load("Data/Base_Files/Hawaii_Data_LONG_DeIdentified.Rdata")
US_VI_Data_LONG_TEMP <- fread("Data/Base_Files/SB_Data_No_PI_v2.csv")
### Tidy up US_VI Data
US_VI_Data_LONG_ELA <- data.table(
VALID_CASE="VALID_CASE",
YEAR=rep(c("2015", "2016"), each=nrow(US_VI_Data_LONG_TEMP)),
CONTENT_AREA="ELA",
GRADE=as.character(c(US_VI_Data_LONG_TEMP[['2014-15ELAGrade']], US_VI_Data_LONG_TEMP[['2015-16ELAGrade']])),
ID=rep(US_VI_Data_LONG_TEMP[['ID']], 2),
SCALE_SCORE=as.numeric(c(US_VI_Data_LONG_TEMP[['2014-15ELAScaleScore']], US_VI_Data_LONG_TEMP[['2015-16ELAScaleScore']])),
ACHIEVEMENT_LEVEL=as.numeric(c(US_VI_Data_LONG_TEMP[['2014-15ELAPerformanceLevel']], US_VI_Data_LONG_TEMP[['2015-16ELAPerformanceLevel']])),
SCHOOL_NUMBER=c(US_VI_Data_LONG_TEMP[['2014-15ELASchoolNum']], US_VI_Data_LONG_TEMP[['2015-16ELASchoolNum']]),
DISTRICT_NUMBER=c(US_VI_Data_LONG_TEMP[['2014-15ELADistrictID']], US_VI_Data_LONG_TEMP[['2015-16ELADistrictID']]),
ORIGIN="VI")
US_VI_Data_LONG_MATHEMATICS <- data.table(
VALID_CASE="VALID_CASE",
YEAR=rep(c("2015", "2016"), each=nrow(US_VI_Data_LONG_TEMP)),
CONTENT_AREA="MATHEMATICS",
GRADE=as.character(c(US_VI_Data_LONG_TEMP[['2014-15MATGrade']], US_VI_Data_LONG_TEMP[['2015-16MATGrade']])),
ID=rep(US_VI_Data_LONG_TEMP[['ID']], 2),
SCALE_SCORE=as.numeric(c(US_VI_Data_LONG_TEMP[['2014-15MATScaleScore']], US_VI_Data_LONG_TEMP[['2015-16MATScaleScore']])),
ACHIEVEMENT_LEVEL=as.numeric(c(US_VI_Data_LONG_TEMP[['2014-15MATPerformanceLevel']], US_VI_Data_LONG_TEMP[['2015-16MATPerformanceLevel']])),
SCHOOL_NUMBER=c(US_VI_Data_LONG_TEMP[['2014-15MATSchoolNum']], US_VI_Data_LONG_TEMP[['2015-16MATSchoolNum']]),
DISTRICT_NUMBER=c(US_VI_Data_LONG_TEMP[['2014-15MATDistrictID']], US_VI_Data_LONG_TEMP[['2015-16MATDistrictID']]),
ORIGIN="VI")
US_Virgin_Islands_Data_LONG <- rbindlist(list(US_VI_Data_LONG_ELA, US_VI_Data_LONG_MATHEMATICS))
US_Virgin_Islands_Data_LONG <- US_Virgin_Islands_Data_LONG[!is.na(SCALE_SCORE)]
US_Virgin_Islands_Data_LONG[,ACHIEVEMENT_LEVEL:=as.character(factor(ACHIEVEMENT_LEVEL, labels=c("Not Met Standard", "Nearly Met Standard", "Met Standard", "Exceeded Standard")))]
US_Virgin_Islands_Data_LONG[GRADE %in% c("2", "9", "10"), VALID_CASE:="INVALID_CASE"]
### Tidy up Hawaii LONG Data
Hawaii_Data_LONG_DeIdentified[CONTENT_AREA=="READING", CONTENT_AREA:="ELA"]
### Merge in de-identified Hawaii data
US_Virgin_Islands_Data_LONG <- rbindlist(list(US_Virgin_Islands_Data_LONG, Hawaii_Data_LONG_DeIdentified), fill=TRUE)
### setkey
setkey(US_Virgin_Islands_Data_LONG, VALID_CASE, CONTENT_AREA, YEAR, ID)
### Save LONG Data
save(US_Virgin_Islands_Data_LONG, file="Data/US_Virgin_Islands_Data_LONG.Rdata")