Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Differencing variables

    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:

    Code:
    foreach var of varlist[list of variables] {
    gen D`var' = D.`var'
    }
    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

  • #2
    "S" is for seasonal and seems unlikely to be what you want; however, you should be able to use "D2"; see -h tsvarlist-

    Comment


    • #3
      Hi,

      Thanks for your answer. As I understood D2 gives the differences of the difference, but what I am looking for is the first differences between non-consecutive years, like newvar = var(t=2001) - var(t=1998). Can D. or any modification of it, do that?

      I don't even know how to do it "manually" hehe

      Thanks again.

      Comment


      • #4
        Ivan, try with S# (where # is 2 for 2011-2009 and 3 for 2000-1997).
        D2, as per the manual, is " D2. difference of difference (x_t - 2x_t-1 + x_t-2)" , which you probably don't want (but is a very common mistake).

        Best,
        S

        Comment


        • #5
          Sergio! Great! I will use it right away.

          Thanks for your answer.

          Iván

          Comment

          Working...
          X