I just learned how to use a for
loop in Stata.
I tried this on my data in order to convert my string formatted variables to numeric ones and then move the new numeric variables right next to the old string formatted variables.
But somehow Stata gave me an error message:
foreach var of varlist city zipcode {
encode 'var', gen(_'var')
order _'var', after('var')
}
' invalid name
r(198);
I also tried the following:
foreach varlist in city zipcode {
encode 'varlist', gen(_'varlist')
order _'varlist', after('varlist')
}
invalid syntax
r(198);
I guess these simple code snippets should work but I have no idea why they fail.
Could someone please help me out?