Thanks for the plug. These references may also be relevant:
SJ-7-4 dm0033 . . . . . . Speaking Stata: Counting groups, especially
panels
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N.
J. Cox
Q4/07 SJ 7(4):571--581 (no
commands)
discusses how to count panels through reduction commands
or through tabulation commands and how to overcome
problems that do not yield easily to these approaches
SJ-7-3 pr0033 . . . . . . . . . . . . . . Stata tip 51: Events in
intervals
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N.
J. Cox
Q3/07 SJ 7(3):440--443 (no
commands)
tip for counting or summarizing irregularly spaced
events in intervals
Nick
[email protected]
Martin Weiss
I hope you can take it from here, with the added help of Nick`s
http://www.stata-journal.com/article.html?article=dm0029
[email protected]
First of all thanks a lot! It is definitely a good start.
But, if I set in your code the window instead of "begin-6" to a longer
period, say "begin-31" than the window will be overwritten by the
previous
employment spells. In addition, it also does not count the number of
weeks
correctly until a previous emloyment spells starts.
Does somebody see a solution to the problem?
From: "Martin Weiss" <[email protected]>
> -egen- happily accepts expressions for some of its functions, so let`s
try
> and use that...
>
> ***
>
> clear*
>
> input Id spell begin end status:mylabel , auto
> 1 1 12 14 empl
> 1 2 15 46 unempl
> 1 3 47 52 sick
> 1 4 59 66 unempl
> 1 5 70 80 empl
> 1 6 81 88 unempl
> 1 7 89 105 empl
> 2 1 14 21 unempl
> 2 2 55 59 sick
> 2 3 61 109 empl
> 2 4 110 115 unempl
> 2 5 116 200 empl
> end
> compress
>
> bys Id: gen byte newspell=sum((status[_n-1]==1)*(_n!=1))
> bys Id newsp: egen window=total((begin-6)*(_n==_N)*(_n!=1))
> bys Id newsp: /*
> */egen weeks=total((status==2)*/*
> */(begin<=window)*(end>=window)*/*
> */(end-window))
> l, sepby(Id news)
> ***
> From: <[email protected]>
>> I have the following panel dataset:
>>
>> Id spell begin end status
>> 1 1 12 14 empl
>> 1 2 15 46 unempl
>> 1 3 47 52 sick
>> 1 4 59 66 unempl
>> 1 5 70 80 empl
>> 1 6 81 88 unempl
>> 1 7 89 105 empl
>> 2 1 14 21 unempl
>> 2 2 55 59 sick
>> 2 3 61 109 empl
>> 2 4 110 115 unempl
>> 2 5 116 200 empl
>>
>>
>> I want now to calculate for each spell and person how many weeks the
>> person has been e.g. unemployed during the past 31 weeks (6 month)
when
>> he/she enters employment.
>>
>> The problem is not to calculate the entire weeks spent in
unemployment
>> but only the number of weeks during a fixed period of time.
*
* 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/