Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Recoding Question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Recoding Question
Date   Mon, 25 Apr 2005 14:47:09 +0100

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 
n.j.cox@durham.ac.uk 

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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index