Statalist


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

st: create a new time variable from an old one


From   Carlos del Carpio <[email protected]>
To   [email protected]
Subject   st: create a new time variable from an old one
Date   Tue, 27 Jan 2009 18:16:35 -0500

Hi,

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?

Thanks

Carlos del Carpio
*
*   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