Hi, I'm using Stata 14 on Windows.
Currently I use this syntax for each country SEPARATELY (here only for Georgia):
use "D:\drive\SME adapt in COVID19\data\merged data\Georgia1.dta"
include 1st_round_vars
keep idstd adapt onlineadapt riseadapt workeradapt
rename * *1
rename idstd1 idstd
save rst_tmp, replace
use "D:\drive\SME adapt in COVID19\data\merged data\Georgia2.dta"
include 2nd_round_vars
keep idstd adapt onlineadapt riseadapt workeradapt
rename * *2
rename idstd2 idstd
merge 1:1 idstd using rst_tmp, keepusing(adapt onlineadapt riseadapt workeradapt) gen(mrg1)
drop mrg1
generate country= "Georgia"
save ctr_merging.dta, replace
BUT, I am new to stata. And I am trying to use looping by through country's data files. The names of the data files are "Georgia1.dta", "Belarus1.dta", "Moldova1.dta", "Mongolia1.dta" etc.
use "D:\drive\SME adapt in COVID19\data\merged data\Georgia2.dta"
instead of this I am trying to use this
cd "C:\Users\user\Desktop\panel\merged data"
local countrylist1 "Belarus1 Estonia1 Georgia1 Kazakhstan1 Latvia1 Lithuania1 Mongolia1 Moldova1 Russia1"
foreach country of local countrylist1 {
local datafiles : dir . files "`country'*.dta"
foreach f of local files {
use `f', replace
}
Any help appreciated.
Related Posts with looping through data files
Standard Error Correction Time Series AnalysisHello, I am currently working on a time series analysis project. I have autocorrelation in the erro…
Standardized variablesHi, I have panel data and defined my variables accordingly: xtset id q_date,q if i want to standard…
Compile total sample based on one fiscal year (2004)Hi all, I have filtered specific firms based on certain criteria for the fiscal year 2004. On the b…
Standardized variablesHi, I have panel data and defined my variables accordingly: xtset id q_date,q if i want to standard…
Defining a variable fitting to the size of a matrixHey everyone, im still new to stata so this is probably still a trivial question . for further compu…
Subscribe to:
Post Comments (Atom)
0 Response to looping through data files
Post a Comment