[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Eymann Annina <Annina.Eymann@ehb-schweiz.ch> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
st: AW: AW: panel data: problem with time-series operator |

Date |
Tue, 14 Jul 2009 13:33:30 +0200 |

Thank you for your answer, Martin. But I am not sure if I understood your suggestion in the right way. The idea you present does not produce my desired result. Maybe I was not clear enough. The data set looks like the following and I like to create the change-variable only for those observations where there are at least two consecutive years (without gaps). id year status change 1 1996 1 . 1 1997 2 1 1 1998 2 0 2 1998 1 . 3 2000 1 . 3 2001 1 0 3 2003 1 . 3 2004 2 1 ... The time-series operators do not produce missings for individuals with only one year of observations, whereas the [_n-1]-type does not take care of non-consecutive years. Sorry to bother you all with that supposedly trivial problem. Best regards, Annina -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss Gesendet: Dienstag, 14. Juli 2009 12:00 An: statalist@hsphsun2.harvard.edu Betreff: st: AW: panel data: problem with time-series operator <> As ************* help tsvarlist ************* says: " The time-series operators respect the time variable." So gaps in your dataset (years in which the -status- is unobserved) will impact the result of the lag operation, but not the _n-version, as you can observe here: ************* use http://www.stata-press.com/data/r10/union.dta, clear bys idcode (year): gen lagunion=union[_n-1] l idcode year union L.union lagunion in 1/100, noo sepby(id) ************* HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Eymann Annina Gesendet: Dienstag, 14. Juli 2009 11:43 An: statalist@hsphsun2.harvard.edu Betreff: st: panel data: problem with time-series operator Dear Statalisters I am having trouble when using time-series operators on my panel data set. The data set is tsset id year, yet the panel is unbalanced. Each individual is observed 1 to 5 times. The years cover a time span of 13 years. I am interested in the change of labor market status, thus I want to be able to follow individuals from time (t) to time (t+1) or more. Since many users strongly suggest to use the time-series operators instead of [_n-1] etc, I would like to apply the second way of coding. Here are my two versions: Version 1 sort id year gen change=0 if id==id[_n-1] & status==status[_n-1] replace change=1 if id==id[_n-1] & status!=status[_n-1] Version 2 tsset id year by id: gen change=0 if status==L.status by id: replace change=1 if status!=L.status The problem is that the result of the second version is quite different to the first one. What is wrong? In version 2, individuals who were only observed once also get a 1 instead of the desired missing. Why? I seem to miss an important point... Note that I do not want to create something like - by id: gen leadstatus=F.status -. Thank you very much for your help, suggestions, ect. Best regards, Annina * * 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/ * * 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/

**Follow-Ups**:**st: AW: AW: AW: panel data: problem with time-series operator***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: panel data: problem with time-series operator***From:*Eymann Annina <Annina.Eymann@ehb-schweiz.ch>

**st: AW: panel data: problem with time-series operator***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: Treatment for Missing Values - What Options ?** - Next by Date:
**st: AW: AW: AW: panel data: problem with time-series operator** - Previous by thread:
**st: AW: panel data: problem with time-series operator** - Next by thread:
**st: AW: AW: AW: panel data: problem with time-series operator** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |