Hello all, I could use your help with some coding. I have data that I have organized into a panel type dataset. There are multiple organizations in the dataset that are observed each year. I also have a variable in this dataset that has a lot of missing values. For this variable, if it is missing in a given year, I would like to fill in the current year's value with the previous year's value. However, the previous year's value may also be missing. It may even be missing for several years back when the firm first entered the dataset (e.g., firm enters dataset in 2001, but does not have an observed value on said variable until 2007), in which case I would want the values for 2001-2006 to be changed from missing to zeros. Additionally, a value could appear on the variable when it first enters the dataset, but then be missing for two subsequent years, the value could appear again, and then be missing for next year, and so on. So the missingness is random. To sum up, I would like my variable to take on the value of the last year in which it had a value. if it does not have a value in any of the previous years, I would like it to take on a zero up until it has a value (if ever). I have created a small example below. Firm ID Year Variable Transformed to ---> Firm ID Year Variable 1 2002 . 1 2002 0 1 2003 . 1 2003 0 1 2004 1 1 2004 1 1 2005 . 1 2005 1 2 2002 2 2 2002 2 2 2003 . 2 2003 2 2 2004 3 2 2004 3 2 2005 . 2 2005 3 3 1996 . 3 1996 0 3 1997 . 3 1997 0 3 1998 . 3 1998 0 If I could get some guidance with how to code this, I would really appreciate it! To be honest, I'm not sure where to start with this. Thanks in advance.
... View more