Dear all,
I have a panel data set where I observe IDs over time and when each ID was treated by a policy.
I want to make a figure where I show trends in observations over time, but where I normalize my observations according the year of a policy introduction. So that, instead of the year on the x-axis I would have the year relative to the introduction on the x-axis (…,-2,-1,0,2,1).
In my example below, I therefore want to generate a NewVar that takes the value 0 when the dummy Treatment was first turned on and the values -1 and +1 in the years before and after, respectively. This will hopefully allow me to graph tendencies in another variable (not in the table) before and after the policy introduction.
Example:
My initial thoughts was that a code starting with the following could be of use:
Thank you in advance for any help.
Best regards,
Morten
And apologies for not using -dataex-. I tried but as a novice mind I was not able to create an appropriate example that could present the above question in a simple and concise manner. I will make myself more acquainted with the function for possible future questions.
I have a panel data set where I observe IDs over time and when each ID was treated by a policy.
I want to make a figure where I show trends in observations over time, but where I normalize my observations according the year of a policy introduction. So that, instead of the year on the x-axis I would have the year relative to the introduction on the x-axis (…,-2,-1,0,2,1).
In my example below, I therefore want to generate a NewVar that takes the value 0 when the dummy Treatment was first turned on and the values -1 and +1 in the years before and after, respectively. This will hopefully allow me to graph tendencies in another variable (not in the table) before and after the policy introduction.
Example:
ID | Time | Treatment | NewVar |
1 | 2005 | 0 | -1 |
1 | 2006 | 1 | 0 |
1 | 2007 | 1 | 1 |
1 | 2008 | 1 | 2 |
2 | 2005 | 0 | -2 |
2 | 2006 | 0 | -1 |
2 | 2007 | 1 | 0 |
2 | 2008 | 1 | 1 |
3 | 2005 | 0 | -3 |
3 | 2006 | 0 | -2 |
3 | 2007 | 0 | -1 |
3 | 2008 | 1 | 0 |
Code:
bysort ID (Time) : gen NewVar=0 if ...
Best regards,
Morten
And apologies for not using -dataex-. I tried but as a novice mind I was not able to create an appropriate example that could present the above question in a simple and concise manner. I will make myself more acquainted with the function for possible future questions.
Comment