Hello,
I have a dataset that is of the format group | year | value. I would like to create an additional variable "started_by_2012" that is 1 for all observations for group if "value" is 1 before or during year 2012. Here is an example dataset:
I want the value of "started_by_2012" to be 0 for all obs for group 1, 1 for all obs for group 2, 1 for all obs for group 3 (since the Value for group 3, year 2011 is 1, even though later years are 0), and 0 for all obs for group 4 (even though Value is 1 for 2013 and 2014, it was 0 prior to 2012 and in 2012).
I believe I should be using some version of egen and by (or bysort), but have not been able to find the right way to do this despite scouring the Statalist.
Thanks in advance!
Best,
Ed
I have a dataset that is of the format group | year | value. I would like to create an additional variable "started_by_2012" that is 1 for all observations for group if "value" is 1 before or during year 2012. Here is an example dataset:
Code:
Group | Year | Value | started_by_2012 1 2011 0 1 2012 0 1 2013 0 1 2014 0 2 2011 1 2 2012 1 2 2013 1 2 2014 1 3 2011 1 3 2012 0 3 2013 0 3 2014 0 4 2011 0 4 2012 0 4 2013 1 4 2014 1
I believe I should be using some version of egen and by (or bysort), but have not been able to find the right way to do this despite scouring the Statalist.
Thanks in advance!
Best,
Ed

Comment