Announcement

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

  • how can I generate a dummy variable based on another dummy variable?

    Hi all,

    my data pretty much looks like the following

    Code:
    Year company var1
    1999 CompanyA 0
    2000 CompanyA 1
    2001 CompanyA 0
    2002 CompanyA 0
    2010 CompanyB 0
    2011 CompanyB 1
    2012 CompanyB 0 
    2013 CompanyB 0
    What I want to do is I want to create a new dummy variable which is one year before and two years later from the current dummy. So I want it looks like the following:

    Code:
    Year Company var1 var2
    1999 CompanyA 0 1
    2000 CompanyA 1 0
    2001 CompanyA 0 0 
    2002 CompanyA 0 1
    2010 CompanyB 0 1
    2011 CompanyB 1 0 
    2012 CompanyB 0 0
    2013 CompanyB 0 1
    How can I do this?

    Thanks!

  • #2
    Hey Hakan, I think you're looking for time-series operators. You may have to put var2 together in two steps. I would first declare your data as a panel using
    Code:
    xtset company year
    and then add a new variable using the operators. The first is a single wave lag and so looks like this
    Code:
    gen var2 = L.var1
    the second is a two wave lead and so would look something like this
    Code:
    gen var3 = FF.var1
    . There's more info here https://www.stata.com/help13.cgi?xtset.

    Comment

    Working...
    X