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 on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: forval query


From   "Mirnezami, Oliver" <O.Y.Mirnezami@warwick.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: forval query
Date   Fri, 5 Apr 2013 14:21:05 +0000

Thanks Nick. Yes I do reshape it later on in the do file. 

Oliver 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 05 April 2013 15:05
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: forval query

If your data are really panel or longitudinal data, then a -reshape
long- is now likely to be advisable.

For the record: Thanks to Billy for the plug, and I'll add that
-renvars- (SJ) was a joint production of Jeroen Weesie and myself. It remains possibly useful for renaming for Stata <12.

Nick
njcoxstata@gmail.com


On 5 April 2013 14:52, Mirnezami, Oliver <O.Y.Mirnezami@warwick.ac.uk> wrote:
> Thank you very much Maarten and Billy for your replies! Works brilliantly.
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu 
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of William 
> Buchanan
> Sent: 05 April 2013 14:47
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: forval query
>
> Why not just use the rename command with the group syntax?  Additionally, Nick Cox wrote an amazingly helpful command for performing a variety of renaming tasks that may be helpful in other situations (-findit renvars-).
>
> This is completely untested but maybe you could try something like:
>
> forv i=2/10{
> loc val = 1990+(2*`i')
> rename r`i'mobila mobila_`val'
> }
>
> HTH,
> Billy
>
> Sent from my iPhone
>
> On Apr 5, 2013, at 6:32, "Mirnezami, Oliver" <O.Y.Mirnezami@warwick.ac.uk> wrote:
>
>> Hi
>>
>> I'm having some difficulty in using forval and foreach commands and was hoping for some help with the syntax please.
>>
>> Previously i've been renaming variables manually en masse using the following code:
>>
>> rename  r2mobila mobila_1994
>> rename  r3mobila mobila_1996
>> rename  r4mobila mobila_1998
>> .etc..
>> rename  r10mobila mobila_2010
>>
>> i.e. '2' corresponds with '1994', '3' with '1996' etc.
>>
>> I've tried using the following command but i get an r(111) error:
>>
>> forval i = 2/10 {
>> forval j = 1994/2010 {
>> foreach k in r`i'mobila {
>> rename `k' mobila_`j'
>> }
>> }
>> }
>>
>> I don't think I've managed to link '2' with '1994' and '3' with '1996' properly.
>>
*
*   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