Dear all,
I am trying to combine datasets which are saved in files per country per year.
I start with a database of hourly electricity prices for a number of countries and now want to add load data by running a loop using joinby for the countries and years.
As stated in the title, the code runs smoothly and does not generate any error terms, but generates empty values "." for all hourly slots after Austria, 2015 (which should be the first pair on the loops).
This is my code: (the country list is actually significantly longer, but I am running it like this to work the kinks out of the code)
local countrylist "AT BE"
local years "2015 2016 2017 2018 2019 2020 2021 2022 2023"
foreach year of local years {
foreach country of local countrylist {
clear
use "${pathBASE}/2. working/Database merged.dta"
joinby iso2code datetimelocal using "${pathBASE}/1. raw data/load data/`country'/load_`country'_`year'.dta", unmatched(both)
drop _merge
save "${pathBASE}/2. working/Database merged.dta", replace
}
}
iso2code is a string variable, datetimelocal is a double.
I am trying to combine datasets which are saved in files per country per year.
I start with a database of hourly electricity prices for a number of countries and now want to add load data by running a loop using joinby for the countries and years.
As stated in the title, the code runs smoothly and does not generate any error terms, but generates empty values "." for all hourly slots after Austria, 2015 (which should be the first pair on the loops).
This is my code: (the country list is actually significantly longer, but I am running it like this to work the kinks out of the code)
local countrylist "AT BE"
local years "2015 2016 2017 2018 2019 2020 2021 2022 2023"
foreach year of local years {
foreach country of local countrylist {
clear
use "${pathBASE}/2. working/Database merged.dta"
joinby iso2code datetimelocal using "${pathBASE}/1. raw data/load data/`country'/load_`country'_`year'.dta", unmatched(both)
drop _merge
save "${pathBASE}/2. working/Database merged.dta", replace
}
}
iso2code is a string variable, datetimelocal is a double.
Comment