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]

Re: st: Adjusting overlapping spell data


From   Robert Picard <[email protected]>
To   [email protected]
Subject   Re: st: Adjusting overlapping spell data
Date   Wed, 31 Jul 2013 11:48:09 -0400

Here is one way of doing this. I assume that for each id, spellnr
identifies each spell.

* --------------- begin example ---------------------------

clear
input id spellnr str7 begindate str7 enddate period unemployed
1 1 2008m4 2008m9 6 0
1 2 2009m3 2009m8 6 1
1 3 2009m9 2010m9 13 0
1 4 2010m3 2011m3 13 0
1 5 2009m7 2010m9 15 1
1 6 2011m1 2011m6 6 0
2 1 2008m4 2009m4 13 0
2 2 2009m3 2009m8 6 1
end

* translate to Stata monthly dates
gen bdate = monthly(begindate,"YM")
gen edate = monthly(enddate,"YM")
format %tm bdate edate

* expand each spell to one observation per month
expand edate-bdate+1
sort id spellnr
by id spellnr: gen spelldate = bdate + _n - 1
format %tm spelldate

* remove duplicate per month, put unemployment last
sort id spelldate unemployed spellnr
by id spelldate: keep if _n == 1

collapse (count) period (min) bdate=spelldate ///
(max) edate=spelldate (first) unemployed, by(id spellnr)
list

* --------------- end example -----------------------------


On Wed, Jul 31, 2013 at 8:34 AM, Birte Tiedemann
<[email protected]> wrote:
> Hello everybody,
>
> I am working on a panel data set (spell type) with overlapping data on times
> of employment (ym):
>
> id spellnr begindate enddate period unemployed
> 1 1 2008m4 2008m9 6 0
> 1 2 2009m3 2009m8 6 1
> 1 3 2009m9 2010m9 13 0
> 1 4 2010m3 2011m3 13 0
> 1 5 2009m7 2010m9 15 1
> 1 6 2011m1 2011m6 6 0
>
> Now I'm trying to summarize times of employment and unemployment for every
> id whi.e avoiding double counting due to  overlappings. Also employment
> should be prioritised.
>
> In the end the data is supposed to look like:
> id spellnr begindate enddate period unemployed
> 1 1 2008m4 2008m9 6 0
> 1 2 2009m3 2009m8 6 1
> 1 3 2009m9 2010m9 13 0
> 1 4 2010m10 2011m3 6 0
> 1 6 2011m4 2011m6 3 0
>
> I've no idea how to fix this in Stata. Hope you can help me. Thank you in
> advance.
>
> Regards,
> Birte
>
> *
> *   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/
*
*   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