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: Remove portion of a number at the end of a variable name


From   Steve Nakoneshny <scnakone@ucalgary.ca>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Remove portion of a number at the end of a variable name
Date   Wed, 19 Dec 2012 18:48:40 -0700

David,

I mistyped. I meant to say -h rename groups-. The amped up -rename- in Stata 12 can do what you require without needing to resort to a loop solution.

Steve

Sent via carrier pigeon

On 2012-12-19, at 5:02 PM, "David Torres" <writeon4truth2@msn.com> wrote:

> Thanks for your suggestion, Steve.
> 
> I would, however, like to avoid using Stata's standard -reshape- command since it does not preserve variable labels.  Instead, I'm using the user-written command -longshape-.
> 
> A few lines of code to just drop those pesky zeros before single digit years is preferred if you can provide it.
> 
> Diego
> 
> 
> --
> 
> David Diego Torres, PhD
> NSF SBE Postdoctoral Research Fellow
> Houston Education Research Consortium
> Rice University
> 6100 Main Street, MS-28
> Houston, TX 77005
> Phone: 713-348-2984
> Email: ddtorres at rice dot edu
> 
> 
> ----------------------------------------
>> From: scnakone@ucalgary.ca
>> To: statalist@hsphsun2.harvard.edu
>> Date: Wed, 19 Dec 2012 16:45:50 -0700
>> Subject: Re: st: Remove portion of a number at the end of a variable name
>> 
>> David,
>> 
>> Look at -h reshape group-. It will give you the syntax you need to rename your var appropriately with a minimum of pain.
>> 
>> Steve
>> 
>> Sent via carrier pigeon
>> 
>> On 2012-12-19, at 4:42 PM, "David Torres" <writeon4truth2@msn.com> wrote:
>> 
>>> Hello, Stata experts,
>>> 
>>> I have about 260 variables with two-digit numbers (representing years) following the variable stub in the following form:
>>> 
>>> 08
>>> 09
>>> 
>>> Before reshaping the data to long format, I need to get rid of the 0 between the variable stub and the year.
>>> 
>>> For instance, how can I get these variables:
>>> 
>>> yrid08
>>> yrcampus08
>>> testdate08
>>> dob08
>>> 
>>> into this form:
>>> 
>>> yrid8
>>> yrcampus8
>>> testdate8
>>> dob8
>>> 
>>> Thanks in advance for any help,
>>> Diego
>>> 
>>> --
>>> 
>>> David Diego Torres, PhD
>>> NSF SBE Postdoctoral Research Fellow
>>> Houston Education Research Consortium
>>> Rice University
>>> 6100 Main Street, MS-28
>>> Houston, TX 77005
>>> Phone: 713-348-2984
>>> Email: ddtorres at rice dot edu
>>> 
>>> *
>>> * For searches and help try:
>>> * http://www.stata.com/help.cgi?search
>>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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