Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: loop to insert underscore before year suffix


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: loop to insert underscore before year suffix
Date   Wed, 21 Sep 2011 13:28:04 +0100

Tacitly you are using Stata 12 and so could use -rename- directly, without needing any programming. Alternatively, -findit renvars-.

All that said, underscores are not needed here. See my FAQ on - reshape- for how to extract stubs using -unab-.

Nick

On 21 Sep 2011, at 13:16, Lindsay Pettingill <lpetting@gmail.com> wrote:

Hello,
I am working with a massive panel dataset in wide form that I would
like to convert to long. The reshape command requires stubs, and I
have a ton of variables, differentiated by a variable name, followed
by the year. I'd like to generate a list of stubs, and have found some
programs here to do so, but my stubs are not separated from year with
an underscore. Instead, I just have text, followed by a number.
Example:
yearmovedinto2005 yearmovedinto2006 satisdwelling1995 satisdwelling1994
Is there a loop I can run to insert an underscore before the year, so
that I can then generate the stub names and reshape? I imagine there
is an easy way, using a wildcard, but my programming skills are close
to null.
Thanks!

Lindsay Pettingill
Georgetown University
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index