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
Exogenous variables in DCC modelHi all, Is there any way to include exogenous variables in a DCC model? I'm using the mgarch dcc co…
Panel data : assigning random treatment to same no of observation yearwiseHi, Stata people. I have got a 20 years panel data 1990- 2010. For the falsification test. I drop a…
import file excel only date to stringHello please how can i import only date variables as character from an excel file Thanks …
For loopHi guys, I would like to make a loop that includes several different variables for different databa…
Looping through different databasesHi guys, I would like to make a loop that includes several different variables for different databa…
Subscribe to:
Post Comments (Atom)
0 Response to Combinig two loops into one
Post a Comment