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
Estimating discrete choice model using continuous v/s binary variablesHello, I am trying to estimate a discrete choice model, and I have a quick question on how I can st…
generalised DID with two-way fixed modelDear researchers, I have unbalanced panel data for a set of firms for the year extends from 2000-201…
How to detect data entry error: locating an observation that does not match any of the observations of a given set?Hi Statalist, Apologies for the vagueness of the question as I didn't know how to frame it better. H…
find robustHow can I solve the following error? must specify panelvar; use xtset r(459); …
Issue with summing and averaging different columns/variablesHi, I'm fairly new to Stata so I apologize if my question is basic. I am essentially trying to creat…
Subscribe to:
Post Comments (Atom)
0 Response to looping through data files
Post a Comment