Dear experts,
I am working with a panel dataset (from 1946 to 2015) that contains among other variables a dummy equal to 1 for each year a country is at war.
I am trying to create a variable that records peace. In essence, the peace variable is supposed to start with 1 when a war ends (thus the war dummy would be 0), and continue to have consecutive values (2, 3, 4 etc.) until a new war starts (war = 1), and then peace gets values of 0 until that new war ends, and so on. Thus, it measures the years of peace from the time a war stops, and up until a new war starts.
I have created the peace variable itself, but I have some issues with it. Below is the code I used to create the peace variable.
peace - peace variable
owar - war dummy
lowar - lag of war dummy
The problem with this peace variable is that if a country, say Afghanistan, begins in the dataset (at 1946) without a war, I want it to have values of 0 for the peace variable until the first war of that country starts, and then when the war ends I want the peace variable to continue normally. However the variable I created counts the first years of any country (1946 and up) as "post-war" peace years and assigns consecutive values starting from 1 until a war starts.
An example to make it a bit clearer:
Unfortunately the first wars of all the countries start at different times, so I can't specify a certain time that would encompass all first wars of each country.
Essentially, I want the countries and years before the first wars start to have 0 values for peace, and then once the first wars start the peace variable continues normally (consecutively).
However, I can't figure out how to make that distinction in Stata.
In the worst case scenario, I would have to fix them manually.
I hope I've made myself clear enough, and if not, I apologize.
Thank you in advance!
I am working with a panel dataset (from 1946 to 2015) that contains among other variables a dummy equal to 1 for each year a country is at war.
I am trying to create a variable that records peace. In essence, the peace variable is supposed to start with 1 when a war ends (thus the war dummy would be 0), and continue to have consecutive values (2, 3, 4 etc.) until a new war starts (war = 1), and then peace gets values of 0 until that new war ends, and so on. Thus, it measures the years of peace from the time a war stops, and up until a new war starts.
I have created the peace variable itself, but I have some issues with it. Below is the code I used to create the peace variable.
Code:
//Generating Peace Variable gen peace = 1 replace peace = 0 if owar==1 by country, sort: replace peace = peace + peace[_n-1] if lowar==0 replace peace = 0 if peace!=0 & owar==1
owar - war dummy
lowar - lag of war dummy
The problem with this peace variable is that if a country, say Afghanistan, begins in the dataset (at 1946) without a war, I want it to have values of 0 for the peace variable until the first war of that country starts, and then when the war ends I want the peace variable to continue normally. However the variable I created counts the first years of any country (1946 and up) as "post-war" peace years and assigns consecutive values starting from 1 until a war starts.
An example to make it a bit clearer:
country | year | owar | my "peace" variable | new "peace" variable I want |
Afghanistan | 1946 | 0 | 1 | 0 |
Afghanistan | 1947 | 0 | 2 | 0 |
Afghanistan | 1948 | 1 | 0 | 0 |
Afghanistan | 1949 | 0 | 1 | 1 |
Angola | 1946 | 0 | 1 | 0 |
Angola | 1947 | 1 | 0 | 0 |
Angola | 1948 | 0 | 1 | 1 |
Angola | 1949 | 0 | 2 | 2 |
Essentially, I want the countries and years before the first wars start to have 0 values for peace, and then once the first wars start the peace variable continues normally (consecutively).
However, I can't figure out how to make that distinction in Stata.
In the worst case scenario, I would have to fix them manually.
I hope I've made myself clear enough, and if not, I apologize.
Thank you in advance!
Comment