-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 342384952163c86255e5119dfb8322b2aca7b52b Author: Evan Hensleigh <futuraprime@gmail.com> Date: Wed Jul 11 17:55:13 2018 +0100 Added Excel. commit 31f992432e612a86585470b0d5c9e08167de0dc3 Author: Evan Hensleigh <futuraprime@gmail.com> Date: Wed Jul 11 15:17:58 2018 +0000 Minor fix. commit 518550fee07d994dfad58774e8a27ead8a015e45 Author: Evan Hensleigh <futuraprime@gmail.com> Date: Wed Jul 11 14:57:25 2018 +0000 Correcting Euro-area figures. commit 6363f73493b0304fa574ea473d16805c2a85f7bf Author: Evan Hensleigh <futuraprime@gmail.com> Date: Wed Jul 11 11:22:56 2018 +0000 Update R script. commit f1a468c35a4c2ee9cd2b55f32828c7859d34f656 Author: Evan Hensleigh <futuraprime@gmail.com> Date: Wed Jul 11 11:21:41 2018 +0000 Updated with final data. commit 72d770a74f62a9a322fe903c6c5bc49153cf7407 Author: Evan Hensleigh <futuraprime@gmail.com> Date: Tue Jul 10 18:52:19 2018 +0100 New-ish data. commit 9e0575601cdfc174bdce41b364a2bffef93455ef Author: Evan Hensleigh <futuraprime@gmail.com> Date: Tue Jul 10 12:24:47 2018 +0100 Now with updated data and correct country names. commit a7f70acb5f0d07d5519c34eb75760535c38d1d55 Author: Evan Hensleigh <futuraprime@gmail.com> Date: Tue Jul 10 12:01:19 2018 +0100 Update for regression. commit 93201141016b31e8980a2ac8cc7baa0839d56fb6 Author: Evan Hensleigh <futuraprime@gmail.com> Date: Tue Jul 10 11:55:06 2018 +0100 Adding July numbers.
- Loading branch information
1 parent
4858c7c
commit 2add4db
Showing
8 changed files
with
791 additions
and
382 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
library('tidyverse') | ||
library('data.table') | ||
|
||
big_mac_countries = c('ARG', 'AUS', 'BRA', 'GBR', 'CAN', 'CHL', 'CHN', 'CZE', 'DNK', | ||
'EGY', 'HKG', 'HUN', 'IDN', 'ISR', 'JPN', 'MYS', 'MEX', 'NZL', | ||
'NOR', 'PER', 'PHL', 'POL', 'RUS', 'SAU', 'SGP', 'ZAF', 'KOR', | ||
'SWE', 'CHE', 'TWN', 'THA', 'TUR', 'ARE', 'USA', 'COL', 'CRI', | ||
'PAK', 'LKA', 'UKR', 'URY', 'IND', 'VNM', 'GTM', 'HND', # Venezuela removed | ||
'NIC', 'AZE', 'BHR', 'HRV', 'JOR', 'KWT', 'LBN', 'MDA', 'OMN', | ||
'QAT', 'ROU', 'EUZ') | ||
base_currencies = c('USD', 'EUR', 'GBP', 'JPY', 'CNY') | ||
|
||
big_mac_data = fread('./source-data/big-mac-source-data.csv', na.strings = '#N/A') %>% | ||
.[!is.na(local_price)] %>% # remove lines where the local price is missing | ||
.[,GDP_dollar := as.numeric(GDP_dollar)] %>% # convert GDP to a number | ||
.[order(date, name)] # sort by date and then by country name, for easy reading | ||
|
||
latest_date = big_mac_data$date %>% max | ||
|
||
big_mac_data[, dollar_price := local_price / dollar_ex] | ||
|
||
big_mac_index = big_mac_data[ | ||
!is.na(dollar_price) & iso_a3 %in% big_mac_countries | ||
,.(date, iso_a3, currency_code, name, local_price, dollar_ex, dollar_price)] | ||
|
||
for(currency in base_currencies) { | ||
big_mac_index[ | ||
, | ||
(currency) := dollar_price / .SD[currency_code == currency]$dollar_price - 1, | ||
by=date | ||
] | ||
} | ||
big_mac_index[, (base_currencies) := round(.SD, 3), .SDcols=base_currencies] | ||
|
||
fwrite(big_mac_index, './output-data/big-mac-raw-index.csv') | ||
|
||
big_mac_gdp_data = big_mac_data[GDP_dollar > 0] | ||
|
||
regression_countries = c('ARG', 'AUS', 'BRA', 'GBR', 'CAN', 'CHL', 'CHN', 'CZE', 'DNK', | ||
'EGY', 'EUZ', 'HKG', 'HUN', 'IDN', 'ISR', 'JPN', 'MYS', 'MEX', | ||
'NZL', 'NOR', 'PER', 'PHL', 'POL', 'RUS', 'SAU', 'SGP', 'ZAF', | ||
'KOR', 'SWE', 'CHE', 'TWN', 'THA', 'TUR', 'USA', 'COL', 'PAK', | ||
'IND', 'AUT', 'BEL', 'NLD', 'FIN', 'FRA', 'DEU', 'IRL', 'ITA', | ||
'PRT', 'ESP', 'GRC', 'EST') | ||
big_mac_gdp_data = big_mac_gdp_data[iso_a3 %in% regression_countries] | ||
|
||
big_mac_gdp_data[,adj_price := lm(dollar_price ~ GDP_dollar) %>% predict,by=date] | ||
|
||
big_mac_adj_index = big_mac_gdp_data[ | ||
!is.na(dollar_price) & iso_a3 %in% regression_countries & iso_a3 %in% big_mac_countries | ||
,.(date, iso_a3, currency_code, name, local_price, dollar_ex, dollar_price, GDP_dollar, adj_price)] | ||
|
||
for(currency in base_currencies) { | ||
big_mac_adj_index[ | ||
, | ||
(currency) := (dollar_price / adj_price) / | ||
(.SD[currency_code == currency]$dollar_price / .SD[currency_code == currency]$adj_price ) - 1, | ||
by=date | ||
] | ||
} | ||
big_mac_adj_index[, (base_currencies) := round(.SD, 3), .SDcols=base_currencies] | ||
|
||
fwrite(big_mac_adj_index, './output-data/big-mac-adjusted-index.csv') | ||
|
||
big_mac_full_index = merge(big_mac_index, big_mac_adj_index, | ||
by=c('date', 'iso_a3', 'currency_code', 'name', 'local_price', 'dollar_ex', 'dollar_price'), | ||
suffixes=c('_raw', '_adjusted'), | ||
all.x=TRUE | ||
) | ||
|
||
fwrite(big_mac_full_index, './output-data/big-mac-full-index.csv') |
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters