Similar questions have started several threads
in the last few weeks.
If you
. tsset Country Year
then -tsspell- from SSC will do this for you. After
. tsspell, cond(Rev == 0)
the new variable -_spell- will be exactly what you seek.
Alternatively, from first principles we can go
bysort Country (Year):
gen code = cond(Rev == 1, 0, sum(Rev == 0 & Rev[_n-1] != 0))
Nick
[email protected]
Geoffrey D. Peterson
> I am struggling to generate a new variable that SEEMS like it
> should be easy
> but has been driving me nuts.
>
> I am working with data that looks like the following:
> Country Year Democracy Score Rev?
> 1 1999 8 0
> 1 2000 8 1
> 1 2001 2 0
> 1 2002 2 0
> 1 2003 2 0
> 1 2004 2 0
> 2 1999 6 0
> 2 2000 6 0
> 2 2001 6 1
> 2 2002 9 0
> 2 2003 9 1
> 2 2004 2 0
>
> What I am trying to do is find a way to generate a variable
> that will code
> as "1" for before the first revolution, "0" during ANY
> revolution, and code
> the sequence of the revolution. For example, I would want the
> data above to
> look like this:
>
> Country Year Democracy Score Rev? Code
> 1 1999 8
> 0 1
> 1 2000 8
> 1 0
> 1 2001 2
> 0 2
> 1 2002 2
> 0 2
> 1 2003 2
> 0 2
> 1 2004 2
> 0 2
> 2 1999 6
> 0 1
> 2 2000 6
> 0 1
> 2 2001 6
> 1 0
> 2 2002 9
> 0 2
> 2 2003 9
> 1 0
> 2 2004 2
> 0 3
>
> The goal is to be able to compare the distributions for the
> democracy scores
> before and after the various revolutions. Is there a simple
> way to do this?
*
* 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/