I am working with panel data and I want to generate the variable "polstability" which measures the polical stability of countries. It should be based on my variable polity, which is given in my dataset. More precisely, polstabiltiy should be based on a difference between the values of polity. That is, if there occurred a change of more than 3 points in the last 3 years, then the variable polstability should give a value of 0. On the other hand, if such a change does not occur, the variable polstability should add1 to the value in the previous year. I hope the idea becomes more clear with this example (with fictional data):
country | ccode | year | polity | polstability |
US | 1 | 2000 | 19 | 13 |
US | 1 | 2001 | 19 | 14 |
US | 1 | 2002 | 18 | 15 |
US | 1 | 2003 | 17 | 16 |
US | 1 | 2004 | 19 | 17 |
Albania | 2 | 2000 | 9 | 8 |
Albania | 2 | 2001 | 9 | 9 |
Albania | 2 | 2002 | 9 | 10 |
Albania | 2 | 2003 | 3 | 0 |
Albania | 2 | 2004 | 4 | 1 |
Albania | 2 | 2005 | 5 | 2 |
Albania | 2 | 2006 | 3 | 3 |
Albania | 2 | 2007 | 1 | 0 |
Albania | 2 | 2008 | 1 | 1 |
I do not know, how to generate such a variable & I hope someone can give me advice.
As some of you might have noticed, my variable follows the logic of the durable variable in the PolityIV dataset. I know, I could try to use their variable and merge it with my dataset but I rather want to understand how to do it by myself in order to improve my STATA skills for the future.
Thanks!
0 Response to Panel data: Generate A Variable with values based on difference in other variable
Post a Comment