Dear Statalist
I am running Stata 14.1. I have an unbalanced panel which follows the same set of individuals from 2009-2014. I have 99,742 obs in total. To illustrate my question, I've created the table below. The id variable is an individual identifier, so there are 3 individuals in the example table below. Var1 is a dummy. What I want to do is the following: If var1 in 2009 for a particular individual is equal to 1, I want to replace var1 by 1 for that individual for all other years that he/she was observed. For example, for individual 1, I want to replace var1 by 1 for his/her observation in 2010-2014 (i.e. all observations that the individual has in the data). For individual 2, I want to replace var1 by 1 for his observation in 2010, 2012 and 2014 (again, all of his/her observations). For individual 3, since var1=0 for him/her in 2009, there is no need to replace var1 for him/her at all.
What would be the command to implement the above changes?
Thanks for the help!
Best
Alastair
I am running Stata 14.1. I have an unbalanced panel which follows the same set of individuals from 2009-2014. I have 99,742 obs in total. To illustrate my question, I've created the table below. The id variable is an individual identifier, so there are 3 individuals in the example table below. Var1 is a dummy. What I want to do is the following: If var1 in 2009 for a particular individual is equal to 1, I want to replace var1 by 1 for that individual for all other years that he/she was observed. For example, for individual 1, I want to replace var1 by 1 for his/her observation in 2010-2014 (i.e. all observations that the individual has in the data). For individual 2, I want to replace var1 by 1 for his observation in 2010, 2012 and 2014 (again, all of his/her observations). For individual 3, since var1=0 for him/her in 2009, there is no need to replace var1 for him/her at all.
id | year | var1 |
1 | 2009 | 1 |
1 | 2010 | 0 |
1 | 2011 | 0 |
1 | 2012 | 0 |
1 | 2013 | 0 |
1 | 2014 | 0 |
2 | 2009 | 1 |
2 | 2010 | 0 |
2 | 2012 | 0 |
2 | 2014 | 0 |
3 | 2009 | 0 |
3 | 2010 | 0 |
3 | 2011 | 0 |
3 | 2013 | 0 |
3 | 2014 | 0 |
Thanks for the help!
Best
Alastair