Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# RE: st: Calculating months since entry into risk set by actor_id and month

 From Erik Aadland To Subject RE: st: Calculating months since entry into risk set by actor_id and month Date Mon, 3 Sep 2012 09:07:19 +0000

```Thank you so much, Nick.

Kind regards,
Erik.

> Date: Fri, 31 Aug 2012 15:42:01 +0100
> Subject: Re: st: Calculating months since entry into risk set by actor_id and month
> From: njcoxstata@gmail.com
> To: statalist@hsphsun2.harvard.edu
>
> The variable -wanted- (NO SHOUTING PLEASE ERIK) is in this example just
>
> bysort actor_id (month) : gen wanted = _n - 1
>
> I don't see what you desire if there is right censoring at the end,
> but some technique is indicated by
>
> bysort actor_id (month) : gen wanted = cond(event[_N] == 1, _n - 1, .)
>
> Under -by:- the final value of -event- for each actor is just -event[_N]-.
>
> Nick
>
> On Fri, Aug 31, 2012 at 3:23 PM, Erik Aadland <erikaadland@hotmail.com> wrote:
>
> I have an event history dataset in which actors enter the dataset at
> different points in time. Entry into the dataset constitutes the onset
> of risk, or "contracting the infection" if you will, for that actor.
> From this point on, I follow this actor monthly (MONTH) tracking
> whether the actor "gets sick" or not (EVENT). If the actor actor "gets
> sick", the actor is given an event score 1 as opposed to 0. If the
> actor never gets "sick" the actor is right censored at the end of the
> observation period.
> > By ACTOR_ID MONTH, I want to calculate the number of months since ACTOR_ID entered the risk set (or "contracted the infection) yielding the variable WANTED.
> > The dataset looks like this:
> > MONTH ACTOR_ID EVENT WANTED
> > 1 1 0 0
> > 2 1 0 1
> > 3 1 0 2
> > 4 1 1 3
> > .. .. ..
> > 1 2 0 0
> > 2 2 1 1
> > .. .. ..
> > 3 3 0 0
> > 4 3 0 1
> > 5 3 0 2
> > 6 3 0 3
> > 7 3 0 4
> > 8 3 1 5
> > Any input on this problem would be very much appreciated.
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```