-
Notifications
You must be signed in to change notification settings - Fork 5
/
02-prepare-data.R
39 lines (30 loc) · 902 Bytes
/
02-prepare-data.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
# Prepare the data ----
## Prepare interval data
gravity2 <- gravity %>%
filter(year %in% seq(1986, 2006, 4))
## Create and transform some variables that are needed later
gravity2 <- gravity2 %>%
mutate(
log_trade = log(trade),
log_dist = log(dist)
) %>%
group_by(exporter, year) %>%
mutate(
output = sum(trade),
log_output = log(output)
) %>%
group_by(importer, year) %>%
mutate(
expenditure = sum(trade),
log_expenditure = log(expenditure)
) %>%
ungroup()
## Create pair ID and symmetric pair ID variables
## IMPORTANT: Here we don't need to create pair_id and symm_id as in Stata
gravity2 <- gravity2 %>%
mutate(
pair = paste(exporter, importer, sep = "_"),
first = ifelse(exporter < importer, exporter, importer),
second = ifelse(exporter < importer, importer, exporter),
symm = paste(first, second, sep = "_")
)