Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: panel data: problem with time-series operator
Date   Tue, 14 Jul 2009 11:59:38 +0200

<> 

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: [email protected]
[mailto:[email protected]] Im Auftrag von Eymann Annina
Gesendet: Dienstag, 14. Juli 2009 11:43
An: [email protected]
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/



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