I have three datasets located in this below file structure,
1. data_2017_2018/merged_2017.dta
2. data_2018_2019/merged_2018.dta
3. data_2019_2020/merged_2019.dta
I want to append all three .dta datasets with some cleaning without moving three datasets in one folder. The way I am doing is,
In the above code, the first iteration is running but followed that is not working. Can anyone please help on how to fix this issue?
1. data_2017_2018/merged_2017.dta
2. data_2018_2019/merged_2018.dta
3. data_2019_2020/merged_2019.dta
I want to append all three .dta datasets with some cleaning without moving three datasets in one folder. The way I am doing is,
Code:
foreach i in data_2017_2018 data_2018_2019 data_2019_2020 {
forvalues year = 2017 (1) 2019 {
di in red "codes running on year `year'"
use "$globalpath/`i'/merged_`year'" , clear
*cleaning codes
if `year' == 2017 {
*some cleaning code
tempfile datacomb
save `datacomb'
}
else {
append using `datacomb' , force
*some cleaning codes
save `datacomb' , replace
}
}
}

Comment