I am not quite clear what you want to do, but the
typing of the numlist and looping over it
with -forval- are unnecessary given -egen, seq()-.
numlist "1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5
6 6 6 6 6 7 7 7 7
7 8 8 8 8 8 9 9"
tokenize `r(numlist)'
local N : word count `r(numlist)'
set obs `N'
gen idfifth = .
forval i = 1 / `N' {
replace idfifth = ``i'' in `i'
}
could be replaced by
set obs 42
egen idfifth = seq(), block(5)
5 can be replaced by 3 as desired.
This can also be done in conjunction
with -by:- as desired.
Hence fire up the help for -egen-
or go to [R] egen.
Nick
[email protected]
P.S. the fact that -by- and -in- cannot
be combined is often soluble by using e.g.
-by- and -if _n == <whatever>-, but that
seems unnecessary here.
> -----Original Message-----
[email protected]
> Dear Statalisters,
> To avoid temporary external shocks effects, I have
> restructure my balanced
> panel data in a 5-years averages. I used the following
> program so far but now
> that I want to try the data set in 3-years averages, I
> found it to be a pain
> if I should type in the full numlist as before.
> I would appreciate therefore any suggestion that avoids me
> typing the numlist.
> *****************THE PROGRAM************
> version 8.1
> use datafilename1, clear
> list year if id_1, nolab /*for identifying the number of
> 5-years periods
> necessary -(panel of 7 countries)-*/
> sort id year
> capture egen tag=tag(id)
> save, replace
> clear
> numlist "1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5
> 6 6 6 6 6 7 7 7 7
> 7 8 8 8 8 8 9 9"
> tokenize `r(numlist)'
> local N : word count `r(numlist)'
> set obs `N'
> gen idfifth = .
> forval i = 1 / `N' {
> replace idfifth = ``i'' in `i' /*isn't possible to do that
> using -bysort id-?
> */
> }
> save datafilename2
> merge datafilename2 with datafilename1
> **********************END****************
> By the way the above program creates only one panel i.e.
> for 1 of the 7
> countries simply because I can't combine -in `i'- with
> -by- expression.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/