Statalist The Stata Listserver


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

Fwd: st: Generating an indicator of occurance of an event during the interval


From   "Sergio Correia" <[email protected]>
To   [email protected]
Subject   Fwd: st: Generating an indicator of occurance of an event during the interval
Date   Fri, 15 Dec 2006 04:44:46 -0500

This works but I'm pretty sure its not the best way:

* CODE:
gen xyz = outcome==4
replace xyz = (xyz[_n-1]==1 | xyz ==1) & (outcome!=2)
gen indicator = xyz[_n-1]==1 if order>1


Line 1 is straightforward.
Line 2 is 1 if there has been an outcome of 4 since the last success
(and we are not on a successful outcome)
Line 3 is also simple

The last two lines can be merged but that would make them harder to
understand. Again, I'm sure there are better answers (maybe egen, sum
or more complex gens).

Regards,
Sergio

On 12/15/06, Le Wang <[email protected]> wrote:
Hi there,

Thanks for your time in advance.

I have a data set containing four variables

(1) household id (2) event id (3) event outcome (4) order of success

event outcomes can takes on values of 1,2,3,4; if the event outcome is
2, it is successful and ordered according to the timing of occurance
of the success (recorded in the fourth variable "order of success").
The data looks like what follows,

-----------------------------------------------------------------------------------------
id      eventid outcome order of success
1       1       1       0
1       2       2       1
1       3       4       0
1       4       2       2
2       1       2       1
2       2       4       0
2       3       4       0
2       4       3       0
2       5       2       2
3       1       2       1
3       2       2       2
3       3       1       0
3       4       4       0
3       5       2       3
.
.
.
.
-----------------------------------------------------------------------------------------

What I wanna do is to create a variable for obs with the order of
success greater than 1; this variable indicates whether or not there
exists an event outcome equal to 4 during the interval between this
success and the previous success. The final data for the example
should look like the following

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

id      eventid outcome order of success        indicator
1       1       1       0       .
1       2       2       1       .
1       3       4       0       .
1       4       2       2       1
2       1       2       1       .
2       2       4       0       .
2       3       4       0       .
2       4       3       0       .
2       5       2       2       1
3       1       2       1       .
3       2       2       2       0
3       3       1       0       .
3       4       4       0       .
3       5       2       3       1
.
.
.
.
-----------------------------------------------------------------------------------------

Le

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Le Wang, Ph.D.
Minnesota Population Center
University of Minnesota
(o) 612-624-5818
*
*   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index