Dear All,
I'm creating a dta file with names of files within a folder of my local disk. To do so, I'm running the same loop twice, where the only change is the type of file I want to record in the dta file. I want to simplify the process in one loop, rather than two. This is my code.
local paths ""C:\project1" "C:\project2" "C:\project3""
foreach path of local paths {
local fdir "`path'"
cd "`path'"
local files : dir . files "*.do"
foreach file of local files {
replace name= "`file'" if name==""
set obs `=_N+1'
}
}
foreach path of local paths {
local fdir "`path'"
cd "`path'"
local files : dir . files "*.txt"
foreach file of local files {
replace name= "`file'" if name==""
set obs `=_N+1'
}
}
I tried inserting a new local macro within the first loop, but it yields repeated names of files.
Thank you for your help in advance,
Liz
Related Posts with Combinig two loops into one
Construct equally weighted decile portfolios by ranking stocks on past 3 years volatilityHey dear Members, I have a data sets of about 303 companies with monthly returns of the last 22 yea…
How to check correlation among 2000+ variables in a quick way?Hi, all, I had a data set of 2000+ variables (all binary or categorical), for example, 1000+ are …
Can I use logit without with YES/NO data instead of 0/1?Hi, everyone, All my data are in YES/NO values instead of 0/1. And I want to find the correlation a…
Plotting a (curvilinear) mediated relationI am working with a mediated-moderated model like that in Fig. 1. All variables in the model are con…
Sublime Text and Stata 16I am trying to use Sublime Text with Stata 16, similar to what I previously did with earlier version…
Subscribe to:
Post Comments (Atom)
0 Response to Combinig two loops into one
Post a Comment