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

Re: st: Date: Sat, 7 Dec 2002 15:35:59 +0100

From   "Erik Ø. Sørensen" <>
Subject   Re: st: Date: Sat, 7 Dec 2002 15:35:59 +0100
Date   Sat, 7 Dec 2002 10:53:20 -0500

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.

the code i have used is
. bys progid: gen np = _n
. 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?

best regards
Erik Ø. Sørensen, <>.
phd student (economics), Norwegian School of Economics.
currently visiting Queen's University, Kingston, Ontario.

* For searches and help try:

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