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 Sanders <[email protected]>
To   [email protected]
Subject   Re: st: shifting status variable
Date   Thu, 18 Nov 2010 11:32:37 -0800

Vincenzo,

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)


--
Nicholas J. Sanders, Ph.D.
Postdoctoral Fellow
Stanford Institute for Economic Policy Research
366 Galvez St, Room 228
Stanford, CA 94305

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

> Dear statlisters,
> 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.
> 
> Any help is appreciated.
> 
> Many thanks,
> *
> *   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/


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