Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Kai Huang <demonsecret@hotmail.com.hk> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | st: Calculating span exculsive of the current spell |
Date | Mon, 10 Jun 2013 12:50:19 +0000 |
Dear all, I have a spell dataset as follows: ID Start End X 433 1987 1990 1 433 1990 1992 1 433 1992 1994 2 433 1994 1997 1 433 1997 2000 3 433 2000 2004 2 433 2004 2006 3 where x is a dummy indicating activity status. I have the following commands for calculating the span of the respondent in each status: gen span=End-Start by ID: gen span1=sum(span) if X==1 by ID: gen span2=sum(span) if X==2 by ID: gen span3=sum(span) if X==2 drop duration 3 new variables are added to the dataset: ID Start End X span1 span2 span3 433 1987 1990 1 3 . . 433 1990 1992 1 5 . . 433 1992 1994 2 . 2 . 433 1994 1997 1 7 . . 433 1997 2000 3 . . 3 433 2000 2004 2 . 6 . 433 2004 2006 3 . . 5 The above commands calculate the span including the current spell. I would like to know how can we calculate the span excluding the current spell so that we have the following values instead: ID Start End X span1 span2 span3 433 1987 1990 1 0 . . 433 1990 1992 1 3 . . 433 1992 1994 2 . 0 . 433 1994 1997 1 5 . . 433 1997 2000 3 . . 0 433 2000 2004 2 . 2 . 433 2004 2006 3 . . 3 Thank you very much in advance. Best regards, Kai Huang * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/