I am trying to import state unemployment into stata and then append them all into one file. Here is what I try to do with loop, and original data and final data are in different dataset. But I encounter error as "no; data in memory would be lost"
And following is what I thought about the appending, but have not try yet
Code:
clear
set more off
global path "D:\OneDrive..."
cd "$path"
* state abb list
global abb "AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY"
foreach x of global abb {
import excel "data/monthly unemployment rate/`x'.xlsx", sheet("BLS Data Series") cellrange(A11:H71) firstrow
gen month = month(date(Period, "M"))
rename Year year
gen date =ym(year,month)
format date %tmCCYY/NN
*gen state variable
gen state_abb = "`x'"
save "data_final/`x'.dta", replace
}
Code:
use "data_final/AL.dta", replace
global app "AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY"
foreach y of global app{
append using "data_final/`y.dta"
}
save "data_final/2018_2022 unemploy.dta", replace

Comment