Announcement

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

  • how to find the first year of treatment implementation and create the post treatment variable

    Hi, in the following code replicated, I want to find the first year that firm received the treatment so that I may create the post treatment variable (dummy) for each firm.
    The following codes generate errors because first() and fillmissing functions may be not be default command. Is there any way to make the following code work or alternative way of doing this job? Thank you.

    Code:
    sort firmid year gen temp=year if amount_999 > 0
    bysort firmid: egen first_year_999=first(temp)
    bysort firmid: fillmissing first_year_999, with(any)
    label var first_year_999 "first year receiving 999 funding"
    gen dummy_999_post=1 if year>=first_year_999
    replace dummy_999_post=0 if dummy_999_post==.
    label var dummy_999_post "Dummy variable =1 from the first year receiving 999 funding and thereafter"
    drop temp

  • #2
    The -first()- function mentioned in the code you show is not among the official Stata -egen- functions. But it can be found in the -egenmore- package, available from SSC.

    -fillmissing- is also not part of official Stata. -search fillmissing- turns up two possibilities. The syntax shown in the code is compatible with the one in SSC and would appear to do the same. The other -fillmissing- does not have an online help file available without installing it, so I cannot say anything more about it.

    That said, the code is unnecessarily complicated for its purpose. You can accomplish the same thing simply using the following code, which consists exclusively of official Stata commands:
    Code:
    by firmid (year), sort: egen first_year_999 = min(cond(amount_999 > 0, year, .))
    label var first_year_999 "first year receiving 999 funding"
    gen dummy_999_post = (year >= first_year_999) if !missing(first_year_999, year)
    label var dummy_999_post "Dummy variable =1 from the first year receiving 999 funding and thereafter"

    Comment


    • #3
      Clyde Schechter Thanks so much!

      Comment

      Working...
      X