Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Count variable


From   Felipe Botero <[email protected]>
To   [email protected]
Subject   st: Count variable
Date   Mon, 19 Mar 2007 10:56:55 -0500

I have data on congressional careers and need to create a variable that counts the number of *consecutive* terms served in the same office.

 

I used the following code but it didn't do the trick:

 

sort id office electionyear

by id office: gen count = cond(win==0,0,sum(win))

list id office win count...

 

� +---------------------------------+

� |� id�� office��� win������ count |

� |---------------------------------|

� | 153��������� 1���� 0��������� 0 |

� | 153��������� 1���� 1 ���������1 |

� | 153��������� 1���� 0��������� 0 |

� | 153��������� 1���� 1��������� 2 |� <-- should start again with 1

� | 153��������� 1���� 1��������� 3 |

� | 153��������� 1���� 1��������� 4 |

� +---------------------------------+

 

The problem is that I need the counter to start back at 1 after each occurrence of win==0.

 

Any ideas on how to do this?

 

Thanks,

 

 

 

------------------------------------------------------------

Felipe Botero
Profesor Asistente
Departamento de Ciencia Pol�tica

Universidad de los Andes

Bogot�, Colombia
Tel: +57(1) 339 4949 x 2615
[email protected]
http://wwwprof.uniandes.edu.co/~fbotero
------------------------------------------------------------

 




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