Statalist


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

st: RE: create a new time variable from an old one


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: create a new time variable from an old one
Date   Tue, 27 Jan 2009 23:28:35 -0000

That appears to be the right command. Note also 

bysort id (t) : gen T2 = t[_n+1]

although that is not exactly equivalent. 

Nick 
[email protected] 

Carlos del Carpio


I have a dataset with an id variable, and a time variable with
distinct values for each observation, like this:

id       t
1   1999m12
1   2000m1
1   2000m2
2   2004m7
2   2004m8
3   2001m2
...

I would like to create a new variable, t2, with the next corresponding
time value for each id. The result would look like this:

id       t               t2
1   1999m12   2000m1
1   2000m1     2000m2
1   2000m2         .
2   2004m7     2004m8
2   2004m8         .
3   2001m2         .
...

I tried "gen t2=f.t" after "xtset id t", but it only returned empty
values. Is there any way to do this for a large dataset?

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