#==================================================================================================================================================== # AULA 05 # MATERIA: ECONOMETRIA II # PROFESSOR: DANIEL DOMINGUES DOS SANTOS # MONITOR: DIEGO MENEZES # R - VERSAO UTILIZADA: 3.4.0 (2017-04-21) # SCRIPT: dados em painel # ETAPA: construcao do painel #==================================================================================================================================================== # SETUP: -------------------------------------------------------------------------------------------------------------------------------------------- rm(list = ls()) # GLOBAL SETTINGS # data paths # input DATA.INPUT.VARIABLES.PANEL <- "C:/Users/diego/OneDrive/Documentos/Mestrado_FEARP/Monitorias/Econometria II/aula 05/Data/Input" # output DATA.OUTPUT.PANEL <- "C:/Users/diego/OneDrive/Documentos/Mestrado_FEARP/Monitorias/Econometria II/aula 05/Data/Output" # DATA INPUT: --------------------------------------------------------------------------------------------------------------------------------------- # CSV INPUT # lists all csv files in data input directory (incoming.csv.files = list.files(path = DATA.INPUT.VARIABLES.PANEL, pattern = "*.csv")) # automates input of individual csv files # change of WD needed to point lapply to data input folder setwd(DATA.INPUT.VARIABLES.PANEL) panel.variables <- lapply(setNames(incoming.csv.files, make.names(gsub("*.csv$", "", incoming.csv.files))), read.csv) # DATASET CLEANUP AND PREP -------------------------------------------------------------------------------------------------------------------------- # PANEL MERGE # merge # Reduce used to apply binary function to more than two objects -- needed to merge multiple dataframes, as merge(x,y) is binary panel <- Reduce(function(x,y) {merge(x, y, all = T)}, panel.variables) # VARIABLES CREATION # turnover rate panel$turnover_rate <- (panel$total_admissions - panel$total_dismissals)/panel$total_labour panel$turnover_rate <- panel$turnover_rate * 100 # interaction between monthly income average and open processes in TST panel$int_TSTrec_income <- panel$TST_received * panel$mthly_income_avg # open processes in TST normalized by total labour panel$TST_received_norm <- panel$TST_received / panel$total_labour # interaction between judges per hundred thousand people and linear tendency panel$int_judges_time <- panel$judges_per_hund_thous_people * panel$time # dummy after 2009 dummy_after2009 <- ifelse(panel$year >= 2009, 1, 0) panel <- cbind(panel, dummy_after2009) # EXPORT -------------------------------------------------------------------------------------------------------------------------------------------- save(panel, file = file.path(DATA.OUTPUT.PANEL, "panel_4_analysis.Rdata")) # exports Rdata write.csv(panel, file.path(DATA.OUTPUT.PANEL, "panel_4_analysis.csv"), row.names = F) # exports csv # END OF SCRIPT: ------------------------------------------------------------------------------------------------------------------------------------