[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Date: Sat, 7 Dec 2002 15:35:59 +0100
On lørdag, des 7, 2002, at 10:35 America/Montreal, Sophie Barthel wrote:
i have currently got a variable which can take the values 1 or 0. i
want to create a new variable which takes the values of the old one
but which will be equal to 0 once the number of 0 values in the old
variable exceeds 200.
. bys progid: gen np = _n
the code i have used is
. gen byte y = (progid==1 & np <= 200)
. drop np
Probably you would like to do the "bys progid" with some other variable
as well, such as personal id or whatever. The idea is that you sort on
the progid, and takes a running count within the progid (or possibly
'progid pid') group, and generates y as 1 only if progid is 1 and the
running number is less than or equal to 200. I am not sure I understand
the syntax of what you proposed. Does Stata accept it?
Erik Ø. Sørensen, <http://www.geocities.com/erik_oiolf/>.
phd student (economics), Norwegian School of Economics.
currently visiting Queen's University, Kingston, Ontario.
* For searches and help try: