Dear Statalist,


For a panel of 60 countries I need to calculate the average for every 'segment' of time of the budget surplus for that country. The data that I already have are the country, year, surplus and break year. (The break year is determined by a Bai and Perron structural break filter in another program and I entered them manually already for all countries). Now I need to know if the average surplus in the segment after the break is larger than the average surplus before the break (if it is, the country implements a consolidation).

Therefore, I am trying to make the new 'segment' variable based on the 'break' variable. Segment is 1, and if there is a break, the following year start a new segment. Having the segment variable will allow me to quickly compare the averages of segments.

Is there a way to make Stata create this segment variable?

country year surplus break segment
Australia 1990 1 0 1
Australia 1991 -1 0 1
Australia 1992 -2 0 1
Australia 1995 -2 0 1
Australia 1996 -2 1 1
Australia 1997 -2 0 2
Australia 1998 4 0 2
Australia 1999 4 0 2
Australia 2000 4 0 2
Australia 2001 3 1 2
Australia 2002 3 0 3
Australia 2003 4 0 3
Australia 2004 4 0 3
Australia 2005 4 0 3