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

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


From   "Erik Ø. Sørensen" <sameos@mac.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: AW: st: Date: Sat, 7 Dec 2002 15:35:59 +0100
Date   Sat, 7 Dec 2002 13:50:11 -0500

On lørdag, des 7, 2002, at 11:57 America/Montreal, Sophie Barthel wrote:
One question regarding the running code: will that only count progid when it takes on the value 0 as that is what I need?
I may have misunderstood and used 1 as the exciting case.

The idea is that bys: sorts the data and constructs the variable np that counts the observations _within_ progid. Assume there are 241 with progid==0 and 258 with progid==1. The dataset after the "bys..." line looks something like this:

progid np
0 1
0 2
...
0 241
1 1
1 2
1 258

Now you construct a variable from these two variables. If you want all the first 200 with progid==0 to take on the value of 0, and else 1, I would do

gen byte y = 1 - (progid==0 & np<=200)

The () part is 1 if the argument is true, else it is zero. So y will be 1 if either progid==1 or np>200 and 0 otherwise. Which seems to be what you want.


entries has exceeded 200, y will take the value 0?
basically my next step would then be to say

stset progtm, failure(y)
This may not work well with my solution: You have to be very careful about the sort order. I would make sure that you do sort appropriately.

. sort progtm
. gen byte progid0= (progid==0) * is equal to 1 if true
. gen long np0 = sum(progid0) * is the #observation of progid==0
. gen y = 1 - (progid==0 & np0<=200)
. drop np0 progid0

Then you are sure that the first 200 as they appear in time are marked with 0. If all of this has to be made true for every person, say, with identification variable pid, the sort has to be sort pid progtm and the generation of np0 has to be "by pid: gen np0=sum(progid0)". Everything else should work.



Erik
--
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:
* 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