Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[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   Amanda Fu <[email protected]>
To   [email protected]
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 10:26:01 -0400

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.

Best,
Amanda

On Thu, Sep 30, 2010 at 10:16 AM, Nick Cox <[email protected]> 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
>
> Nick
> [email protected]

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index