I have several .csv data files that I want to import and save using a for loop.
The file names have a pattern, namely, scd1011, scd1112, scd1213, scd1314,...,scd1516
I am thinking of the following code, but cannot get the result
1. forvalues i =10(1)15{
cd "$rawdata"
insheet using "scd`i'`i+1'.csv", clear
cd "$workdata"
save "scd`i'`i+1'.dta",replace
}
2. forvalues i =10(1)15{
scalar j=i+1
cd "$rawdata"
insheet using "scd`i'`j'.csv", clear
cd "$workdata"
save "scd`i'`j'.dta",replace
}
Is there any solution to this?
Related Posts with A For Loop problem
Time varying covariate in Cox Regression modelHi all. After a thorough search online I can't seem to find a solution to my problem, which is why I…
Please help: Importing and merging multiple sheets from an excel file while renaming variables using loopsHello, I am quite new using loops and really want to understand it better. I have an excel file with…
Timevar for survival analysisDear All, This might be a silly question, but it is driving me crazy. I am managing data which wer…
Margins: trouble with continuous interactions under simultaneous fixed effectsSometimes I wish to control for variable X via fixed effects (say, year fixed effects) but also allo…
Panel data regressionHello everyone, I'm writing my thesis and I'm struggling with the processing of my data. First of a…
Subscribe to:
Post Comments (Atom)
0 Response to A For Loop problem
Post a Comment