Try this:
1) create example file
set obs 30
gen year=1990+_n
2) answer
gen dummy = ceil(_n/5)
The trick is in using the ceil function with the _n variable.
Sergio
On 11/10/05, Lynda Zhang <[email protected]> wrote:
> I have a variable Year:
> ...
> 1991
> 1992
> 1993
> 1994
> 1995
> 1996
> 1997
> 1998
> 1999
> 2000
> ...
>
> How do I create one dummy variable for each 5-year interval with one
> command.
>
> Typically I can get it manually by generating one dummy at a time
> gen year1=1 if year>=1991 & year<=1995
> ...
>
> or using Recode:
> gen yr=year
> recode yr (1991/1995=1)(1996/2000=2)
> tab yr, g(y)
>
> Thanks a lot!
> Lynda
>
>
>
*
* 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/