Statalist


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

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


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

<> 

In my example below, the missing does appear for id==2, but if it does not
for you, use my last line to remedy this failure...

*************
clear*

input id    year    status      
1	1996		1		
1	1997		2		
1	1998		2		
2	1998		1		
3	2000		1		
3	2001		1		
3	2003		1		
3	2004		2		 
end

compress
list, noobs sepby(id) 

tsset id year
bys id (year): gen lagstatus=L.status
list , noobs sepby(id)

/*
if ever there was an 
issue with the singletons... 
*/ 

bys id: replace /*
 */ lagstatus=. if _N==1
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Eymann Annina
Gesendet: Dienstag, 14. Juli 2009 13:34
An: [email protected]
Betreff: st: AW: AW: panel data: problem with time-series operator

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: [email protected]
[mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Dienstag, 14. Juli 2009 12:00
An: [email protected]
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: [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/

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