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
please help me about this code error: invalid options:t(below)the code is below: asdoc reghdfe tq rds ,absorb(id) vce(r) dec(4) rep(t) t(below) nest replace Array…
What should we conclude when the Adjusted R square decrease when adding a dummy variable into the regression?In my regression using OLS, when I add a dummy variable into my regression, the Adjusted R-squared r…
Picking highest real output per worker in sector i in year tDear all, In my dataset, I have variables of real output per worker across 34 different sectors in …
Writing loop to identify individuals with consecutive positive values (n, n+1, n+2, ...)Hi, First time Statalist poster, long time follower. Thanks for this great resource. I am working …
How to Create and Merge New VariablesHi All, I need to create two new variables (one for HIV questions and one for STD questions) that me…
Subscribe to:
Post Comments (Atom)
0 Response to Combinig two loops into one
Post a Comment