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:looping over 41 months over 3 full years(12 months each) and a half year (5 months)


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st:looping over 41 months over 3 full years(12 months each) and a half year (5 months)
Date   Thu, 30 Sep 2010 15:30:28 +0100

I've been called some funny names in my time but Mr. Nix is new. 

Nick 
n.j.cox@durham.ac.uk 

Amanda Fu

Dear Mr. Nix,

Thank you, Mr Nix for your suggestion. It helped a lot.

I think I will go for the reshaping. Just now I sent out my request
for your article on looping tips through library. I will read it when
I receive it.

On Thu, Sep 30, 2010 at 10:16 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote:

> An overall comment is that this kind of structure is usually more awkward, so do consider a -reshape-.
>
> This is (untested) code intended to do what you want.
>
> local m = 0
> local year = 1999
> forval i = 1/41 {
>        local m = cond(`m' == 12, 1, `m' + 1)
>        local year = `year' + (`m' == 1)
>        local M : di %02.0f `m'
>        rename var`i' var`M'_`year'
> }
>
> See also
>
> SJ-10-1 pr0051  . . . . . . . . . . . . Stata tip 85: Looping over nonintegers
>        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
>        Q1/10   SJ 10(1):160--163                                (no commands)
>        tip on using forvalues to loop over numbers
>

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