Announcement

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

  • Create indicator function of previous years in variable

    I'm doing a diff-in-diff with multiple years in the pre-and post periods, and where membership in the treatment group varies over time. I have an dummy variable indicating whether a municipality is in the treatment group for each year. What I want to do is fix the list of all municipalities that were in the treatment group during the pre-period, so that I have a fixed treatment group during the treatment period itself.

    Specifically, I have an indicator variable `treatment` that equals 1 if a municipality is in the treatment group for each of the years 2010-2013. I want to add to `treatment` the following indicator function for the each of the years 2014 and 2015:
    Code:
    fixed_treatment = 1{treatment(2010)==1 or treatment(2011)==1 or treatment(2012)==1 or treatment(2013)==1}
    In matlab I could just define treatment(2014:2015) = fixed_treatment, but I don't know how to do that in Stata.

  • #2
    I am not clear what you want here. A data example (see FAQ Advice #12) would help.

    But you can count like this

    Code:
    egen ntreat1 = total(treatment == 1 & inrange(year, 2010, 2013)), by(municipality)
    Convert to an indicator by

    Code:
    gen itreat1 = ntreat1 > 0
    That will be defined for all observations for each municipality.

    You can use egen functions other than total().

    If that doesn't answer the question, please give a data-centred example.

    See also http://www.stata-journal.com/article...article=dm0055 for a review of technique.
    Last edited by Nick Cox; 29 Sep 2016, 01:39.

    Comment

    Working...
    X