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: shifting status variable


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: shifting status variable
Date   Fri, 19 Nov 2010 16:55:14 +0000

There is at least one small refinement here. Suppose someone got divorced in the first year of record. Then for that observation -separati- is 1 but -separati[_n-1]- evaluates to missing. Thus the condition for divorced this year should be 

separati == 1   &     separati[_n-1] == 0 | _n == 1

where the extra possibility _n == 1, under the aegis of -by:-, identifies the first observation of record. 

More general technique is discussed in 

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/07   SJ 7(2):249--265                                 (no commands)
        shows how to handle spells with complete control over
        spell specification

and (independently) encoded within -tsspell- from SSC. Either of these two sources could be of use if interest extends to e.g. lengths of time spent divorced. 

Nick 
[email protected] 

Nick Sanders

This is a bit clunky, but it should do the trick (I imagine someone else has a cleaner way out there). Note this can't identify those who divorced in 2004, but you can't do that with your data anyway.

*Sort into individual/year order
sort pb030 pb010

*Generate indicator for "Changed status this year"
by pb030: gen divorced = (separati == 1 & separati[_n-1] == 0)

*Generate indicators for divorced in difference years
foreach year in 2005 2006 2007 {
	gen divorced_`year'  = (divorced == 1 & pb010 == `year')
}

That should do it (assuming you have no missing data)

On Nov 18, 2010, at 11:23 AM, Vincenzo Carrieri wrote:

> I would like to create a dummy variable equals to one for persons
> which decide to divorce in a given year.
> I have a panel data with the following key variables:
> 
> pb010=year variable (2004, 2005, 2006, 2007)
> separati=dummy variable equal to one for divorced persons (marital
> status=divorced)
> pb030=personal id
> 
> My question is: How is it possible to create a variable which takes
> the value one if the person changes his marital status (from married
> to divorced) in the year 2005 (with respect to 2004), 2006 (with
> respect to 2005) and 2007 (with respect to 2006)?
> 
> My final concern is to build 3 variables: people divorced in 2005,
> people divorced in 2006 and people divorced in 2007.
> 

*
*   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/


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