Announcement

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

  • DiD: Units switch in and out of treatment

    Hello StataList, first time poster, long time admirer of your work.

    I am running diff-in-diffs with panel data using xtdidregress (Stata 18), and along with the output I recieve the following note:
    Treatment occurs at different times and estimation sample contains units that switch in and out of treatment.

    It is correct that treatment occurs at different times, but after several checks in and out of Stata, it does not appear that the sample has units that switch in and out of treatment.

    One such check is as follows, with fips being the unit identifier and hs_treat being the treatment var:
    Code:
    gen switch = .
    by fips: replace switch = 1 if hs_treat == 0 & hs_treat[n-1] == 1 & !missing(hs_treat)
    This generates missing values for all observations, which leads me to believe no units switch..

    Am I spotting these changes correctly? Or can someone tell me why I'm getting that message? I can't seem to find an answer online.

    Thanks in advance!

  • #2
    I don't think your way of identifying switches will catch them all, because a sequence like hs_treat = 1 followed by missing value followed by 0 will be missed. So I would do it this way:
    Code:
    preserve
    drop if missing(hs_treat)
    by fips (TIMEVAR), sort: gen running_sum = sum(hs_treat)
    by fips: assert hs_treat == 1 if running_sum[_n-1] > 0
    restore
    Replace TIMEVAR by the actual name of your time variable.

    This code will check whether in every fips, hs_treat, once it becomes 1, it remains 1 thereafter (except that missing values of hs_treat are skipped over). If your data is what you think it is, this code will run without leaving any error messages. If you have any switches, however, you will get an error message from the -assert- command.
    Last edited by Clyde Schechter; 21 Feb 2025, 13:01.

    Comment

    Working...
    X