Hello, I am trying to generate a new variable "z" that is the previous year's value of the variable "y" for every group of "x" as in the table.
As you see in the table, it should be missing at years of 2000.
I tried this code: bysort YEAR (x): egen z = l.y
But it gave me "z" values for years of 2000 that is not sensible because we don't have info for the year 1999.
Thanks
As you see in the table, it should be missing at years of 2000.
I tried this code: bysort YEAR (x): egen z = l.y
But it gave me "z" values for years of 2000 that is not sensible because we don't have info for the year 1999.
Thanks
| YEAR | x | y | z |
| 2000 | 1004 | 2.64 | |
| 2001 | 1004 | -8.299 | 2.64 |
| 2002 | 1004 | -1.807 | -8.299 |
| 2003 | 1004 | 0.494 | -1.807 |
| 2004 | 1004 | 2.536 | 0.494 |
| 2005 | 1004 | 3.592 | 2.536 |
| 2000 | 1013 | 21.864 | |
| 2001 | 1013 | -51.514 | 21.864 |
| 2002 | 1013 | -100.07 | -51.514 |
| 2003 | 1013 | -5.914 | -100.07 |
| 2004 | 1013 | 2.192 | -5.914 |
| 2005 | 1013 | 5.57 | 2.192 |

Comment