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
remove certain string chars if in beginning of string var onlyDear Statalist, I have been searching for ways to remove a sequence of characters from a string var…
Viewing value labels in a loopHi there, I am trying to retrieve the value labels for the encoded variable pos_index (defined belo…
Non parametric estimation of Regression Discontinuity analysis in Stata(rdrobust)I use the following code for non parametric estimation: rdrobust y v,c(0) kernel(uni) bwselect(mser…
Moving average code to moving additive?By using a time-series dataset, I want to create a moving additive index. For example, I need a 5-ye…
running a loop n times with different outcome variables and storing the beta, standard error and p valuesHi, STATA people, I have 12000 obs. I want to randomly assign fake treatment within each year with …
Subscribe to:
Post Comments (Atom)
0 Response to A For Loop problem
Post a Comment