Upload
janos-divenyi
View
2.155
Download
0
Embed Size (px)
Citation preview
How To Code?
CEU - 2015 Fall
János Divényi
1 - Stay organized
Project
do_code.do
GretlV1.csv
gretl_1.gretl
stata.dta
Project
Data
Code
Output
Project
Data
appended_trade.csv
2003.csv
Code
2004.csv
…
Output
Project
Data
Code
append_data_files.R
analyse_export_import.R
Output
Project
Data
regressions.htm
export_import.png
Output
Code
2 - Be clear
# use comments
## to explain
## to create sections
mydf %>% mutate(lx = log(x))
coke_prices %>%
mutate(log_price = log(price))
mydf %>% mutate(lx = log(x))
coke_prices %>%
mutate(log_price = log(price))
3 - Don’t repeat
trade2003 <- read.csv(′2003.csv′)
trade2004 <- read.csv(′2004.csv′)
trade2005 <- read.csv(′2005.csv′)
…
trade2013 <- read.csv(′2013.csv′)
rbind(trade2003, trade2004, …, trade2013)
trade2003 <- read.csv(′2003.csv′,
header=FALSE, …)
trade2004 <- read.csv(′2004.csv′)
trade2005 <- read.csv(′2005.csv′)
…
trade2013 <- read.csv(′2013.csv′)
bind_rows(trade2003, …, trade2013)
bind_rows(
lapply(
2003:2013,
function(year) {
read.csv(paste(year, ′.csv′),header=FALSE, …)
}
)
)
+1 – Search for help