Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Re: reshape when the stub is at the beginning of the variables


From   Paul Millar <[email protected]>
To   [email protected]
Subject   RE: st: Re: reshape when the stub is at the beginning of the variables
Date   Wed, 26 Apr 2006 14:39:37 -0600

A good solution Nick. I maintain that renpfix may still be a good solution for such situations where the prefix A*, B*, C* is for each wave or cycle of a survey. If there are a hundred or more variables and only a few cycles, the -renpfix- is a better approach. It depends on what there is more of.

- Paul

At 05:34 AM 26/04/2006, you wrote:

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/
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index