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
Drop if 3 consecutive quarters of negative sales growthHey! I have some difficulties to write a proper code to clean my data. The goal is to keep only fir…
Add missing date, last observationHi, I do have an issue with my dataset. I need to add missing dates and replace the variable "creat…
How to find the amount of gaps in a natural number sequence?Dear Stata community, I have some oddly formatted data, as in the following example dataset: Code:…
how to draw a plot with confidence interval non-parametric regHi, I am using npregress kernel code for my analysis which goes like this: npregress kernel DepVar…
Computing Z-Score (risk measure)Hi guys, I´m new here and have just startet do use STATA for my thesis. So basically I´m interested…
Subscribe to:
Post Comments (Atom)
0 Response to looping through data files
Post a Comment