Hi to all,
I have panel data since 1988 to 2011 and in order to use a Differences in Differences (DiD) strategy, I need to generate a variable that equals the change between two years of the panel. At first, I used the following code:
But later I realized that the variable generated by Stata was not what I was trying to get, because I am doing something wrong. The D. modifying option of the "generate" function gives me only the change of variable between 1 year (i.e. D.var = var(t=2011) - var(t=2010) and so on), but I need the change between electoral years, that is every two years (i.e. newvar = var(t=2011) - var(t=2009) and so on) or in different ways like var(t=2000) - var(t=1997).
There is a way I can do this using a loop? I have tried .S option, but I am not having good results.
Thanks in advance,
Iván Higuera
I have panel data since 1988 to 2011 and in order to use a Differences in Differences (DiD) strategy, I need to generate a variable that equals the change between two years of the panel. At first, I used the following code:
Code:
foreach var of varlist[list of variables] { gen D`var' = D.`var' }
There is a way I can do this using a loop? I have tried .S option, but I am not having good results.
Thanks in advance,
Iván Higuera
Comment