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
Strange results with -mi impute-Hi everyone, I am new to multiple imputation. I have a large dataset (60,000+ observations) with da…
Multiple imputationDear all, I will please like to know how to carry out Instrumental variable post estimation tests (…
Again on revisiting the role of p-valueDear All, those interested in this debate may find the following article interesting: https://ift.tt…
Unconditional Quantile Regression (rifreg) with an Interaction Term; and an independent percentile score variableHi all, we have a panel data set (defined by firms and years) and are trying to estimate the followi…
One line code for performing arithmetic operation (here division) for multiple variablesExchange rate CPI.dta Here is the dataset and I want a proportionate values for all countries divide…
Subscribe to:
Post Comments (Atom)
0 Response to Combinig two loops into one
Post a Comment