Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Calculating span exculsive of the current spell


From   Kai Huang <[email protected]>
To   "[email protected]" <[email protected]>
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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index