Various suggestions were made in this thread. In
general, use of -reshape-'s advanced syntax seems
most direct to me. But renaming solutions are
of interest for many other problems and I will
focus on those.
Using -renpfix- is not a good solution.
Here the prefix is variable, not constant.
That is, within
ASMOK BSMOK CSMOK
the prefix is variously A B C.
So -renpfix- offers no advantage over
one by one -rename-s in this instance.
Another solution is
foreach v of var *SMOK {
local pre = substr("`v'",1,index("`v'", "SMOK")-1)
rename `v' SMOK`pre'
}
For who prefer the user-written -renvars- from the SJ,
a solution is possible in the same spirit
renvars *SMOK, map("SMOK" + substr("@",1,index("@","SMOK")-1))
Alternatively,
foreach v of var *SMOK {
local pre : subinstr local v "SMOK" ""
rename `v' SMOK`pre'
}
with again a -renvars- analog, something like this:
renvars *SMOK, map("SMOK" + `"`: subinstr local v "SMOK" ""'"')
Tricky, but it can be done! I prefer
foreach v of var *SMOK {
local pre : subinstr local v "SMOK" ""
rename `v' SMOK`pre'
}
to using -renvars- in this case.
Nick
[email protected]
Paul Millar
> Another approach might be to use the renpfix command, which
> renames (or removes the prefix) see -whelp renpfix-
>
> Once the prefix is removed it is easy to reshape.
*
* 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/