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: Double loop over unbalanced panel


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Double loop over unbalanced panel
Date   Fri, 2 Nov 2012 20:39:29 +0000

I think the best advice depends on what -formula()- is, which you
don't tell us.

That said

foreach of numlist ...

in both your examples can be recast more simply as -forval- loops.

Nick

On Fri, Nov 2, 2012 at 8:12 PM, Fernando Luco <[email protected]> wrote:
> Hi,
>
> I have an unbalanced panel and I need to do a loop over individuals and
> observations. My data looks as follows (I have other variables that are not
> represented in this example)
>
> id t  chc
> 1 1 .5
> 1 2 .
> 1 3 .
> 1 4 .
> 1 5 .
> 2 3 1
> 2 4 .
> 2 5 .
> 2 6 .
>
> What I want to do is, for each individual (id) to complete the values in
> chc according to a formula that depends on other variables. However, the
> number of times that each individual appears differs across individuals. I
> would like to do something such as
>
> foreach k of numlist 1/2 { /*the 2 has to be changed to the total number of
> individuals*/
> foreach w of numlist 2/T_k { /* where T_k corresponds to the number of
> times individual 2 appears*/
> replace chc=formula(`w')
> }
> }
>
> I don't know how to define T_k in the correct way such that it varies
> across individuals (so 5 for individual 1 and 4 for individual 2).
>
> Thanks,
>
> Fernando
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index