-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_introduction.R
152 lines (93 loc) · 2.34 KB
/
01_introduction.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
# 01 - Introduction ----
# Open Trade Statistics package
# This package is available on CRAN
# install.packages("tradestatistics")
## Introduction ----
library(tradestatistics)
library(tibble)
## Package data ----
### Available tables ----
as_tibble(ots_tables)
# y: year column
# r: reporter column
# p: partner column
# c: commodity column
# The most aggregated table is yr
### Country codes ----
as_tibble(ots_countries)
### Commodity codes ----
as_tibble(ots_commodities)
### Inflation data ----
as_tibble(ots_gdp_deflator)
## Package functions ----
### Country code ----
# single match with no replacement
as_tibble(ots_country_code("Chile"))
# Single match with replacement
as_tibble(ots_country_code("America"))
# Double match with no replacement
as_tibble(ots_country_code("Germany"))
### Commodity code ----
as_tibble(ots_commodity_code(commodity = " ShEEp ", section = "mEaT"))
### Trade data ----
### Bilateral trade at commodity level ----
# Chile-Argentina bilateral trade at community level in 2019
yrpc <- ots_create_tidy_data(
years = 2019,
reporters = "chl",
partners = "arg",
table = "yrpc"
)
as_tibble(yrpc)
# Pass two years or more, several reporters/partners,
# and filter by commodities with exact codes or code
# matching based on keywords:
yrpc2 <- ots_create_tidy_data(
years = 2018:2019,
reporters = c("chl", "Peru", "bol"),
partners = c("arg", "Brazil"),
commodities = c("01", "food"),
table = "yrpc"
)
### Bilateral trade at aggregated level ----
yrp <- ots_create_tidy_data(
years = 2018:2019,
reporters = c("chl", "per"),
partners = "arg",
table = "yrp"
)
as_tibble(yrp)
yrpc2
### Reporter trade at commodity level ----
yrc <- ots_create_tidy_data(
years = 2019,
reporters = "chl",
commodities = "010121",
table = "yrc"
)
as_tibble(yrc)
### Reporter trade at aggregated level -----
yr <- ots_create_tidy_data(
years = 2018:2019,
reporters = c("chl", "arg", "per"),
table = "yr"
)
as_tibble(yr)
### Commodity trade at aggregated level ----
yc <- ots_create_tidy_data(
years = 2019,
table = "yc"
)
as_tibble(yc)
yc2 <- ots_create_tidy_data(
years = 2019,
commodities = "010121",
table = "yc"
)
as_tibble(yc2)
### Inflation adjustment ----
inflation <- ots_gdp_deflator_adjustment(
trade_data = yr,
reference_year = 2000
)
as_tibble(inflation)