Statalist The Stata Listserver


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

Re: st: Isolating a single spell


From   [email protected]
To   [email protected]
Subject   Re: st: Isolating a single spell
Date   Wed, 28 Mar 2007 14:18:46 -0500

How about this:

clear
input id  wave  str7 empstat exit   longspl
  1      1    "not emp"      0         0
  1      2        "emp"      0         0
  1      3    "not emp"      1         0
  1      4        "emp"      0         1
  1      5        "emp"      0         1
  1      6        "emp"      0         1
  1      7    "not emp"      1         0
  1      8    "not emp"      0         0
  1      9    "not emp"      0         0
   1     10   "not emp"      0         0
   1     11   "not emp"      0         0
   1     12   "not emp"      0         0
   2      1   "not emp"      0         0
   2      2       "emp"      0         1
   2      3       "emp"      0         1
   2      4       "emp"      0         1
   2      5       "emp"      0         1
   2      6       "emp"      0         1
   2      7       "emp"      0         1
   2      8       "emp"      0         1
   2      9       "emp"      0         1
   2     10       "emp"      0         1
   2     11       "emp"      0         1
   2     12       "emp"      0         1
end
gen spell = long
replace spell = 1 if long[_n-1] ==1 & exit == 1
keep if spell == 1
l, sepby(id)


Scott


----- Original Message -----
From: sara khan <[email protected]>
Date: Wednesday, March 28, 2007 6:16 am
Subject: st: Isolating a single spell
To: [email protected]

> Dear Statlisters
> 
> I was wondering if you help me in isolating a single spell from a
> multiple spell series.
> 
> I have data on employment status and I wish to extract the longest
> employment spell (indexed by longspl) and also whether the person
> exited employment in the next wave ie exit==1. In the example below,
> for person 1, I wish to keep waves 4-7 as the longest spell ended in
> an exit. For person 2, I wish to keep waves 2-12 even though the 
spell
> is censored (no exit took place).
> 
> I tried by pid: keep if longspl==1 & exit[_n+1]>=0 but this doesn't
> work. I would be grateful for suggestions.
> 
> Many thanks
> Sara
> 
> 
> +--------------------------------------+
>     id   wave   empstat   exit   longspl
> --------------------------------------
> 1.   1      1   not emp        0         0
> 2.   1      2       emp          0         0
> 3.   1      3   not emp         1         0
> 4.   1      4       emp          0         1
> 5.   1      5       emp          0         1
> 6.   1      6       emp          0         1
> 7.   1      7   not  emp       1         0
> 8.   1      8   not  emp       0         0
> 9.   1      9   not emp        0         0
> 10.   1     10   not emp      0         0
> 11.   1     11   not emp      0         0
> 12.   1     12   not emp      0         0
> --------------------------------------
> 13.   2      1   not emp      0         0
> 14.   2      2       emp      0         1
> 15.   2      3       emp      0         1
> 16.   2      4       emp      0         1
> 17.   2      5       emp      0         1
> 18.   2      6       emp      0         1
> 19.   2      7       emp      0         1
> 20.   2      8       emp      0         1
> 21.   2      9       emp      0         1
> 22.   2     10       emp      0         1
> 23.   2     11       emp      0         1
> 24.   2     12       emp      0         1
> +--------------------------------------+
> *
> *   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