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

st: panel data: problem with time-series operator

From   Eymann Annina <>
To   "" <>
Subject   st: panel data: problem with time-series operator
Date   Tue, 14 Jul 2009 11:42:43 +0200

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:

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