R-code master1

 ### R Scripts to generate all tables and charts for Asian challenge  
 ### to Harvard affirmative action race-based admissions   
 ### ... Scripts should be executed in order  
 ###   master1.R ==> master2.R ==> master3.R ==> master4.R  
 ###   
 ### User must change the "home" variable to point to the folder/directory  
 ###   PROJECTS/PROJECT-AFFIRMATIVE-ACTION-LEGAL-CHALLENGE/ folder/directory   
 ### on his/her computer  
 #  
 ### A. Set the working directory, load required libraries, and   
 ### read IPEDS-raw.csv and IPEDS-raw-others.csv data  
 #  
 rm(list = ls()) ### clear the environment  
 # home <- "blah/blah-blah/.../blah-blah-blah/SIX-YEAR-GRAD-RATES/"   
 home <- "/blah-blah...blah-blah/PROJECT-AFFIRMATIVE-ACTION-LEGAL-CHALLENGE/"  
 setwd(home)  
 #  
 ### Developed using R = version 3.5.1 and R Studio = version 1.456  
 ### install.packages("tidyverse")  
 library(tidyverse)  
   
 #  
 ### Read IPEDS as tibble, not dataframe   
 ### ... Use tibbles throughout ... Most things are better with tibbles,   
 ### ... but there are, sometimes,   
 ### ... "The Trouble with Tibbles" ... :-)  
 ###   
 ### Code generates tables and charts for each of the   
 ### 21 private institutions = Black 6-year 5 percent 50 group + Cal Tech  
 #  
 dtIPEDS_raw <- read_csv("IPEDS-raw.csv")  
 # Ignore the warning message about unnamed variable now called "X219"   
 dtIPEDS_raw <- select(dtIPEDS_raw, -c(X219))  
 #glimpse(dtIPEDS_raw)  
   
 ### The next file was added while writing the final sections of the report  
 ### when it became clear that hours spent wrangling this data into shape  
 ### then integrating it into the previous data would enable the production  
 ### of a more concise, and, hopefully, more persuasive analysis  
 dtIPEDS_Others_raw <- read_csv("IPEDS-raw-others.csv")  
 # Ignore the warning message about unnamed variable now called "X126"  
 dtIPEDS_Others_raw <- select(dtIPEDS_Others_raw, -c(X126))  
 #glimpse(dtIPEDS_Others_raw)  
 #  
 prepTable_0 <- function(dt){  
   ### Reads raw IPEDS data, renames variables, calculates misc other stuff,   
   ### returns master tibble ...   
   #  
   dt <- dt %>%  
     # Rename IPEDS variables to user friendly names  
     rename(institution = `Institution Name`,   
         totalGrads16 = `Grand total (C2016_A_RV First major Grand total Bachelor's degree)`,   
         asianGrads16 = `Asian total (C2016_A_RV First major Grand total Bachelor's degree)`,                                         blackGrads16 = `Black or African American total (C2016_A_RV First major Grand total Bachelor's degree)`,   
         hispanicGrads16 = `Hispanic or Latino total (C2016_A_RV First major Grand total Bachelor's degree)` ,  
         whiteGrads16 = `White total (C2016_A_RV First major Grand total Bachelor's degree)`,   
         #  
         totalGradsAgriculture16 = `Grand total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,   
         asianGradsAgriculture16 = `Asian total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,   
         blackGradsAgriculture16 = `Black or African American total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,  
         hispanicGradsAgriculture16 = `Hispanic or Latino total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,   
         whiteGradsAgriculture16 = `White total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,    
         #  
         totalGradsNaturalResourcesConservation16 = `Grand total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)`,  
         asianGradsNaturalResourcesConservation16 = `Asian total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)`,   
         blackGradsNaturalResourcesConservation16 = `Black or African American total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)`,   
         hispanicGradsNaturalResourcesConservation16 = `Hispanic or Latino total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)`,   
         whiteGradsNaturalResourcesConservation16 = `White total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)`,   
         #     
         totalGradsArchitecture16 = `Grand total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,   
         asianGradsArchitecture16 = `Asian total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,   
         blackGradsArchitecture16 = `Black or African American total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,  
         hispanicGradsArchitecture16 = `Hispanic or Latino total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,   
         whiteGradsArchitecture16 = `White total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,   
         #      
         totalGradsAreaEthnicCulturalGenderGroup16 = `Grand total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)`,   
         asianGradsAreaEthnicCulturalGenderGroup16 = `Asian total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)`,  
         blackGradsAreaEthnicCulturalGenderGroup16 = `Black or African American total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)`,   
         hispanicGradsAreaEthnicCulturalGenderGroup16 = `Hispanic or Latino total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)`,   
         whiteGradsAreaEthnicCulturalGenderGroup16 = `White total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)`,   
         #  
         totalGradsCommunicationJournalism16 = `Grand total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,   
         asianGradsCommunicationJournalism16 = `Asian total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,   
         blackGradsCommunicationJournalism16 = `Black or African American total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,   
         hispanicGradsCommunicationJournalism16 = `Hispanic or Latino total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,    
         whiteGradsCommunicationJournalism16 = `White total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,   
         #   
         totalGradsCommunicationsTechnologies16 = `Grand total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,  
         asianGradsCommunicationsTechnologies16 = `Asian total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,  
         blackGradsCommunicationsTechnologies16 = `Black or African American total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,   
         hispanicGradsCommunicationsTechnologies16 = `Hispanic or Latino total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,   
         whiteGradsCommunicationsTechnologies16 = `White total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,    
         #  
         totalGradsComputerInformationSciences16 = `Grand total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,   
         asianGradsComputerInformationSciences16 = `Asian total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,   
         blackGradsComputerInformationSciences16 = `Black or African American total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,  
         hispanicGradsComputerInformationSciences16 = `Hispanic or Latino total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,  
         whiteGradsComputerInformationSciences16 = `White total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,   
         #  
         totalGradsPersonalCulinaryServices16 = `Grand total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,   
         asianGradsPersonalCulinaryServices16 = `Asian total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,   
         blackGradsPersonalCulinaryServices16 = `Black or African American total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,   
         hispanicGradsPersonalCulinaryServices16 = `Hispanic or Latino total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,   
         whiteGradsPersonalCulinaryServices16 = `White total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,  
         #  
         totalGradsEducation16 = `Grand total (C2016_A_RV First major Education Bachelor's degree)`,   
         asianGradsEducation16 = `Asian total (C2016_A_RV First major Education Bachelor's degree)`,    
         blackGradsEducation16 = `Black or African American total (C2016_A_RV First major Education Bachelor's degree)`,   
         hispanicGradsEducation16 = `Hispanic or Latino total (C2016_A_RV First major Education Bachelor's degree)`,  
         whiteGradsEducation16 = `White total (C2016_A_RV First major Education Bachelor's degree)`,  
         #  
         totalGradsEngineering16 = `Grand total (C2016_A_RV First major Engineering Bachelor's degree)`,     
         asianGradsEngineering16 = `Asian total (C2016_A_RV First major Engineering Bachelor's degree)`,   
         blackGradsEngineering16 = `Black or African American total (C2016_A_RV First major Engineering Bachelor's degree)`,   
         hispanicGradsEngineering16 = `Hispanic or Latino total (C2016_A_RV First major Engineering Bachelor's degree)`,   
         whiteGradsEngineering16 = `White total (C2016_A_RV First major Engineering Bachelor's degree)`,   
         #  
         totalGradsEngineeringTechnologies16 = `Grand total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,   
         asianGradsEngineeringTechnologies16 = `Asian total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,  
         blackGradsEngineeringTechnologies16 = `Black or African American total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,   
         hispanicGradsEngineeringTechnologies16 = `Hispanic or Latino total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,  
         whiteGradsEngineeringTechnologies16 = `White total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,  
         #  
         totalGradsForeignLanguagesLiteraturesLinguistics16 = `Grand total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,  
         asianGradsForeignLanguagesLiteraturesLinguistics16 = `Asian total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,  
         blackGradsForeignLanguagesLiteraturesLinguistics16 = `Black or African American total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,  
         hispanicGradsForeignLanguagesLiteraturesLinguistics16 = `Hispanic or Latino total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,  
         whiteGradsForeignLanguagesLiteraturesLinguistics16 = `White total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,   
         #  
         totalGradsFamilyConsumerSciences16 = `Grand total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,   
         asianGradsFamilyConsumerSciences16 = `Asian total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,   
         blackGradsFamilyConsumerSciences16 = `Black or African American total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,  
         hispanicGradsFamilyConsumerSciences16 = `Hispanic or Latino total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,  
         whiteGradsFamilyConsumerSciences16 = `White total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,   
         #  
         totalGradsLegalProfessionsStudies16 = `Grand total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,  
         asianGradsLegalProfessionsStudies16 = `Asian total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,  
         blackGradsLegalProfessionsStudies16 = `Black or African American total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,   
         hispanicGradsLegalProfessionsStudies16 = `Hispanic or Latino total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,  
         whiteGradsLegalProfessionsStudies16 = `White total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,   
         #  
         totalGradsEnglishLanguageLiterature16 = `Grand total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,   
         asianGradsEnglishLanguageLiterature16 = `Asian total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,    
         blackGradsEnglishLanguageLiterature16 = `Black or African American total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,   
         hispanicGradsEnglishLanguageLiterature16 = `Hispanic or Latino total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,  
         whiteGradsEnglishLanguageLiterature16 = `White total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,    
         #  
         totalGradsLiberalArtsSciencesGeneralStudies16 = `Grand total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)`,   
         asianGradsLiberalArtsSciencesGeneralStudies16 = `Asian total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)`,   
         blackGradsLiberalArtsSciencesGeneralStudies16 = `Black or African American total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)`,   
         hispanicGradsLiberalArtsSciencesGeneralStudies16 = `Hispanic or Latino total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)`,  
         whiteGradsLiberalArtsSciencesGeneralStudies16 = `White total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)`,   
         #  
         totalGradsLibraryScience16 = `Grand total (C2016_A_RV First major Library Science Bachelor's degree)`,  
         asianGradsLibraryScience16 = `Asian total (C2016_A_RV First major Library Science Bachelor's degree)`,  
         blackGradsLibraryScience16 = `Black or African American total (C2016_A_RV First major Library Science Bachelor's degree)`,  
         hispanicGradsLibraryScience16 = `Hispanic or Latino total (C2016_A_RV First major Library Science Bachelor's degree)`,   
         whiteGradsLibraryScience16 = `White total (C2016_A_RV First major Library Science Bachelor's degree)`,   
         #  
         totalGradsBiologicalBiomedicalSciences16 = `Grand total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)`,   
         asianGradsBiologicalBiomedicalSciences16 = `Asian total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)`,   
         blackGradsBiologicalBiomedicalSciences16 = `Black or African American total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)`,    
         hispanicGradsBiologicalBiomedicalSciences16 = `Hispanic or Latino total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)`,   
         whiteGradsBiologicalBiomedicalSciences16 = `White total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)`,  
         #      
         totalGradsMathematicsStatistics16 = `Grand total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,   
         asianGradsMathematicsStatistics16 = `Asian total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,   
         blackGradsMathematicsStatistics16 = `Black or African American total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,   
         hispanicGradsMathematicsStatistics16 = `Hispanic or Latino total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,   
         whiteGradsMathematicsStatistics16 = `White total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,  
         #   
         totalGradsMilitaryTechnologiesAppliedSciences16 = `Grand total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)`,   
         asianGradsMilitaryTechnologiesAppliedSciences16 = `Asian total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)`,   
         blackGradsMilitaryTechnologiesAppliedSciences16 = `Black or African American total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)`,  
         hispanicGradsMilitaryTechnologiesAppliedSciences16 = `Hispanic or Latino total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)`,   
         whiteGradsMilitaryTechnologiesAppliedSciences16 = `White total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)`,  
         #   
         #      
         totalGradsMultiInterdisciplinaryStudies16 = `Grand total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,   
         asianGradsMultiInterdisciplinaryStudies16 = `Asian total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,  
         blackGradsMultiInterdisciplinaryStudies16 = `Black or African American total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,  
         hispanicGradsMultiInterdisciplinaryStudies16 = `Hispanic or Latino total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,   
         whiteGradsMultiInterdisciplinaryStudies16 = `White total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,  
         #      
         totalGradsParksRecreationLeisureFitnessStudies16 = `Grand total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)`,   
         asianGradsParksRecreationLeisureFitnessStudies16 = `Asian total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)`,  
         blackGradsParksRecreationLeisureFitnessStudies16 = `Black or African American total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)`,  
         hispanicGradsParksRecreationLeisureFitnessStudies16 = `Hispanic or Latino total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)`,   
         whiteGradsParksRecreationLeisureFitnessStudies16 = `White total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)`,   
         #  
         totalGradsPhilosophyReligiousStudies16 = `Grand total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,  
         asianGradsPhilosophyReligiousStudies16 = `Asian total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,   
         blackGradsPhilosophyReligiousStudies16 = `Black or African American total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,   
         hispanicGradsPhilosophyReligiousStudies16 = `Hispanic or Latino total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,  
         whiteGradsPhilosophyReligiousStudies16 = `White total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,   
         #  
         totalGradsTheologyReligiousVocations16 = `Grand total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,   
         asianGradsTheologyReligiousVocations16 = `Asian total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,  
         blackGradsTheologyReligiousVocations16 = `Black or African American total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,  
         hispanicGradsTheologyReligiousVocations16 = `Hispanic or Latino total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,   
         whiteGradsTheologyReligiousVocations16 = `White total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,   
         #  
         totalGradsPhysicalSciences16 = `Grand total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,   
         asianGradsPhysicalSciences16 = `Asian total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,  
         blackGradsPhysicalSciences16 = `Black or African American total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,    
         hispanicGradsPhysicalSciences16 = `Hispanic or Latino total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,   
         whiteGradsPhysicalSciences16 = `White total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,  
         #  
         totalGradsScienceTechnologiesTechnicians16 = `Grand total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,   
         asianGradsScienceTechnologiesTechnicians16 = `Asian total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,   
         blackGradsScienceTechnologiesTechnicians16 = `Black or African American total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,   
         hispanicGradsScienceTechnologiesTechnicians16 = `Hispanic or Latino total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,   
         whiteGradsScienceTechnologiesTechnicians16 = `White total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,   
         #  
         totalGradsPsychology16 = `Grand total (C2016_A_RV First major Psychology Bachelor's degree)`,   
         asianGradsPsychology16 = `Asian total (C2016_A_RV First major Psychology Bachelor's degree)`,   
         blackGradsPsychology16 = `Black or African American total (C2016_A_RV First major Psychology Bachelor's degree)`,   
         hispanicGradsPsychology16 = `Hispanic or Latino total (C2016_A_RV First major Psychology Bachelor's degree)`,   
         whiteGradsPsychology16 = `White total (C2016_A_RV First major Psychology Bachelor's degree)`,  
         #      
         totaGradslHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `Grand total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,   
         asianGradsHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `Asian total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,  
         blackGradsHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `Black or African American total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,  
         hispanicGradsHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `Hispanic or Latino total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,  
         whiteGradsHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `White total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,  
         #  
         totalGradsPublicAdministrationSocialService16 = `Grand total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)`,   
         asianGradsPublicAdministrationSocialService16 = `Asian total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)`,   
         blackGradsPublicAdministrationSocialService16 = `Black or African American total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)`,  
         hispanicGradsPublicAdministrationSocialService16 = `Hispanic or Latino total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)`,  
         whiteGradsPublicAdministrationSocialService16 = `White total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)`,       
         #                    <int> ...  
         totalGradsSocialSciences16 = `Grand total (C2016_A_RV First major Social Sciences Bachelor's degree)`,   
         asianGradsSocialSciences16 = `Asian total (C2016_A_RV First major Social Sciences Bachelor's degree)`,   
         blackGradsSocialSciences16 = `Black or African American total (C2016_A_RV First major Social Sciences Bachelor's degree)`,  
         hispanicGradsSocialSciences16 = `Hispanic or Latino total (C2016_A_RV First major Social Sciences Bachelor's degree)`,   
         whiteGradsSocialSciences16 = `White total (C2016_A_RV First major Social Sciences Bachelor's degree)`,   
         #  
         totalGradsConstructionTrades16 = `Grand total (C2016_A_RV First major Construction Trades Bachelor's degree)`,   
         asianGradsConstructionTrades16 = `Asian total (C2016_A_RV First major Construction Trades Bachelor's degree)`,   
         blackGradsConstructionTrades16 = `Black or African American total (C2016_A_RV First major Construction Trades Bachelor's degree)`,   
         hispanicGradsConstructionTrades16 = `Hispanic or Latino total (C2016_A_RV First major Construction Trades Bachelor's degree)`,  
         whiteGradsConstructionTrades16 = `White total (C2016_A_RV First major Construction Trades Bachelor's degree)`,   
         #  
         totalGradsMechanicRepairTechnologiesTechnicians16 = `Grand total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)`,   
         asianGradsMechanicRepairTechnologiesTechnicians16 = `Asian total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)`,   
         blackGradsMechanicRepairTechnologiesTechnicians16 = `Black or African American total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)`,   
         hispanicGradsMechanicRepairTechnologiesTechnicians16 = `Hispanic or Latino total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)`,  
         whiteGradsMechanicRepairTechnologiesTechnicians16 = `White total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)`,   
         #  
         totalGradsPrecisionProduction16 = `Grand total (C2016_A_RV First major Precision Production Bachelor's degree)`,   
         asianGradsPrecisionProduction16 = `Asian total (C2016_A_RV First major Precision Production Bachelor's degree)`,   
         blackGradsPrecisionProduction16 = `Black or African American total (C2016_A_RV First major Precision Production Bachelor's degree)`,   
         hispanicGradsPrecisionProduction16 = `Hispanic or Latino total (C2016_A_RV First major Precision Production Bachelor's degree)`,  
         whiteGradsPrecisionProduction16 = `White total (C2016_A_RV First major Precision Production Bachelor's degree)`,   
         #  
         totalGradsTransportationMaterialsMoving16 = `Grand total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,  
         asianGradsTransportationMaterialsMoving16 = `Asian total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,    
         blackGradsTransportationMaterialsMoving16 = `Black or African American total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,  
         hispanicGradsTransportationMaterialsMoving16 = `Hispanic or Latino total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,   
         whiteGradsTransportationMaterialsMoving16 = `White total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,   
         #  
         totalGradsVisualPerformingArts16 = `Grand total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)`,   
         asianGradsVisualPerformingArts16 = `Asian total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)`,  
         blackGradsVisualPerformingArts16 = `Black or African American total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)`,  
         hispanicGradsVisualPerformingArts16 = `Hispanic or Latino total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)`,   
         whiteGradsVisualPerformingArts16 = `White total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)`,   
         #      
         totalGradsHealthProfessionsRelatedPrograms16 = `Grand total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,   
         asianGradsHealthProfessionsRelatedPrograms16 = `Asian total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,  
         blackGradsHealthProfessionsRelatedPrograms16 = `Black or African American total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,  
         hispanicGradsHealthProfessionsRelatedPrograms16 = `Hispanic or Latino total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,   
         whiteGradsHealthProfessionsRelatedPrograms16 = `White total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,   
         #  
         totalGradsBusinessManagementMarketing16 = `Grand total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,  
         asianGradsBusinessManagementMarketing16 = `Asian total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,  
         blackGradsBusinessManagementMarketing16 = `Black or African American total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,  
         hispanicGradsBusinessManagementMarketing16 = `Hispanic or Latino total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,  
         whiteGradsBusinessManagementMarketing16 = `White total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,   
         #  
         totalGradsHistory16 = `Grand total (C2016_A_RV First major History Bachelor's degree)`,   
         asianGradsHistory16 = `Asian total (C2016_A_RV First major History Bachelor's degree)`,   
         blackGradsHistory16 = `Black or African American total (C2016_A_RV First major History Bachelor's degree)`,  
         hispanicGradsHistory16 = `Hispanic or Latino total (C2016_A_RV First major History Bachelor's degree)`,   
         whiteGradsHistory16 = `White total (C2016_A_RV First major History Bachelor's degree)`,      
         #    
         totalGradsEconomics16 = `Grand total (C2016_A_RV First major Economics Bachelor's degree)`,  
         asianGradsEconomics16 = `Asian total (C2016_A_RV First major Economics Bachelor's degree)`,  
         blackGradsEconomics16 = `Black or African American total (C2016_A_RV First major Economics Bachelor's degree)`,  
         hispanicGradsEconomics16 = `Hispanic or Latino total (C2016_A_RV First major Economics Bachelor's degree)`,  
         whiteGradsEconomics16 = `White total (C2016_A_RV First major Economics Bachelor's degree)`,  
         #  
         totalGradsPoliticalScience16 = `Grand total (C2016_A_RV First major Political Science and Government Bachelor's degree)`,   
         blackGradsPoliticalScience16 = `Black or African American total (C2016_A_RV First major Political Science and Government Bachelor's degree)`,   
         asianGradsPoliticalScience16 = `Asian total (C2016_A_RV First major Political Science and Government Bachelor's degree)`,   
         hispanicGradsPoliticalScience16 = `Hispanic or Latino total (C2016_A_RV First major Political Science and Government Bachelor's degree)`,   
         whiteGradsPoliticalScience16 = `White total (C2016_A_RV First major Political Science and Government Bachelor's degree)`,  
         #  
         ##### Expand IPEDS download to include every racial group + M25  
         totalEnroll15 = `Grand total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,   
         asianEnroll15 = `Asian total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,   
         blackEnroll15 = `Black or African American total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)` ,  
         hispanicEnroll15 = `Hispanic total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,    
         whiteEnroll15 = `White total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,  
         twoOrMoreRacesEnroll15 = `Two or more races total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,   
         UnknownEnroll15 = `Race/ethnicity unknown total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,   
         nonResAlienEnroll15 = `Nonresident alien total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,   
         natHawPacIsleEnroll15 = `Native Hawaiian or Other Pacific Islander total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,              
         AmIndAlaNatEnroll15 = `American Indian or Alaska Native total (EF2015A_RV Full-time students Undergraduate Degree/certificate-seeking First-time)`,  
         M25th15 = `SAT Math 25th percentile score (ADM2015_RV)`) %>%  
     #  
     mutate(totalGradsSocialSciencesWithoutEconPoli16 =   
           totalGradsSocialSciences16 -   
           (totalGradsEconomics16 + totalGradsPoliticalScience16),  
         asianGradsSocialSciencesWithoutEconPoli16 =   
           asianGradsSocialSciences16 -  
           (asianGradsEconomics16 + asianGradsPoliticalScience16),  
         blackGradsSocialSciencesWithoutEconPoli16 =   
           blackGradsSocialSciences16 -  
           (blackGradsEconomics16 + blackGradsPoliticalScience16),  
         hispanicGradsSocialSciencesWithoutEconPoli16 =   
           hispanicGradsSocialSciences16 -  
           (hispanicGradsEconomics16 + hispanicGradsPoliticalScience16),  
         whiteGradsSocialSciencesWithoutEconPoli16 =   
           whiteGradsSocialSciences16 -  
           (whiteGradsEconomics16 + whiteGradsPoliticalScience16)) %>%  
     #   
     select(-c(totalGradsSocialSciences16, asianGradsSocialSciences16,  
          blackGradsSocialSciences16, hispanicGradsSocialSciences16,  
          whiteGradsSocialSciences16))    
   #  
   return(dt)  
 }  
 #  
 prepTableOthers_0 <- function(dt){##  
 ### Reads raw IPEDS data for some other variables,  
 ### resident alien, unknown, and two or more races   
 ### renames variables, calculates misc other stuff  
   #  
   dt <- dt %>%  
     # Rename IPEDS variables to user friendly names  
     rename(institution = `Institution Name`,   
   # 42  
     twoOrMoreRacesGrads16 = `Two or more races total (C2016_A_RV First major Bachelor's degree Grand total)`,                             
     unknownGrads16 = `Race/ethnicity unknown total (C2016_A_RV First major Bachelor's degree Grand total)`,                           
     nonResAlienGrads16 = `Nonresident alien total (C2016_A_RV First major Bachelor's degree Grand total)`,    
   #1  
       twoOrMoreRacesGradsAgriculture16 = `Two or more races total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,  
       unknownGradsAgriculture16 = `Race/ethnicity unknown total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,  
       nonResAlienGradsAgriculture16 = `Nonresident alien total (C2016_A_RV First major Agriculture Agriculture Operations and Related Sciences Bachelor's degree)`,    
   #2  
   twoOrMoreRacesGradsNaturalResourcesConservation16 = `Two or more races total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)`,  
   unknownGradsNaturalResourcesConservation16 = `Race/ethnicity unknown total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)` ,  
   nonResAlienGradsNaturalResourcesConservation16 = `Nonresident alien total (C2016_A_RV First major Natural Resources and Conservation Bachelor's degree)`,   
   #3  
   twoOrMoreRacesGradsArchitecture16 = `Two or more races total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,   
   unknownGradsArchitecture16 = `Race/ethnicity unknown total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,   
   nonResAlienGradsArchitecture16 = `Nonresident alien total (C2016_A_RV First major Architecture and Related Services Bachelor's degree)`,  
   #4  
   twoOrMoreRacesGradsAreaEthnicCulturalGenderGroup16 = `Two or more races total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)`,                    
   unknownGradsAreaEthnicCulturalGenderGroup16 = `Race/ethnicity unknown total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)` ,   
   nonResAlienGradsAreaEthnicCulturalGenderGroup16 = `Nonresident alien total (C2016_A_RV First major Area Ethnic Cultural Gender and Group Studies Bachelor's degree)`,     #5  
   twoOrMoreRacesGradsCommunicationJournalism16 = `Two or more races total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,   
   unknownGradsCommunicationJournalism16 = `Race/ethnicity unknown total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,  
   nonResAlienGradsCommunicationJournalism16 = `Nonresident alien total (C2016_A_RV First major Communication Journalism and Related Programs Bachelor's degree)`,   
   #6  
   twoOrMoreRacesGradsCommunicationsTechnologies16 = `Two or more races total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,       
   unknownGradsCommunicationsTechnologies16 = `Race/ethnicity unknown total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,        
   nonResAlienGradsCommunicationsTechnologies16 = `Nonresident alien total (C2016_A_RV First major Communications Technologies/Technicians and Support Services Bachelor's degree)`,    
   #7   
   twoOrMoreRacesGradsComputerInformationSciences16 = `Two or more races total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,      
   unknownGradsComputerInformationSciences16 = `Race/ethnicity unknown total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,  
   nonResAlienGradsComputerInformationSciences16 = `Nonresident alien total (C2016_A_RV First major Computer and Information Sciences and Support Services Bachelor's degree)`,   
   #8  
   twoOrMoreRacesGradsPersonalCulinaryServices16 = `Two or more races total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,  
   unknownRacesGradsPersonalCulinaryServices16 = `Race/ethnicity unknown total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,  
   nonResAlienGradsPersonalCulinaryServices16 = `Nonresident alien total (C2016_A_RV First major Personal and Culinary Services Bachelor's degree)`,  
   #9  
   twoOrMoreRacesGradsEducation16 = `Two or more races total (C2016_A_RV First major Education Bachelor's degree)`,   
   unknownGradsEducation16 = `Race/ethnicity unknown total (C2016_A_RV First major Education Bachelor's degree)`,   
   nonResAlienGradsEducation16 = `Nonresident alien total (C2016_A_RV First major Education Bachelor's degree)`,  
   #10  
   twoOrMoreRacesGradsEngineering16 = `Two or more races total (C2016_A_RV First major Engineering Bachelor's degree)`,    
   unknownGradsEngineering16 = `Race/ethnicity unknown total (C2016_A_RV First major Engineering Bachelor's degree)`,   
   nonResAlienGradsEngineering16 = `Nonresident alien total (C2016_A_RV First major Engineering Bachelor's degree)`,  
   #11  
   twoOrMoreRacesGradsEngineeringTechnologies16 =`Two or more races total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,      unknownGradsEngineeringTechnologies16 = `Race/ethnicity unknown total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,  
   nonResAlienGradsEngineeringTechnologies16 = `Nonresident alien total (C2016_A_RV First major Engineering Technologies and Engineering-related Fields Bachelor's degree)`,  
   #12  
   twoOrMoreRacesGradsForeignLanguagesLiteraturesLinguistics16 = `Two or more races total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,           
   unknownGradsForeignLanguagesLiteraturesLinguistics16 = `Race/ethnicity unknown total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,     
   nonResAlienGradsForeignLanguagesLiteraturesLinguistics16 = `Nonresident alien total (C2016_A_RV First major Foreign Languages Literatures and Linguistics Bachelor's degree)`,    
   #13  
   twoOrMoreRacesGradsFamilyConsumerSciences16 = `Two or more races total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,   
   unknownGradsFamilyConsumerSciences16 = `Race/ethnicity unknown total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,   
   nonResAlienGradsFamilyConsumerSciences16 = `Nonresident alien total (C2016_A_RV First major Family and Consumer Sciences/Human Sciences Bachelor's degree)`,   
   #14  
   twoOrMoreRacesGradsLegalProfessionsStudies16 = `Two or more races total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,   
   unknownGradsLegalProfessionsStudies16 = `Race/ethnicity unknown total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,     
   nonResAlienGradsLegalProfessionsStudies16 = `Nonresident alien total (C2016_A_RV First major Legal Professions and Studies Bachelor's degree)`,  
   #15  
   twoOrMoreRacesGradsEnglishLanguageLiterature16 = `Two or more races total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,   
   unknownGradsEnglishLanguageLiterature16 = `Race/ethnicity unknown total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,   
   nonResAlienGradsEnglishLanguageLiterature16 = `Nonresident alien total (C2016_A_RV First major English Language and Literature/Letters Bachelor's degree)`,  
   #16  
   twoOrMoreRacesGradsLiberalArtsSciencesGeneralStudies16 = `Two or more races total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)` ,    
   unknownGradsLiberalArtsSciencesGeneralStudies16 = `Race/ethnicity unknown total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)` ,     
   nonResAlienGradsLiberalArtsSciencesGeneralStudies16 = `Nonresident alien total (C2016_A_RV First major Liberal Arts and Sciences General Studies and Humanities Bachelor's degree)` ,    
   # 17  
   twoOrMoreRacesGradsLibraryScience16 = `Two or more races total (C2016_A_RV First major Library Science Bachelor's degree)`,   
   unknownGradsLibraryScience16 = `Race/ethnicity unknown total (C2016_A_RV First major Library Science Bachelor's degree)`,  
   nonResAlienGradsLibraryScience16 = `Nonresident alien total (C2016_A_RV First major Library Science Bachelor's degree)`,   
   #  
   #18  
   twoOrMoreRacesGradsBiologicalBiomedicalSciences16 = `Two or more races total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)` ,  
   unknownGradsBiologicalBiomedicalSciences16 = `Race/ethnicity unknown total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)`,   
   nonResAlienGradsBiologicalBiomedicalSciences16 = `Nonresident alien total (C2016_A_RV First major Biological and Biomedical Sciences Bachelor's degree)`,   
   #  
   #19  
   twoOrMoreRacesGradsMathematicsStatistics16 = `Two or more races total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,    
   unknownGradsMathematicsStatistics16 = `Race/ethnicity unknown total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,   
   nonResAlienGradsMathematicsStatistics16 = `Nonresident alien total (C2016_A_RV First major Mathematics and Statistics Bachelor's degree)`,   
   #20  
   twoOrMoreRacesGradsMilitaryTechnologiesAppliedSciences16 = `Two or more races total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)` ,               
   unknownGradsMilitaryTechnologiesAppliedSciences16 = `Race/ethnicity unknown total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)`,             
   nonResAlienGradsMilitaryTechnologiesAppliedSciences16 = `Nonresident alien total (C2016_A_RV First major Military Technologies and Applied Sciences Bachelor's degree)` ,  
   #  
   #21  
   twoOrMoreRacesGradsMultiInterdisciplinaryStudies16 = `Two or more races total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,   
   unknownGradsMultiInterdisciplinaryStudies16 = `Race/ethnicity unknown total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,   
   nonResAlienGradsMultiInterdisciplinaryStudies16 = `Nonresident alien total (C2016_A_RV First major Multi/Interdisciplinary Studies Bachelor's degree)`,    
  #  
  #22  
   twoOrMoreRacesGradsParksRecreationLeisureFitnessStudies16 = `Two or more races total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)`,          
   unknownGradsParksRecreationLeisureFitnessStudies16 =`Race/ethnicity unknown total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)` ,        
   nonResAlienGradsParksRecreationLeisureFitnessStudies16 = `Nonresident alien total (C2016_A_RV First major Parks Recreation Leisure and Fitness Studies Bachelor's degree)`,  
   #  
   #23  
   twoOrMoreRacesGradsPhilosophyReligiousStudies16 = `Two or more races total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,    
   unknownGradsPhilosophyReligiousStudies16 = `Race/ethnicity unknown total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,    
   nonResAlienGradsPhilosophyReligiousStudies16 = `Nonresident alien total (C2016_A_RV First major Philosophy and Religious Studies Bachelor's degree)`,   
   #  
   # 24  
   twoOrMoreRacesGradsTheologyReligiousVocations16 = `Two or more races total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,   
   unknownGradsTheologyReligiousVocations16 = `Race/ethnicity unknown total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,   
   nonResAlienGradsGradsTheologyReligiousVocations16 = `Nonresident alien total (C2016_A_RV First major Theology and Religious Vocations Bachelor's degree)`,  
   #25  
   twoOrMoreRacesGradsPhysicalSciences16 = `Two or more races total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,    
   unknownGradsPhysicalSciences16 = `Race/ethnicity unknown total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,    
   nonResAlienGradsPhysicalSciences16 = `Nonresident alien total (C2016_A_RV First major Physical Sciences Bachelor's degree)`,        
   # 26  
  twoOrMoreRacesGradsScienceTechnologiesTechnicians16 = `Two or more races total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,  
  unknownGradsScienceTechnologiesTechnicians16 = `Race/ethnicity unknown total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,  
  nonResAlienGradsScienceTechnologiesTechnicians16 = `Nonresident alien total (C2016_A_RV First major Science Technologies/Technicians Bachelor's degree)`,  
   #27  
  twoOrMoreRacesGradsPsychology16 = `Two or more races total (C2016_A_RV First major Psychology Bachelor's degree)`,   
   unknownGradsPsychology16 = `Race/ethnicity unknown total (C2016_A_RV First major Psychology Bachelor's degree)`,  
  nonResAlienGradsPsychology16 = `Nonresident alien total (C2016_A_RV First major Psychology Bachelor's degree)` ,  
   #29   
   twoOrMoreRacesGradsPublicAdministrationSocialService16 = `Two or more races total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)` ,        
   unknownGradsPublicAdministrationSocialService16 = `Race/ethnicity unknown total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)` ,      
   nonResAlienGradsPublicAdministrationSocialService16 = `Nonresident alien total (C2016_A_RV First major Public Administration and Social Service Professions Bachelor's degree)`,  
   #30  
   twoOrMoreRacesGradsConstructionTrades16 = `Two or more races total (C2016_A_RV First major Construction Trades Bachelor's degree)` ,   
   unknownGradsConstructionTrades16 = `Race/ethnicity unknown total (C2016_A_RV First major Construction Trades Bachelor's degree)` ,   
   nonResAlienGradsConstructionTrades16 = `Nonresident alien total (C2016_A_RV First major Construction Trades Bachelor's degree)`,   
   #31  
   twoOrMoreRacesGradsMechanicRepairTechnologiesTechnicians16 = `Two or more races total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)`,  
   unknownGradsMechanicRepairTechnologiesTechnicians16 = `Race/ethnicity unknown total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)` ,   
   nonResAlienGradsMechanicRepairTechnologiesTechnicians16 = `Nonresident alien total (C2016_A_RV First major Mechanic and Repair Technologies/Technicians Bachelor's degree)` ,   
   #32  
   twoOrMoreRacesGradsPrecisionProduction16 = `Two or more races total (C2016_A_RV First major Precision Production Bachelor's degree)`,   
   unknownGradsPrecisionProduction16 = `Race/ethnicity unknown total (C2016_A_RV First major Precision Production Bachelor's degree)`,   
   nonResAlienGradsPrecisionProduction16 = `Nonresident alien total (C2016_A_RV First major Precision Production Bachelor's degree)`,   
   #33  
   twoOrMoreRacesGradsTransportationMaterialsMoving16 = `Two or more races total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,    
   unknownGradsTransportationMaterialsMoving16 = `Race/ethnicity unknown total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,  
   nonResAlienGradsTransportationMaterialsMoving16 = `Nonresident alien total (C2016_A_RV First major Transportation and Materials Moving Bachelor's degree)`,   
   #34  
   twoOrMoreRacesGradsVisualPerformingArts16 = `Two or more races total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)`,   
   unknownGradsVisualPerformingArts16 = `Race/ethnicity unknown total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)` ,  
   nonResAlienGradsVisualPerformingArts16 = `Nonresident alien total (C2016_A_RV First major Visual and Performing Arts Bachelor's degree)`,   
   #35  
   twoOrMoreRacesGradsHealthProfessionsRelatedPrograms16 = `Two or more races total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,   
   unknownGradsHealthProfessionsRelatedPrograms16 = `Race/ethnicity unknown total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,   
   nonResAlienGradsHealthProfessionsRelatedPrograms16 = `Nonresident alien total (C2016_A_RV First major Health Professions and Related Programs Bachelor's degree)`,   
   #36  
  twoOrMoreRacesGradsBusinessManagementMarketing16 = `Two or more races total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,  
  unknownGradsBusinessManagementMarketing16 = `Race/ethnicity unknown total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,           
  nonResAlienGradsBusinessManagementMarketing16 = `Nonresident alien total (C2016_A_RV First major Business Management Marketing and Related Support Services Bachelor's degree)`,   
   #37  
   twoOrMoreRacesGradsHistory16 = `Two or more races total (C2016_A_RV First major History Bachelor's degree)` ,   
   unknownGradsHistory16 = `Race/ethnicity unknown total (C2016_A_RV First major History Bachelor's degree)`,   
   nonResAlienGradsHistory16 = `Nonresident alien total (C2016_A_RV First major History Bachelor's degree)`,     
   # 38  
   twoOrMoreRacesGradsHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `Two or more races total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,    
   unknownGradsHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `Race/ethnicity unknown total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,   
   nonResAlienGradsHomelandSecurityLawEnforcementFirefightingRelatedProtectiveService16 = `Nonresident alien total (C2016_A_RV First major Homeland Security Law Enforcement Firefighting and Related Protective Service Bachelor's degree)`,    
   # 39  
   twoOrMoreRacesGradsEconomics16 = `Two or more races total (C2016_A_RV First major Economics Bachelor's degree)`,   
   unknownGradsEconomics16 = `Race/ethnicity unknown total (C2016_A_RV First major Economics Bachelor's degree)`,   
   nonResAlienGradsEconomics16 = `Nonresident alien total (C2016_A_RV First major Economics Bachelor's degree)`,   
   #40  
   twoOrMoreRacesGradsPoliticalScience16 = `Two or more races total (C2016_A_RV First major Political Science and Government Bachelor's degree)`,     
   unknownGradsPoliticalScience16 = `Race/ethnicity unknown total (C2016_A_RV First major Political Science and Government Bachelor's degree)` ,    
   nonResAlienGradsPoliticalScience16= `Nonresident alien total (C2016_A_RV First major Political Science and Government Bachelor's degree)` ,    
   # 41  
   twoOrMoreRacesGradsSocialSciences16 = `Two or more races total (C2016_A_RV First major Social Sciences Bachelor's degree)`,    
   unknownGradsSocialSciences16 = `Race/ethnicity unknown total (C2016_A_RV First major Social Sciences Bachelor's degree)`,   
   nonResAlienGradsSocialSciences16 = `Nonresident alien total (C2016_A_RV First major Social Sciences Bachelor's degree)` ) %>%   
   #  
   # Modify to refer to twoOrMore, unknown, nonResAlien  
   mutate(twoOrMoreRacesGradsSocialSciencesWithoutEconPoli16 =   
         twoOrMoreRacesGradsSocialSciences16 -  
         (twoOrMoreRacesGradsEconomics16 + twoOrMoreRacesGradsPoliticalScience16),  
       unknownGradsSocialSciencesWithoutEconPoli16 =   
         unknownGradsSocialSciences16 -  
         (unknownGradsEconomics16 + unknownGradsPoliticalScience16),  
       nonResAlienGradsSocialSciencesWithoutEconPoli16 =   
         nonResAlienGradsSocialSciences16 -  
         (nonResAlienGradsEconomics16 + nonResAlienGradsPoliticalScience16)) %>%  
   # Modify to refer to twoOrMoreRaces, unknown, nonResAlien  
   select(-c(twoOrMoreRacesGradsSocialSciences16,  
          unknownGradsSocialSciences16, nonResAlienGradsSocialSciences16))    
   #   
   # return(dt)     
   }  
 #  
 shortInlongOut <- function(short, dt){  
   longNames <- dt$institution   
   lVec <- str_detect(longNames, short) # ... at least 5 chars  
   if (sum(lVec) == 0) {  
     print(paste("Can't find", short))  
     return(NULL)  
   } else if (sum(lVec) >=2) {  
     print(paste("More than one match for", short))  
     return(NULL)  
   }  
   index <- seq(1:length(longNames))[lVec]  
   return(longNames[index])  
 }  
 #  
 prepTableRaceOthers_0 <- function(dt1=table_0, dt2=tableOthers_0) {  
 ### Function joins graduate variables in table_0 with   
 ### graduate variables in tableOthers_0 via shared UnitID   
 ### ... drops extra duplicate copy of institution  
   #  
   # Exclude enrollment data from dt1  
   dt1 <- dt1 %>%  
     select(-c(totalEnroll15, asianEnroll15,   
          blackEnroll15, hispanicEnroll15, whiteEnroll15,  
          twoOrMoreRacesEnroll15, UnknownEnroll15,  
          nonResAlienEnroll15, natHawPacIsleEnroll15,  
          AmIndAlaNatEnroll15, twoOrMoreRacesEnroll15, M25th15))   
   dt2 <- select(dt2, -institution)  
   # Inner Join the tables  
   dt <- inner_join(dt1, dt2, by = "UnitID")  
   #  
   return(dt)  
 }  
 #  
 makeBasicListGrads <- function(shortName, dt=tableRaceOthers_0) {  
 ### Wrangle long format tibble into wide format tibble with race in   
 ### first column followed by degrees  
   #  
   longName <- shortInlongOut(shortName, dt)  
   if(is.null(longName)) {  
     return(longName)  
   }  
   #  
   dt <- dt %>%  
     filter(institution == longName)   
   #  
   # Skip first two columns UnitID and institution  
   dtRow <- dt[1, -c(1,2)]  
   # Delete the variables that have NA values  
   logVec <- !is.na(dtRow)  
   colVec <- 2 + c(1:length(logVec))[logVec]  
   dt <- dt[, c(1,2, colVec)]  
   #  
   vNames <- names(dt)  
   vNames <- str_replace_all(vNames, pattern="total", replacement = "total-")  
   vNames <- str_replace_all(vNames, pattern="asian", replacement = "asian-")  
   vNames <- str_replace_all(vNames, pattern="black", replacement = "black-")  
   vNames <- str_replace_all(vNames, pattern="hispanic", replacement = "hispanic-")  
   vNames <- str_replace_all(vNames, pattern="white", replacement = "white-")  
   vNames <- str_replace_all(vNames, pattern="twoOrMoreRaces", replacement = "twoOrMoreRaces-")  
   vNames <- str_replace_all(vNames, pattern="unknown", replacement = "unknown-")  
   vNames <- str_replace_all(vNames, pattern="nonResAlien", replacement = "nonResAlien-")  
   names(dt) <- vNames  
   #  
   dt <- gather(dt, programs, grads, -c(institution, UnitID))  
   dt <- dt[, -c(1, 2)] # drop 1st 2 cols institution and UnitID  
   dt <- separate(dt, programs, into=c("race", "degree"), sep="-")  
   # "Grads16" becomes a "degree" after separate  
   dt <- spread(dt, key=degree, value=grads)  
   dt <- arrange(dt, desc(Grads16))   
   #  
   asianGrads <- dt[3, "Grads16"]  
   whiteGrads <- dt[2, "Grads16"]  
   asianGrads2whiteGrads16 <- round(asianGrads/whiteGrads, 2)  
   #  
   basicListGrads <- list("institution" = longName, "allGradData16" = dt,   
         "asianGrads2whiteGrads16" = asianGrads2whiteGrads16)  
   return(basicListGrads)  
 }  
 #  
 makeTableSummaryEnrollDraft <- function (dt=table_0){  
 ### Function selects the enrollment variables from dt, drops all others  
 #  
   dt <- dt %>%  
     select(institution, totalEnroll15, asianEnroll15,   
       blackEnroll15, hispanicEnroll15, whiteEnroll15,  
       UnknownEnroll15, AmIndAlaNatEnroll15, nonResAlienEnroll15,  
       natHawPacIsleEnroll15, AmIndAlaNatEnroll15,  
       twoOrMoreRacesEnroll15, M25th15) %>%  
     rename(Institution = institution, Total=totalEnroll15,   
        Asian=asianEnroll15, Black=blackEnroll15,   
        Hispanic=hispanicEnroll15, White=whiteEnroll15,  
        Unknown = UnknownEnroll15,   
        NonResAlien=nonResAlienEnroll15,  
        NatHawPac = natHawPacIsleEnroll15,   
        AmIndAlNat = AmIndAlaNatEnroll15,  
        TwoOrMore = twoOrMoreRacesEnroll15) %>%  
     arrange(desc(Asian))  
  #    
   return(dt)  
 }  
   
 #############################  
 ############################  
 #  
 ### C. Execute the script commands that call the functions   
 table_0 <- prepTable_0(dtIPEDS_raw)  
 # glimpse(table_0)  
 #  
 tableOthers_0 <- prepTableOthers_0(dtIPEDS_Others_raw)  
 # glimpse(tableOthers_0)  
 #  
 tableRaceOthers_0 <- prepTableRaceOthers_0(table_0, tableOthers_0)  
 # glimpse(tableRaceOthers_0)  
 #  
 tableSummaryEnrollDraft <- makeTableSummaryEnrollDraft(table_0)   
 #  
 # Make the first list objects for each of the 21 institutions  
 Harvard <- makeBasicListGrads("Harvard")  
 Yale <- makeBasicListGrads("Yale")  
 Princeton <- makeBasicListGrads("Princeton")  
 Cornell <- makeBasicListGrads("Cornell")  
 Columbia <- makeBasicListGrads("Columbia")  
 Dartmouth <- makeBasicListGrads("Dartmouth")  
 Brown <- makeBasicListGrads("Brown")  
 Penn <- makeBasicListGrads("Penn")  
   
 Stanford <- makeBasicListGrads("Stanford")  
 Duke <- makeBasicListGrads("Duke")  
 Northwestern <- makeBasicListGrads("Northwestern")  
 Rice <- makeBasicListGrads("Rice")  
 Tufts <- makeBasicListGrads("Tufts")  
 Amherst <- makeBasicListGrads("Amher")  
 NotreDame <- makeBasicListGrads("Notre")  
 Vanderbilt <- makeBasicListGrads("Vande")  
 Washington <- makeBasicListGrads("Washi")  
 Illinois <- makeBasicListGrads("Illin")  
 Carnegie <- makeBasicListGrads("Carne")  
 MIT <- makeBasicListGrads("Massa")  
 CalTech <- makeBasicListGrads("Calif")  
   
 save(file="master1.rda",   
       Harvard, Yale, Princeton, Cornell,  
       Columbia, Dartmouth, Brown, Penn,  
       Stanford, Duke, Northwestern, Rice,  
       Tufts, Amherst, NotreDame, Vanderbilt,  
       Washington, Illinois, Carnegie, MIT,   
       CalTech, tableSummaryEnrollDraft)  
   
 ###################  
 # Examples  
 names(Harvard)  
 tableAllHarvardData16 <- Harvard[["allGradData16"]]  
   

No comments:

Post a Comment

Thank you!!! Your comments and suggestions will be greatly appreciated ... :-)