Dear Statalists,
I have ten identically structured excel files which correspond to ten different years. All files include 18 variables which indentify an agegroup. For example the first agegroup variable is called "Underfiveyears", the second "Fivetonineyears" and the last "Overeightyyears". I want to use a loop which imports the excel files and renames these agegroup variables into age1, age2,...age18. Therefore, I used this loop:
forvalues i=1990/1999 {
import excel file`i', firstrow clear
foreach var of varlist Underfiveyears-Overeightyyears {
local x= `x'+1
rename `var' age`x'
save file_`i',replace
}
}
The problem is, that the command works for the first file but the numbering of the variables just continues for the following files instead of beginning with age1,...,. For example, the last agegroup variable in the first file is renamed age18 but the first agegroup variable in the second file is renamed age19 instead of age1.
Can someone help me to find a solution?
Thank you in advance!
Related Posts with Mistake in loop for renaming variables of several datafiles
Time-to-event analysis for panels STATA 13Hi all, I have the following database Code: * Example generated by -dataex-. To install: ssc inst…
Storing decile values correspong to decile rank in a separate variableHi everyone, I am writing to understand how I can store the decile values for the following dummy d…
Insignificant Variables and CollinearityHello! I am having some troubles with a particular regression. I have data from the labour force su…
Outreg2 for Likelihood Ratio Test (LR Test) ResultsHi all, I have been trying to send the Likelihood Ratio Test (LR Test) Results to MS Excel but fail…
error occurred while loading xtsur.ado Dear All, Greetings I use stata 14.1. I try to execute xtsur command . sometimes I get the result b…
Subscribe to:
Post Comments (Atom)
0 Response to Mistake in loop for renaming variables of several datafiles
Post a Comment