-
Notifications
You must be signed in to change notification settings - Fork 0
/
CAClean.R
2161 lines (1803 loc) · 82.1 KB
/
CAClean.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
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#### Center on Reinventing Public Education ####
# Description: Cleaning data obtained from the website of California's Department of Education
# on Performance and Demographics/Enrollment
# Title: Cleaning California
# Created by: Kevin Cha on 07-26-17
# Updated by: Kevin Cha on 08-08-17
# Data from:
# Performance: STAR: http://star.cde.ca.gov/starresearchfiles.asp CAASPP: http://caaspp.cde.ca.gov/
# -Click on 20XX CAASPP Test Results=>Research Files)
# Demographics: http://www.cde.ca.gov/ds/sd/sd/filesenr.asp
# -Click on "File Name"
# Codebook:
# Demographics: http://www.cde.ca.gov/ds/sd/sd/filesenr.asp
# -Click on "File Structure"
# Performance:
# -2016: http://caaspp.cde.ca.gov/sb2016/research_fixfileformat 2015: http://caaspp.cde.ca.gov/caaspp2015/research_fixfileformat.aspx
# -2014: http://caaspp.cde.ca.gov/caaspp2014/research_fixfileformat.aspx 2013: http://star.cde.ca.gov/star2013/research_fixfileformat.aspx
# -2012: http://star.cde.ca.gov/star2012/research_fixfileformat.aspx 2011: http://star.cde.ca.gov/star2011/research_fixfileformat.aspx
# -2010: http://star.cde.ca.gov/star2010/research_fixfileformat.asp 2009: http://star.cde.ca.gov/star2009/research_fixfileformat.asp
# -2008: http://star.cde.ca.gov/star2008/research_fixfileformat.asp 2007: http://star.cde.ca.gov/star2007/research_fixfileformat.asp
# Link to Github: https://github.com/CRPE-UWB/State
# Notes: -idk what's with the warning messages: "Unknown or uninitialised column: 'ETHNIC'." but it can be ignored
# -For Performance: 2014+2015 will have problems due to lack of info in the dataset
# Setup --------------------------------------------------------------------------------------------------------
rm(list=ls())
setwd("/Users/crpe/Documents/al_ca_clean") #MAC
library(plyr)
library(dplyr)
library(tidyr)
library(data.table)
library(stringr)
library(readxl)
library(readr)
# Demo List --------------------------------------------------------------------------------------------------------
demo_order <- c("CDS_CODE", "COUNTY", "DISTRICT", "SCHOOL", "YEAR", "TOTAL_ENROLL", "TOTAL_MALE", "TOTAL_MALE_PCT",
"TOTAL_FEMALE", "TOTAL_FEMALE_PCT", "AMINDIAN", "AMINDIAN_PCT", "ASIAN", "ASIAN_PCT",
"BLACK", "BLACK_PCT", "FILIPINO", "FILIPINO_PCT", "HISPANIC", "HISPANIC_PCT",
"PACISLAND", "PACISLAND_PCT", "TWOORMORE", "TWOORMORE_PCT", "WHITE", "WHITE_PCT", "NOTREPORTED", "NOTREPORTED_PCT")
demo_order_2 <- c("CDS_CODE", "COUNTY", "DISTRICT", "SCHOOL", "YEAR", "TOTAL_ENROLL", "TOTAL_MALE", "TOTAL_MALE_PCT",
"TOTAL_FEMALE", "TOTAL_FEMALE_PCT", "AMINDIAN", "AMINDIAN_PCT", "ASIAN", "ASIAN_PCT",
"BLACK", "BLACK_PCT", "FILIPINO", "FILIPINO_PCT", "HISPANIC", "HISPANIC_PCT",
"PACISLAND", "PACISLAND_PCT", "TWOORMORE", "TWOORMORE_PCT", "WHITE", "WHITE_PCT")
demo_order_3 <- c("CDS_CODE", "YEAR", "TOTAL_ENROLL", "TOTAL_MALE", "TOTAL_MALE_PCT",
"TOTAL_FEMALE", "TOTAL_FEMALE_PCT", "AMINDIAN", "AMINDIAN_PCT", "ASIAN", "ASIAN_PCT",
"BLACK", "BLACK_PCT", "FILIPINO", "FILIPINO_PCT", "HISPANIC", "HISPANIC_PCT",
"PACISLAND", "PACISLAND_PCT", "TWOORMORE", "TWOORMORE_PCT", "WHITE", "WHITE_PCT")
demo_order_4 <- c("CDS_CODE", "YEAR", "TOTAL_ENROLL", "TOTAL_MALE", "TOTAL_MALE_PCT",
"TOTAL_FEMALE", "TOTAL_FEMALE_PCT", "AMINDIAN", "AMINDIAN_PCT", "ASIAN", "ASIAN_PCT",
"BLACK", "BLACK_PCT", "FILIPINO", "FILIPINO_PCT", "HISPANIC", "HISPANIC_PCT",
"PACISLAND", "PACISLAND_PCT", "WHITE", "WHITE_PCT")
# Perf List --------------------------------------------------------------------------------------------------------
perf_list_16 <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_ENROLL", "TOTAL_TESTED_ENTITY", "TEST_ID", "TOTAL_REPORTED", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "STUDENTS_SCORED")
perf_list_16b <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_ENROLL", "TOTAL_TESTED_ENTITY", "TOTAL_REPORTED", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "STUDENTS_SCORED")
perf_list_1415 <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_TESTED_ENTITY", "TEST_ID", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "FAR_BELOW_BASIC_PCT", "STUDENTS_SCORED")
perf_list_1415b <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_TESTED_ENTITY", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "FAR_BELOW_BASIC_PCT", "STUDENTS_SCORED")
perf_list_0913 <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_ENROLL", "TOTAL_TESTED_ENTITY", "TEST_ID", "TOTAL_REPORTED", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "FAR_BELOW_BASIC_PCT", "STUDENTS_SCORED")
perf_list_0913b <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_ENROLL", "TOTAL_TESTED_ENTITY", "TOTAL_REPORTED", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "FAR_BELOW_BASIC_PCT", "STUDENTS_SCORED")
perf_list_0708 <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_ENROLL", "TOTAL_TESTED_ENTITY", "TEST_ID", "TOTAL_REPORTED", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "FAR_BELOW_BASIC_PCT", "STUDENTS_SCORED")
perf_list_0708b <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TOTAL_ENROLL", "TOTAL_TESTED_ENTITY", "TOTAL_REPORTED", "NUM_STUDENTS_TESTED",
"ADV_PCT", "PROF_PCT", "BASIC_PCT", "BELOW_BASIC_PCT", "FAR_BELOW_BASIC_PCT", "STUDENTS_SCORED")
info_list <- c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR",
"TYPE_ID", "COUNTY_NAME", "DISTRICT_NAME", "SCHOOL_NAME", "ZIP_CODE")
# Function --------------------------------------------------------------------------------------------------------
no_more_special_characters <- function(df_col) {
# need to replace the chracters
require(gsubfn)
# make sure the col is character
df_col <- as.character(df_col)
# list of special characters to replace with
unwanted_array = list( 'Š'='S', 'š'='s', 'Ž'='Z', 'ž'='z', 'À'='A', 'Á'='A', 'Â'='A', 'Ã'='A', 'Ä'='A', 'Å'='A', 'Æ'='A', 'Ç'='C', 'È'='E', 'É'='E',
'Ê'='E', 'Ë'='E', 'Ì'='I', 'Í'='I', 'Î'='I', 'Ï'='I', 'Ñ'='N', 'Ò'='O', 'Ó'='O', 'Ô'='O', 'Õ'='O', 'Ö'='O', 'Ø'='O', 'Ù'='U',
'Ú'='U', 'Û'='U', 'Ü'='U', 'Ý'='Y', 'Þ'='B', 'ß'='Ss', 'à'='a', 'á'='a', 'â'='a', 'ã'='a', 'ä'='a', 'å'='a', 'æ'='a', 'ç'='c',
'è'='e', 'é'='e', 'ê'='e', 'ë'='e', 'ì'='i', 'í'='i', 'î'='i', 'ï'='i', 'ð'='o', 'ñ'='n', 'ò'='o', 'ó'='o', 'ô'='o', 'õ'='o',
'ö'='o', 'ø'='o', 'ù'='u', 'ú'='u', 'û'='u', 'ý'='y', 'ý'='y', 'þ'='b', 'ÿ'='y' )
# replaces the characters
df_col <- gsubfn(paste(names(unwanted_array),collapse='|'), unwanted_array,df_col)
return(df_col)
}
clean_demo_1017 <- function(df) {
# turn all numbers into what they actually are for demographic
df$ETHNIC[df$ETHNIC == 0] <- "NOTREPORTED"
df$ETHNIC[df$ETHNIC == 1] <- "AMINDIAN"
df$ETHNIC[df$ETHNIC == 2] <- "ASIAN"
df$ETHNIC[df$ETHNIC == 3] <- "PACISLAND"
df$ETHNIC[df$ETHNIC == 4] <- "FILIPINO"
df$ETHNIC[df$ETHNIC == 5] <- "HISPANIC"
df$ETHNIC[df$ETHNIC == 6] <- "BLACK"
df$ETHNIC[df$ETHNIC == 7] <- "WHITE"
df$ETHNIC[df$ETHNIC == 9] <- "TWOORMORE"
# combine the ethnic and gender columns
df$ETHNIC <- paste(df$ETHNIC, df$GENDER, sep = "_")
# get rid of not needed columns
df$GENDER <- NULL
df$KDGN <- NULL
df$GR_1 <- NULL
df$GR_2 <- NULL
df$GR_3 <- NULL
df$GR_4 <- NULL
df$GR_5 <- NULL
df$GR_6 <- NULL
df$GR_7 <- NULL
df$GR_8 <- NULL
df$GR_9 <- NULL
df$GR_10 <- NULL
df$GR_11 <- NULL
df$GR_12 <- NULL
df$UNGR_ELM <- NULL
df$UNGR_SEC <- NULL
df$ADULT <- NULL
# Separate by ethnicity
df <-df %>%
spread(ETHNIC, ENR_TOTAL)
# change the NA into 0
df[is.na(df)] <- 0
# create a MALE column
df$TOTAL_MALE <- rowSums(df[,c("AMINDIAN_M", "ASIAN_M", "BLACK_M", "FILIPINO_M", "HISPANIC_M", "NOTREPORTED_M", "PACISLAND_M", "TWOORMORE_M", "WHITE_M")], na.rm = TRUE)
# create a MALE column
df$TOTAL_FEMALE <- rowSums(df[,c("AMINDIAN_F", "ASIAN_F", "BLACK_F", "FILIPINO_F", "HISPANIC_F", "NOTREPORTED_F", "PACISLAND_F", "TWOORMORE_F", "WHITE_F")], na.rm = TRUE)
# create a TOTAL_ENROLL column
df$TOTAL_ENROLL <- rowSums(df[,c("TOTAL_MALE", "TOTAL_FEMALE")], na.rm = TRUE)
# create columns that contain total ethnicity
df$AMINDIAN <- rowSums(df[,c("AMINDIAN_M", "AMINDIAN_F")], na.rm = TRUE)
df$ASIAN <- rowSums(df[,c("ASIAN_M", "ASIAN_F")], na.rm = TRUE)
df$BLACK <- rowSums(df[,c("BLACK_M", "BLACK_F")], na.rm = TRUE)
df$FILIPINO <- rowSums(df[,c("FILIPINO_M", "FILIPINO_F")], na.rm = TRUE)
df$HISPANIC <- rowSums(df[,c("HISPANIC_M", "HISPANIC_F")], na.rm = TRUE)
df$NOTREPORTED <- rowSums(df[,c("NOTREPORTED_M", "NOTREPORTED_F")], na.rm = TRUE)
df$PACISLAND <- rowSums(df[,c("PACISLAND_M", "PACISLAND_F")], na.rm = TRUE)
df$TWOORMORE <- rowSums(df[,c("TWOORMORE_M", "TWOORMORE_F")], na.rm = TRUE)
df$WHITE <- rowSums(df[,c("WHITE_M", "WHITE_F")], na.rm = TRUE)
# get rid of the separated gender columns
df$AMINDIAN_F <- NULL
df$AMINDIAN_M <- NULL
df$ASIAN_F <- NULL
df$ASIAN_M <- NULL
df$BLACK_F <- NULL
df$BLACK_M <- NULL
df$FILIPINO_F <- NULL
df$FILIPINO_M <- NULL
df$HISPANIC_F <- NULL
df$HISPANIC_M <- NULL
df$NOTREPORTED_F <- NULL
df$NOTREPORTED_M <- NULL
df$PACISLAND_F <- NULL
df$PACISLAND_M <- NULL
df$TWOORMORE_F <- NULL
df$TWOORMORE_M <- NULL
df$WHITE_F <- NULL
df$WHITE_M <- NULL
# create a PCT column
df$AMINDIAN_PCT <- round(df$AMINDIAN / df$TOTAL_ENROLL, digits = 3)
df$ASIAN_PCT <- round(df$ASIAN / df$TOTAL_ENROLL, digits = 3)
df$BLACK_PCT <- round(df$BLACK / df$TOTAL_ENROLL, digits = 3)
df$FILIPINO_PCT <- round(df$FILIPINO / df$TOTAL_ENROLL, digits = 3)
df$HISPANIC_PCT <- round(df$HISPANIC / df$TOTAL_ENROLL, digits = 3)
df$NOTREPORTED_PCT <- round(df$NOTREPORTED / df$TOTAL_ENROLL, digits = 3)
df$PACISLAND_PCT <- round(df$PACISLAND / df$TOTAL_ENROLL, digits = 3)
df$TWOORMORE_PCT <- round(df$TWOORMORE / df$TOTAL_ENROLL, digits = 3)
df$WHITE_PCT <- round(df$WHITE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_MALE_PCT <- round(df$TOTAL_MALE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_FEMALE_PCT <- round(df$TOTAL_FEMALE / df$TOTAL_ENROLL, digits = 3)
# gets rid of multiple warnings
df$ETHNIC <- NA
df$ETHNIC <- NULL
# last part of cleaning
df$COUNTY <- no_more_special_characters(df$COUNTY)
df$DISTRICT <- no_more_special_characters(df$DISTRICT)
df$SCHOOL <- no_more_special_characters(df$SCHOOL)
df[df == ','] <- ""
df[df == '~'] <- "-"
df[is.na(df)] <- -99
return(df)
}
clean_demo_0809 <- function(df) {
# turn all numbers into what they actually are for demographic
df$ETHNIC[df$ETHNIC == 1] <- "AMINDIAN"
df$ETHNIC[df$ETHNIC == 2] <- "ASIAN"
df$ETHNIC[df$ETHNIC == 3] <- "PACISLAND"
df$ETHNIC[df$ETHNIC == 4] <- "FILIPINO"
df$ETHNIC[df$ETHNIC == 5] <- "HISPANIC"
df$ETHNIC[df$ETHNIC == 6] <- "BLACK"
df$ETHNIC[df$ETHNIC == 7] <- "WHITE"
df$ETHNIC[df$ETHNIC == 8] <- "TWOORMORE"
# combine the ethnic and gender columns
df$ETHNIC <- paste(df$ETHNIC, df$GENDER, sep = "_")
# get rid of not needed columns
df$GENDER <- NULL
df$KDGN <- NULL
df$GR_1 <- NULL
df$GR_2 <- NULL
df$GR_3 <- NULL
df$GR_4 <- NULL
df$GR_5 <- NULL
df$GR_6 <- NULL
df$GR_7 <- NULL
df$GR_8 <- NULL
df$GR_9 <- NULL
df$GR_10 <- NULL
df$GR_11 <- NULL
df$GR_12 <- NULL
df$UNGR_ELM <- NULL
df$UNGR_SEC <- NULL
df$ADULT <- NULL
# Separate by ethnicity
df <-df %>%
spread(ETHNIC, ENR_TOTAL)
# change the NA into 0
df[is.na(df)] <- 0
# create a MALE column
df$TOTAL_MALE <- rowSums(df[,c("AMINDIAN_M", "ASIAN_M", "BLACK_M", "FILIPINO_M", "HISPANIC_M", "PACISLAND_M", "TWOORMORE_M", "WHITE_M")], na.rm = TRUE)
# create a MALE column
df$TOTAL_FEMALE <- rowSums(df[,c("AMINDIAN_F", "ASIAN_F", "BLACK_F", "FILIPINO_F", "HISPANIC_F", "NOTREPORTED_F", "PACISLAND_F", "TWOORMORE_F", "WHITE_F")], na.rm = TRUE)
# create a TOTAL_ENROLL column
df$TOTAL_ENROLL <- rowSums(df[,c("TOTAL_MALE", "TOTAL_FEMALE")], na.rm = TRUE)
# create columns that contain total ethnicity
df$AMINDIAN <- rowSums(df[,c("AMINDIAN_M", "AMINDIAN_F")], na.rm = TRUE)
df$ASIAN <- rowSums(df[,c("ASIAN_M", "ASIAN_F")], na.rm = TRUE)
df$BLACK <- rowSums(df[,c("BLACK_M", "BLACK_F")], na.rm = TRUE)
df$FILIPINO <- rowSums(df[,c("FILIPINO_M", "FILIPINO_F")], na.rm = TRUE)
df$HISPANIC <- rowSums(df[,c("HISPANIC_M", "HISPANIC_F")], na.rm = TRUE)
df$PACISLAND <- rowSums(df[,c("PACISLAND_M", "PACISLAND_F")], na.rm = TRUE)
df$TWOORMORE <- rowSums(df[,c("TWOORMORE_M", "TWOORMORE_F")], na.rm = TRUE)
df$WHITE <- rowSums(df[,c("WHITE_M", "WHITE_F")], na.rm = TRUE)
# get rid of the separated gender columns
df$AMINDIAN_F <- NULL
df$AMINDIAN_M <- NULL
df$ASIAN_F <- NULL
df$ASIAN_M <- NULL
df$BLACK_F <- NULL
df$BLACK_M <- NULL
df$FILIPINO_F <- NULL
df$FILIPINO_M <- NULL
df$HISPANIC_F <- NULL
df$HISPANIC_M <- NULL
df$PACISLAND_F <- NULL
df$PACISLAND_M <- NULL
df$TWOORMORE_F <- NULL
df$TWOORMORE_M <- NULL
df$WHITE_F <- NULL
df$WHITE_M <- NULL
# create a PCT column
df$AMINDIAN_PCT <- round(df$AMINDIAN / df$TOTAL_ENROLL, digits = 3)
df$ASIAN_PCT <- round(df$ASIAN / df$TOTAL_ENROLL, digits = 3)
df$BLACK_PCT <- round(df$BLACK / df$TOTAL_ENROLL, digits = 3)
df$FILIPINO_PCT <- round(df$FILIPINO / df$TOTAL_ENROLL, digits = 3)
df$HISPANIC_PCT <- round(df$HISPANIC / df$TOTAL_ENROLL, digits = 3)
df$PACISLAND_PCT <- round(df$PACISLAND / df$TOTAL_ENROLL, digits = 3)
df$TWOORMORE_PCT <- round(df$TWOORMORE / df$TOTAL_ENROLL, digits = 3)
df$WHITE_PCT <- round(df$WHITE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_MALE_PCT <- round(df$TOTAL_MALE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_FEMALE_PCT <- round(df$TOTAL_FEMALE / df$TOTAL_ENROLL, digits = 3)
# gets rid of multiple warnings
df$ETHNIC <- NA
df$ETHNIC <- NULL
# last part of cleaning
df$COUNTY <- no_more_special_characters(df$COUNTY)
df$DISTRICT <- no_more_special_characters(df$DISTRICT)
df$SCHOOL <- no_more_special_characters(df$SCHOOL)
df[df == ','] <- ""
df[df == '~'] <- "-"
df[is.na(df)] <- -99
return(df)
}
clean_demo_9907 <- function(df) {
# turn all numbers into what they actually are for demographic
df$ETHNIC[df$ETHNIC == 1] <- "AMINDIAN"
df$ETHNIC[df$ETHNIC == 2] <- "ASIAN"
df$ETHNIC[df$ETHNIC == 3] <- "PACISLAND"
df$ETHNIC[df$ETHNIC == 4] <- "FILIPINO"
df$ETHNIC[df$ETHNIC == 5] <- "HISPANIC"
df$ETHNIC[df$ETHNIC == 6] <- "BLACK"
df$ETHNIC[df$ETHNIC == 7] <- "WHITE"
df$ETHNIC[df$ETHNIC == 8] <- "TWOORMORE"
# combine the ethnic and gender columns
df$ETHNIC <- paste(df$ETHNIC, df$GENDER, sep = "_")
# get rid of not needed columns
df$GENDER <- NULL
df$KDGN <- NULL
df$GR_1 <- NULL
df$GR_2 <- NULL
df$GR_3 <- NULL
df$GR_4 <- NULL
df$GR_5 <- NULL
df$GR_6 <- NULL
df$GR_7 <- NULL
df$GR_8 <- NULL
df$GR_9 <- NULL
df$GR_10 <- NULL
df$GR_11 <- NULL
df$GR_12 <- NULL
df$UNGR_ELM <- NULL
df$UNGR_SEC <- NULL
df$ADULT <- NULL
# Separate by ethnicity
df <-df %>%
spread(ETHNIC, ENR_TOTAL)
# change the NA into 0
df[is.na(df)] <- 0
# create a MALE column
df$TOTAL_MALE <- rowSums(df[,c("AMINDIAN_M", "ASIAN_M", "BLACK_M", "FILIPINO_M", "HISPANIC_M", "PACISLAND_M", "TWOORMORE_M", "WHITE_M")], na.rm = TRUE)
# create a MALE column
df$TOTAL_FEMALE <- rowSums(df[,c("AMINDIAN_F", "ASIAN_F", "BLACK_F", "FILIPINO_F", "HISPANIC_F", "PACISLAND_F", "TWOORMORE_F", "WHITE_F")], na.rm = TRUE)
# create a TOTAL_ENROLL column
df$TOTAL_ENROLL <- rowSums(df[,c("TOTAL_MALE", "TOTAL_FEMALE")], na.rm = TRUE)
# create columns that contain total ethnicity
df$AMINDIAN <- rowSums(df[,c("AMINDIAN_M", "AMINDIAN_F")], na.rm = TRUE)
df$ASIAN <- rowSums(df[,c("ASIAN_M", "ASIAN_F")], na.rm = TRUE)
df$BLACK <- rowSums(df[,c("BLACK_M", "BLACK_F")], na.rm = TRUE)
df$FILIPINO <- rowSums(df[,c("FILIPINO_M", "FILIPINO_F")], na.rm = TRUE)
df$HISPANIC <- rowSums(df[,c("HISPANIC_M", "HISPANIC_F")], na.rm = TRUE)
df$PACISLAND <- rowSums(df[,c("PACISLAND_M", "PACISLAND_F")], na.rm = TRUE)
df$TWOORMORE <- rowSums(df[,c("TWOORMORE_M", "TWOORMORE_F")], na.rm = TRUE)
df$WHITE <- rowSums(df[,c("WHITE_M", "WHITE_F")], na.rm = TRUE)
# get rid of the separated gender columns
df$AMINDIAN_F <- NULL
df$AMINDIAN_M <- NULL
df$ASIAN_F <- NULL
df$ASIAN_M <- NULL
df$BLACK_F <- NULL
df$BLACK_M <- NULL
df$FILIPINO_F <- NULL
df$FILIPINO_M <- NULL
df$HISPANIC_F <- NULL
df$HISPANIC_M <- NULL
df$PACISLAND_F <- NULL
df$PACISLAND_M <- NULL
df$TWOORMORE_F <- NULL
df$TWOORMORE_M <- NULL
df$WHITE_F <- NULL
df$WHITE_M <- NULL
# create a PCT column
df$AMINDIAN_PCT <- round(df$AMINDIAN / df$TOTAL_ENROLL, digits = 3)
df$ASIAN_PCT <- round(df$ASIAN / df$TOTAL_ENROLL, digits = 3)
df$BLACK_PCT <- round(df$BLACK / df$TOTAL_ENROLL, digits = 3)
df$FILIPINO_PCT <- round(df$FILIPINO / df$TOTAL_ENROLL, digits = 3)
df$HISPANIC_PCT <- round(df$HISPANIC / df$TOTAL_ENROLL, digits = 3)
df$PACISLAND_PCT <- round(df$PACISLAND / df$TOTAL_ENROLL, digits = 3)
df$TWOORMORE_PCT <- round(df$TWOORMORE / df$TOTAL_ENROLL, digits = 3)
df$WHITE_PCT <- round(df$WHITE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_MALE_PCT <- round(df$TOTAL_MALE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_FEMALE_PCT <- round(df$TOTAL_FEMALE / df$TOTAL_ENROLL, digits = 3)
# gets rid of multiple warnings
df$ETHNIC <- NA
df$ETHNIC <- NULL
# last part of cleaning
df[df == ','] <- ""
df[df == '~'] <- "-"
df[is.na(df)] <- -99
return(df)
}
clean_demo_9498 <- function(df) {
# turn all numbers into what they actually are for demographic
df$ETHNIC[df$ETHNIC == 1] <- "AMINDIAN"
df$ETHNIC[df$ETHNIC == 2] <- "ASIAN"
df$ETHNIC[df$ETHNIC == 3] <- "PACISLAND"
df$ETHNIC[df$ETHNIC == 4] <- "FILIPINO"
df$ETHNIC[df$ETHNIC == 5] <- "HISPANIC"
df$ETHNIC[df$ETHNIC == 6] <- "BLACK"
df$ETHNIC[df$ETHNIC == 7] <- "WHITE"
# combine the ethnic and gender columns
df$ETHNIC <- paste(df$ETHNIC, df$GENDER, sep = "_")
# get rid of not needed columns
df$GENDER <- NULL
df$KDGN <- NULL
df$GR_1 <- NULL
df$GR_2 <- NULL
df$GR_3 <- NULL
df$GR_4 <- NULL
df$GR_5 <- NULL
df$GR_6 <- NULL
df$GR_7 <- NULL
df$GR_8 <- NULL
df$GR_9 <- NULL
df$GR_10 <- NULL
df$GR_11 <- NULL
df$GR_12 <- NULL
df$UNGR_ELM <- NULL
df$UNGR_SEC <- NULL
df$ADULT <- NULL
# Separate by ethnicity
df <-df %>%
spread(ETHNIC, ENR_TOTAL)
# change the NA into 0
df[is.na(df)] <- 0
# create a MALE column
df$TOTAL_MALE <- rowSums(df[,c("AMINDIAN_M", "ASIAN_M", "BLACK_M", "FILIPINO_M", "HISPANIC_M", "PACISLAND_M", "WHITE_M")], na.rm = TRUE)
# create a MALE column
df$TOTAL_FEMALE <- rowSums(df[,c("AMINDIAN_F", "ASIAN_F", "BLACK_F", "FILIPINO_F", "HISPANIC_F", "PACISLAND_F", "WHITE_F")], na.rm = TRUE)
# create a TOTAL_ENROLL column
df$TOTAL_ENROLL <- rowSums(df[,c("TOTAL_MALE", "TOTAL_FEMALE")], na.rm = TRUE)
# create columns that contain total ethnicity
df$AMINDIAN <- rowSums(df[,c("AMINDIAN_M", "AMINDIAN_F")], na.rm = TRUE)
df$ASIAN <- rowSums(df[,c("ASIAN_M", "ASIAN_F")], na.rm = TRUE)
df$BLACK <- rowSums(df[,c("BLACK_M", "BLACK_F")], na.rm = TRUE)
df$FILIPINO <- rowSums(df[,c("FILIPINO_M", "FILIPINO_F")], na.rm = TRUE)
df$HISPANIC <- rowSums(df[,c("HISPANIC_M", "HISPANIC_F")], na.rm = TRUE)
df$PACISLAND <- rowSums(df[,c("PACISLAND_M", "PACISLAND_F")], na.rm = TRUE)
df$WHITE <- rowSums(df[,c("WHITE_M", "WHITE_F")], na.rm = TRUE)
# get rid of the separated gender columns
df$AMINDIAN_F <- NULL
df$AMINDIAN_M <- NULL
df$ASIAN_F <- NULL
df$ASIAN_M <- NULL
df$BLACK_F <- NULL
df$BLACK_M <- NULL
df$FILIPINO_F <- NULL
df$FILIPINO_M <- NULL
df$HISPANIC_F <- NULL
df$HISPANIC_M <- NULL
df$PACISLAND_F <- NULL
df$PACISLAND_M <- NULL
df$WHITE_F <- NULL
df$WHITE_M <- NULL
# create a PCT column
df$AMINDIAN_PCT <- round(df$AMINDIAN / df$TOTAL_ENROLL, digits = 3)
df$ASIAN_PCT <- round(df$ASIAN / df$TOTAL_ENROLL, digits = 3)
df$BLACK_PCT <- round(df$BLACK / df$TOTAL_ENROLL, digits = 3)
df$FILIPINO_PCT <- round(df$FILIPINO / df$TOTAL_ENROLL, digits = 3)
df$HISPANIC_PCT <- round(df$HISPANIC / df$TOTAL_ENROLL, digits = 3)
df$PACISLAND_PCT <- round(df$PACISLAND / df$TOTAL_ENROLL, digits = 3)
df$WHITE_PCT <- round(df$WHITE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_MALE_PCT <- round(df$TOTAL_MALE / df$TOTAL_ENROLL, digits = 3)
df$TOTAL_FEMALE_PCT <- round(df$TOTAL_FEMALE / df$TOTAL_ENROLL, digits = 3)
# gets rid of multiple warnings
df$ETHNIC <- NA
df$ETHNIC <- NULL
# last part of cleaning
df[df == ','] <- ""
df[df == '~'] <- "-"
df[is.na(df)] <- -99
return(df)
}
add_info <- function(df_info, df_perf) {
#change column names
colnames(df_info) <- info_list
# don't include statewide
df_info <- df_info %>%
filter(COUNTY_CODE != '00')
# include only schools and charters
# don't include statewide
df_info <- df_info %>%
filter(TYPE_ID == c(7,9,10))
# make sure columns are character
df_info$COUNTY_NAME <- as.character(df_info$COUNTY_NAME)
df_info$DISTRICT_NAME <- as.character(df_info$DISTRICT_NAME)
df_info$SCHOOL_NAME <- as.character(df_info$SCHOOL_NAME)
# change TYPE_ID for df_info
df_info$TYPE_ID[df_info$TYPE_ID == 7] <- 'SCHOOL'
df_info$TYPE_ID[df_info$TYPE_ID == 9] <- 'DIRECT FUNDED CHARTER'
df_info$TYPE_ID[df_info$TYPE_ID == 10] <- 'LOCALLY FUNDED CHARTER'
df_info[df_info == ','] <- ""
df_info[df_info == '~'] <- "-"
# merge it with data_perf
df_perf <- inner_join(df_info, df_perf, by=c("COUNTY_CODE", "DISTRICT_CODE", "SCHOOL_CODE", "CHARTER_NUM", "YEAR"))
return(df_perf)
}
# Read in Each Dataset --------------------------------------------------------------------------------------------------------
# dataset: performance
data_perf_16 <- read_csv("data/sb_ca2016_1_csv_v3.txt")
# dataset: info
data_info_16 <- read_csv("data/sb_ca2016entities_csv.txt")
# dataset: performance
data_perf_15 <- read_csv("data/ca2015_1_csv_v3.txt")
# dataset: info
data_info_15 <- read_csv("data/ca2015entities_csv.txt")
# dataset: performance
data_perf_14 <- read_csv("data/ca2014_1_csv_v2.txt")
# dataset: info
data_info_14 <- read_csv("data/ca2014entities_csv.txt")
# dataset: performance
data_perf_13 <- read_csv("data/ca2013_1_csv_v3.txt")
# dataset: info
data_info_13 <- read_csv("data/ca2013entities_csv.txt")
# dataset: performance
data_perf_12 <- read_csv("data/ca2012_1_csv_v3.txt")
# dataset: info
data_info_12 <- read_csv("data/ca2012entities_csv.txt")
# dataset: performance
data_perf_11 <- read_csv("data/ca2011_1_csv_v3.txt")
# dataset: info
data_info_11 <- read_csv("data/ca2011entities_csv.txt")
# dataset: performance
data_perf_10 <- read_csv("data/ca2010_1_csv_v3.txt")
# dataset: info
data_info_10 <- read_csv("data/ca2010entities_csv.txt")
# dataset: performance
data_perf_09 <- read_csv("data/ca2009_1_csv_v3.txt")
# dataset: info
data_info_09 <- read_csv("data/ca2009entities_csv.txt")
# dataset: performance
data_perf_08 <- read_csv("data/ca2008_1_csv_v3.txt")
# dataset: info
data_info_08 <- read_csv("data/ca2008entities_csv.txt")
# dataset: performance
data_perf_07 <- read_csv("data/CA2007_1_CSV_v3.txt")
# dataset: info
data_info_07 <- read_csv("data/CA2007Entities_CSV.txt")
# dataset: demographics
data_demo_17 <- read_tsv("data/enroll_2017.txt")
# dataset: demographics
data_demo_16 <- read_tsv("data/enroll_2016.txt")
# dataset: demographics
data_demo_15 <- read_tsv("data/enroll_2015.txt")
# dataset: demographics
data_demo_14 <- read_tsv("data/enroll_2014.txt")
# dataset: demographics
data_demo_13 <- read_tsv("data/enroll_2013.txt")
# dataset: demographics
data_demo_12 <- read_tsv("data/enroll_2012.txt")
# dataset: demographics
data_demo_11 <- read_tsv("data/enroll_2011.txt")
# dataset: demographics
data_demo_10 <- read_tsv("data/enroll_2010.txt")
# dataset: demographics
data_demo_09 <- read_tsv("data/enroll_2009.txt")
# dataset: demographics
data_demo_08 <- read_tsv("data/enroll_2008.txt")
# dataset: demographics
data_demo_07 <- read_tsv("data/enroll_2007.txt")
# dataset: demographics
data_demo_06 <- read_tsv("data/enroll_2006.txt")
# dataset: demographics
data_demo_05 <- read_tsv("data/enroll_2005.txt")
# dataset: demographics
data_demo_04 <- read_tsv("data/enroll_2004.txt")
# dataset: demographics
data_demo_03 <- read_tsv("data/enroll_2003.txt")
# dataset: demographics
data_demo_02 <- read_tsv("data/enroll_2002.txt")
# dataset: demographics
data_demo_01 <- read_tsv("data/enroll_2001.txt")
# dataset: demographics
data_demo_00 <- read_tsv("data/enroll_2000.txt")
# dataset: demographics
data_demo_99 <- read_tsv("data/enroll_1999.txt")
# dataset: demographics
data_demo_98 <- read_tsv("data/enroll_1998.txt")
# dataset: demographics
data_demo_97 <- read_tsv("data/enroll_1997.txt")
# dataset: demographics
data_demo_96 <- read_tsv("data/enroll_1996.txt")
# dataset: demographics
data_demo_95 <- read_tsv("data/enroll_1995.txt")
# dataset: demographics
data_demo_94 <- read_tsv("data/enroll_1994.txt")
# Performance --------------------------------------------------------------------------------------------------------
# 2015-2016 -----
# keep wanted columns
data_perf_16 <- data_perf_16 %>%
select(c("County Code", "District Code", "School Code", "Filler", "Test Year", "Total CAASPP Enrollment",
"Total Tested At Entity Level", "Test Id", "CAASPP Reported Enrollment", "Students Tested", "Percentage Standard Exceeded",
"Percentage Standard Met", "Percentage Standard Nearly Met", "Percentage Standard Not Met",
"Students with Scores"))
# change column names
colnames(data_perf_16) <- perf_list_16
# turn * into NA
data_perf_16[data_perf_16 == "*"] <- NA
data_perf_16[data_perf_16 == "-Inf"] <- NA
# get rid of statewide rows
data_perf_16 <- data_perf_16 %>%
filter(COUNTY_CODE != '00')
# make sure its numeric
data_perf_16$TOTAL_ENROLL <- as.numeric(data_perf_16$TOTAL_ENROLL)
data_perf_16$TOTAL_TESTED_ENTITY <- as.numeric(data_perf_16$TOTAL_TESTED_ENTITY)
data_perf_16$TOTAL_REPORTED <- as.numeric(data_perf_16$TOTAL_REPORTED)
data_perf_16$NUM_STUDENTS_TESTED <- as.numeric(data_perf_16$NUM_STUDENTS_TESTED)
data_perf_16$ADV_PCT <- as.numeric(data_perf_16$ADV_PCT)
data_perf_16$PROF_PCT <- as.numeric(data_perf_16$PROF_PCT)
data_perf_16$BASIC_PCT <- as.numeric(data_perf_16$BASIC_PCT)
data_perf_16$BELOW_BASIC_PCT <- as.numeric(data_perf_16$BELOW_BASIC_PCT)
data_perf_16$STUDENTS_SCORED <- as.numeric(data_perf_16$STUDENTS_SCORED)
# create the math columns
data_perf_16_m <- data_perf_16 %>%
filter(TEST_ID == 2)
# get rid of TEST_ID
data_perf_16_m$TEST_ID <- NULL
# combine rows of school together
data_perf_16_m <- data_perf_16_m %>%
group_by_("COUNTY_CODE","DISTRICT_CODE","SCHOOL_CODE","CHARTER_NUM","YEAR") %>%
summarise(max(TOTAL_ENROLL, na.rm = TRUE),max(TOTAL_TESTED_ENTITY, na.rm = TRUE), max(TOTAL_REPORTED, na.rm = TRUE),
max(NUM_STUDENTS_TESTED, na.rm = TRUE), mean(ADV_PCT, na.rm = TRUE), mean(PROF_PCT, na.rm = TRUE),
mean(BASIC_PCT, na.rm = TRUE), mean(BELOW_BASIC_PCT, na.rm = TRUE),
max(STUDENTS_SCORED, na.rm = TRUE))
# change column names (again)
colnames(data_perf_16_m) <- perf_list_16b
# turn NaN to NAs
data_perf_16_m[data_perf_16_m == 'NaN'] <- NA
# round the PCT columns
data_perf_16_m$ADV_PCT <- round(data_perf_16_m$ADV_PCT, digits = 3)
data_perf_16_m$PROF_PCT <- round(data_perf_16_m$PROF_PCT, digits = 3)
data_perf_16_m$BASIC_PCT <- round(data_perf_16_m$BASIC_PCT, digits = 3)
data_perf_16_m$BELOW_BASIC_PCT <- round(data_perf_16_m$BELOW_BASIC_PCT, digits = 3)
# add MATH_ in columns' names
for (i in 6:ncol(data_perf_16_m)) {
colnames(data_perf_16_m)[i] <- paste('MATH', colnames(data_perf_16_m)[i], sep="_")
next
}
# create the ela columns
data_perf_16_e <- data_perf_16 %>%
filter(TEST_ID == 1)
# get rid of TEST_ID
data_perf_16_e$TEST_ID <- NULL
# combine rows of school together
data_perf_16_e <- data_perf_16_e %>%
group_by_("COUNTY_CODE","DISTRICT_CODE","SCHOOL_CODE","CHARTER_NUM","YEAR") %>%
summarise(max(TOTAL_ENROLL, na.rm = TRUE),max(TOTAL_TESTED_ENTITY, na.rm = TRUE), max(TOTAL_REPORTED, na.rm = TRUE),
max(NUM_STUDENTS_TESTED, na.rm = TRUE), mean(ADV_PCT, na.rm = TRUE), mean(PROF_PCT, na.rm = TRUE),
mean(BASIC_PCT, na.rm = TRUE), mean(BELOW_BASIC_PCT, na.rm = TRUE),
max(STUDENTS_SCORED, na.rm = TRUE))
# change column names (again)
colnames(data_perf_16_e) <- perf_list_16b
# turn NaN to NAs
data_perf_16_e[data_perf_16_e == 'NaN'] <- NA
# round the PCT columns
data_perf_16_e$ADV_PCT <- round(data_perf_16_e$ADV_PCT, digits = 3)
data_perf_16_e$PROF_PCT <- round(data_perf_16_e$PROF_PCT, digits = 3)
data_perf_16_e$BASIC_PCT <- round(data_perf_16_e$BASIC_PCT, digits = 3)
data_perf_16_e$BELOW_BASIC_PCT <- round(data_perf_16_e$BELOW_BASIC_PCT, digits = 3)
# add ELA_ in columns' names
for (i in 6:ncol(data_perf_16_e)) {
colnames(data_perf_16_e)[i] <- paste('ELA', colnames(data_perf_16_e)[i], sep="_")
next
}
# combine the math and ela datasets
data_perf_16 <- full_join(data_perf_16_m, data_perf_16_e)
# add info
data_perf_16 <- add_info(data_info_16, data_perf_16)
# last clean
data_perf_16[data_perf_16 == ","] <- ""
data_perf_16[data_perf_16 == "~"] <- "-"
data_perf_16[data_perf_16 == "ñ"] <- "n"
data_perf_16[data_perf_16 == "é"] <- "e"
data_perf_16[is.na(data_perf_16)] <- -99
# write .csv file
write.csv(data_perf_16, "cleaned_data/ca_perf_2016.csv", row.names = FALSE)
# 2014-2015 -----
# keep wanted columns
data_perf_15 <- data_perf_15 %>%
select(c("County Code", "District Code", "School Code", "filler", "Test Year",
"Total Tested At Entity Level", "Test Id", "Students Tested", "Percentage Advanced",
"Percentage Proficient", "Percentage Basic", "Percentage Below Basic", "Percentage Far Below Basic",
"Students with Scores"))
# change column names
colnames(data_perf_15) <- perf_list_1415
# turn * into NA
data_perf_15[data_perf_15 == "*"] <- NA
data_perf_15[data_perf_15 == "-Inf"] <- NA
# get rid of statewide rows
data_perf_15 <- data_perf_15 %>%
filter(COUNTY_CODE != '00')
# create the ela columns
data_perf_15 <- data_perf_15 %>%
filter(TEST_ID == 38)
# get rid of TEST_ID
data_perf_15$TEST_ID <- NULL
# combine rows of school together
data_perf_15 <- data_perf_15 %>%
group_by_("COUNTY_CODE","DISTRICT_CODE","SCHOOL_CODE","CHARTER_NUM","YEAR") %>%
summarise(max(TOTAL_TESTED_ENTITY, na.rm = TRUE),
max(NUM_STUDENTS_TESTED, na.rm = TRUE), mean(ADV_PCT, na.rm = TRUE), mean(PROF_PCT, na.rm = TRUE),
mean(BASIC_PCT, na.rm = TRUE), mean(BELOW_BASIC_PCT, na.rm = TRUE),
mean(FAR_BELOW_BASIC_PCT, na.rm = TRUE), max(STUDENTS_SCORED, na.rm = TRUE))
# change column names (again)
colnames(data_perf_15) <- perf_list_1415b
# turn NaN to NAs
data_perf_15[data_perf_15 == 'NaN'] <- NA
# round the PCT columns
data_perf_15$ADV_PCT <- round(data_perf_15$ADV_PCT, digits = 3)
data_perf_15$PROF_PCT <- round(data_perf_15$PROF_PCT, digits = 3)
data_perf_15$BASIC_PCT <- round(data_perf_15$BASIC_PCT, digits = 3)
data_perf_15$BELOW_BASIC_PCT <- round(data_perf_15$BELOW_BASIC_PCT, digits = 3)
data_perf_15$FAR_BELOW_BASIC_PCT <- round(data_perf_15$FAR_BELOW_BASIC_PCT, digits = 3)
# add ELA_ in columns' names
for (i in 6:ncol(data_perf_15)) {
colnames(data_perf_15)[i] <- paste('ELA', colnames(data_perf_15)[i], sep="_")
next
}
# add info
data_perf_15 <- add_info(data_info_15, data_perf_15)
# last clean
data_perf_15[data_perf_15 == ","] <- ""
data_perf_15[data_perf_15 == "~"] <- "-"
data_perf_15[data_perf_15 == "ñ"] <- "n"
data_perf_15[data_perf_15 == "é"] <- "e"
data_perf_15[is.na(data_perf_15)] <- -99
# merge them
data_perf <- full_join(data_perf_16, data_perf_15)
# write .csv file
write.csv(data_perf_15, "cleaned_data/ca_perf_2015.csv", row.names = FALSE)
# 2013-2014 -----
# keep wanted columns
data_perf_14 <- data_perf_14 %>%
select(c("County Code", "District Code", "School Code", "Charter Number", "Test Year",
"Total Tested At Entity Level", "Test Id", "Students Tested", "Percentage Advanced",
"Percentage Proficient", "Percentage Basic", "Percentage Below Basic", "Percentage Far Below Basic",
"Students with Scores"))
# change column names
colnames(data_perf_14) <- perf_list_1415
# turn * into NA
data_perf_14[data_perf_14 == "*"] <- NA
data_perf_14[data_perf_14 == "-Inf"] <- NA
# get rid of statewide rows
data_perf_14 <- data_perf_14 %>%
filter(COUNTY_CODE != '00')
# make sure its numeric
data_perf_14$TOTAL_TESTED_ENTITY <- as.numeric(data_perf_14$TOTAL_TESTED_ENTITY)
data_perf_14$NUM_STUDENTS_TESTED <- as.numeric(data_perf_14$NUM_STUDENTS_TESTED)
data_perf_14$ADV_PCT <- as.numeric(data_perf_14$ADV_PCT)
data_perf_14$PROF_PCT <- as.numeric(data_perf_14$PROF_PCT)
data_perf_14$BASIC_PCT <- as.numeric(data_perf_14$BASIC_PCT)
data_perf_14$BELOW_BASIC_PCT <- as.numeric(data_perf_14$BELOW_BASIC_PCT)
data_perf_14$FAR_BELOW_BASIC_PCT <- as.numeric(data_perf_14$FAR_BELOW_BASIC_PCT)
data_perf_14$STUDENTS_SCORED <- as.numeric(data_perf_14$STUDENTS_SCORED)
# create the math columns
data_perf_14_m <- data_perf_14 %>%
filter(TEST_ID == 31)
# get rid of TEST_ID
data_perf_14_m$TEST_ID <- NULL
# combine rows of school together
data_perf_14_m <- data_perf_14_m %>%
group_by_("COUNTY_CODE","DISTRICT_CODE","SCHOOL_CODE","CHARTER_NUM","YEAR") %>%
summarise(max(TOTAL_TESTED_ENTITY, na.rm = TRUE),
max(NUM_STUDENTS_TESTED, na.rm = TRUE), mean(ADV_PCT, na.rm = TRUE), mean(PROF_PCT, na.rm = TRUE),
mean(BASIC_PCT, na.rm = TRUE), mean(BELOW_BASIC_PCT, na.rm = TRUE),
mean(FAR_BELOW_BASIC_PCT, na.rm = TRUE), max(STUDENTS_SCORED, na.rm = TRUE))
# change column names (again)
colnames(data_perf_14_m) <- perf_list_1415b
# turn NaN to NAs
data_perf_14_m[data_perf_14_m == 'NaN'] <- NA
# round the PCT columns
data_perf_14_m$ADV_PCT <- round(data_perf_14_m$ADV_PCT, digits = 3)
data_perf_14_m$PROF_PCT <- round(data_perf_14_m$PROF_PCT, digits = 3)
data_perf_14_m$BASIC_PCT <- round(data_perf_14_m$BASIC_PCT, digits = 3)
data_perf_14_m$BELOW_BASIC_PCT <- round(data_perf_14_m$BELOW_BASIC_PCT, digits = 3)
data_perf_14_m$FAR_BELOW_BASIC_PCT <- round(data_perf_14_m$FAR_BELOW_BASIC_PCT, digits = 3)
# add MATH_ in columns' names
for (i in 6:ncol(data_perf_14_m)) {
colnames(data_perf_14_m)[i] <- paste('MATH', colnames(data_perf_14_m)[i], sep="_")
next
}
# create the ela columns
data_perf_14_e <- data_perf_14 %>%
filter(TEST_ID == c(30,38))
# get rid of TEST_ID
data_perf_14_e$TEST_ID <- NULL
# combine rows of school together
data_perf_14_e <- data_perf_14_e %>%
group_by_("COUNTY_CODE","DISTRICT_CODE","SCHOOL_CODE","CHARTER_NUM","YEAR") %>%
summarise(max(TOTAL_TESTED_ENTITY, na.rm = TRUE),
max(NUM_STUDENTS_TESTED, na.rm = TRUE), mean(ADV_PCT, na.rm = TRUE), mean(PROF_PCT, na.rm = TRUE),
mean(BASIC_PCT, na.rm = TRUE), mean(BELOW_BASIC_PCT, na.rm = TRUE),
mean(FAR_BELOW_BASIC_PCT, na.rm = TRUE), max(STUDENTS_SCORED, na.rm = TRUE))
# change column names (again)
colnames(data_perf_14_e) <- perf_list_1415b
# turn NaN to NAs
data_perf_14_e[data_perf_14_e == 'NaN'] <- NA
# round the PCT columns
data_perf_14_e$ADV_PCT <- round(data_perf_14_e$ADV_PCT, digits = 3)
data_perf_14_e$PROF_PCT <- round(data_perf_14_e$PROF_PCT, digits = 3)
data_perf_14_e$BASIC_PCT <- round(data_perf_14_e$BASIC_PCT, digits = 3)
data_perf_14_e$BELOW_BASIC_PCT <- round(data_perf_14_e$BELOW_BASIC_PCT, digits = 3)
data_perf_14_e$FAR_BELOW_BASIC_PCT <- round(data_perf_14_e$FAR_BELOW_BASIC_PCT, digits = 3)
# add ELA_ in columns' names
for (i in 6:ncol(data_perf_14_e)) {
colnames(data_perf_14_e)[i] <- paste('ELA', colnames(data_perf_14_e)[i], sep="_")
next
}
# combine the math and ela datasets
data_perf_14 <- full_join(data_perf_14_m, data_perf_14_e)
# add info
data_perf_14 <- add_info(data_info_14, data_perf_14)
# last clean
data_perf_14[data_perf_14 == ","] <- ""
data_perf_14[data_perf_14 == "~"] <- "-"
data_perf_14[data_perf_14 == "ñ"] <- "n"
data_perf_14[data_perf_14 == "é"] <- "e"
data_perf_14[is.na(data_perf_14)] <- -99
# merge them
data_perf <- full_join(data_perf, data_perf_14)
# write .csv file
write.csv(data_perf_14, "cleaned_data/ca_perf_2014.csv", row.names = FALSE)
# 2012-2013 -----
# keep wanted columns
data_perf_13 <- data_perf_13 %>%
select(c("County Code", "District Code", "School Code", "Charter Number", "Test Year", "Total STAR Enrollment",
"Total Tested At Entity Level", "Test Id", "STAR Reported Enrollment/CAPA Eligible", "Students Tested", "Percentage Advanced",
"Percentage Proficient", "Percentage Basic", "Percentage Below Basic", "Percentage Far Below Basic",
"Students with Scores"))
# change column names
colnames(data_perf_13) <- perf_list_0913
# turn * into NA
data_perf_13[data_perf_13 == "*"] <- NA
data_perf_13[data_perf_13 == "-Inf"] <- NA
# get rid of statewide rows
data_perf_13 <- data_perf_13 %>%
filter(COUNTY_CODE != '00')
# make sure its numeric
data_perf_13$TOTAL_ENROLL <- as.numeric(data_perf_13$TOTAL_ENROLL)
data_perf_13$TOTAL_TESTED_ENTITY <- as.numeric(data_perf_13$TOTAL_TESTED_ENTITY)
data_perf_13$TOTAL_REPORTED <- as.numeric(data_perf_13$TOTAL_REPORTED)
data_perf_13$NUM_STUDENTS_TESTED <- as.numeric(data_perf_13$NUM_STUDENTS_TESTED)
data_perf_13$ADV_PCT <- as.numeric(data_perf_13$ADV_PCT)
data_perf_13$PROF_PCT <- as.numeric(data_perf_13$PROF_PCT)
data_perf_13$BASIC_PCT <- as.numeric(data_perf_13$BASIC_PCT)
data_perf_13$BELOW_BASIC_PCT <- as.numeric(data_perf_13$BELOW_BASIC_PCT)
data_perf_13$FAR_BELOW_BASIC_PCT <- as.numeric(data_perf_13$FAR_BELOW_BASIC_PCT)
data_perf_13$STUDENTS_SCORED <- as.numeric(data_perf_13$STUDENTS_SCORED)
# create the math columns
data_perf_13_m <- data_perf_13 %>%
filter(TEST_ID == c(8,9,10,11,12,13,14,15,28,31,39,45,47,48,49,50))
# get rid of TEST_ID
data_perf_13_m$TEST_ID <- NULL
# combine rows of school together
data_perf_13_m <- data_perf_13_m %>%
group_by_("COUNTY_CODE","DISTRICT_CODE","SCHOOL_CODE","CHARTER_NUM","YEAR") %>%
summarise(max(TOTAL_ENROLL, na.rm = TRUE),max(TOTAL_TESTED_ENTITY, na.rm = TRUE), max(TOTAL_REPORTED, na.rm = TRUE),
max(NUM_STUDENTS_TESTED, na.rm = TRUE), mean(ADV_PCT, na.rm = TRUE), mean(PROF_PCT, na.rm = TRUE),
mean(BASIC_PCT, na.rm = TRUE), mean(BELOW_BASIC_PCT, na.rm = TRUE),
mean(FAR_BELOW_BASIC_PCT, na.rm = TRUE), max(STUDENTS_SCORED, na.rm = TRUE))
# change column names (again)
colnames(data_perf_13_m) <- perf_list_0913b
# turn NaN to NAs
data_perf_13_m[data_perf_13_m == 'NaN'] <- NA
# round the PCT columns
data_perf_13_m$ADV_PCT <- round(data_perf_13_m$ADV_PCT, digits = 3)
data_perf_13_m$PROF_PCT <- round(data_perf_13_m$PROF_PCT, digits = 3)
data_perf_13_m$BASIC_PCT <- round(data_perf_13_m$BASIC_PCT, digits = 3)
data_perf_13_m$BELOW_BASIC_PCT <- round(data_perf_13_m$BELOW_BASIC_PCT, digits = 3)
data_perf_13_m$FAR_BELOW_BASIC_PCT <- round(data_perf_13_m$FAR_BELOW_BASIC_PCT, digits = 3)
# add MATH_ in columns' names
for (i in 6:ncol(data_perf_13_m)) {
colnames(data_perf_13_m)[i] <- paste('MATH', colnames(data_perf_13_m)[i], sep="_")
next
}
# create the ela columns
data_perf_13_e <- data_perf_13 %>%
filter(TEST_ID == c(7,30,38,44))
# get rid of TEST_ID
data_perf_13_e$TEST_ID <- NULL
# combine rows of school together
data_perf_13_e <- data_perf_13_e %>%
group_by_("COUNTY_CODE","DISTRICT_CODE","SCHOOL_CODE","CHARTER_NUM","YEAR") %>%
summarise(max(TOTAL_ENROLL, na.rm = TRUE),max(TOTAL_TESTED_ENTITY, na.rm = TRUE), max(TOTAL_REPORTED, na.rm = TRUE),
max(NUM_STUDENTS_TESTED, na.rm = TRUE), mean(ADV_PCT, na.rm = TRUE), mean(PROF_PCT, na.rm = TRUE),
mean(BASIC_PCT, na.rm = TRUE), mean(BELOW_BASIC_PCT, na.rm = TRUE),
mean(FAR_BELOW_BASIC_PCT, na.rm = TRUE), max(STUDENTS_SCORED, na.rm = TRUE))
# change column names (again)
colnames(data_perf_13_e) <- perf_list_0913b
# turn NaN to NAs
data_perf_13_e[data_perf_13_e == 'NaN'] <- NA
# round the PCT columns
data_perf_13_e$ADV_PCT <- round(data_perf_13_e$ADV_PCT, digits = 3)
data_perf_13_e$PROF_PCT <- round(data_perf_13_e$PROF_PCT, digits = 3)
data_perf_13_e$BASIC_PCT <- round(data_perf_13_e$BASIC_PCT, digits = 3)
data_perf_13_e$BELOW_BASIC_PCT <- round(data_perf_13_e$BELOW_BASIC_PCT, digits = 3)
data_perf_13_e$FAR_BELOW_BASIC_PCT <- round(data_perf_13_e$FAR_BELOW_BASIC_PCT, digits = 3)
# add ELA_ in columns' names
for (i in 6:ncol(data_perf_13_e)) {
colnames(data_perf_13_e)[i] <- paste('ELA', colnames(data_perf_13_e)[i], sep="_")
next
}
# combine the math and ela datasets
data_perf_13 <- full_join(data_perf_13_m, data_perf_13_e)
# add info
data_perf_13 <- add_info(data_info_13, data_perf_13)
# last clean
data_perf_13[data_perf_13 == ","] <- ""
data_perf_13[data_perf_13 == "~"] <- "-"
data_perf_13[data_perf_13 == "ñ"] <- "n"
data_perf_13[data_perf_13 == "é"] <- "e"
data_perf_13[is.na(data_perf_13)] <- -99
# merge them
data_perf <- full_join(data_perf, data_perf_13)
# write .csv file
write.csv(data_perf_13, "cleaned_data/ca_perf_2013.csv", row.names = FALSE)
# 2011-2012 -----
# keep wanted columns
data_perf_12 <- data_perf_12 %>%
select(c("County Code", "District Code", "School Code", "Charter Number", "Test Year", "Total STAR Enrollment",