David asked:
> Is there any way to create a list of variable names, either
> in string form
> or some other way, that could then be manipulated using
> "foreach" and the
> like?
See -help unab-. However, -foreach- can also do this directly,
e.g.
foreach x of varlist * {
...
}
will loop over all variables in the dataset.
> I would like to rename multiple variables in a consistent way
> -- that is, to
> abbreviate their names to 8 characters if they are any longer
> than this
> (using 'abbrev'). I would like to use a structure something like:
>
> foreach x in [list of variable names] {
> if length(`x')>8 {
> rename `x' abbrev(`x',8)
> }
> }
How about this:
foreach x of var * {
if length("`x'")>8 {
local newname: permname `x', length(8)
rename `x' `newname'
}
}
Cheers,
ben
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/