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]

st: Double loop over unbalanced panel


From   Fernando Luco <[email protected]>
To   [email protected]
Subject   st: Double loop over unbalanced panel
Date   Fri, 2 Nov 2012 15:12:56 -0500

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index