Announcement

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

  • Issue with DiD Analysis using xtdidregress

    Good Afternoon,
    I need to evaluate the effect of an event taken place in 2014 in a set of towns. My dataset is panel. I have 200 towns, 101 of which treated and 101 in the control group. I have, for each town 12 rows with the corresponding data for the 12 years between 2012 and 2023. I have created a dummy variable for time (time) and one for being treated (treatment). I have tried to run the DiD using the simple reg command, once I had created a variable time*treatment and it works. Now, I wanted to try to use the xtdidregress as it takes care of fixed effects, the panel effects, and it clusters standard errors.

    I have tried to run such a code:

    xtdidregress (outcome variable) (treatment), group(town) time(time)
    Yet, i get a multicollinearity problem with the treatment variable.

    How should I address it?

    Thank you!

  • #2
    didregress and siblings require use of a time varying treatment variable (it seems that your treatment variable is time constant). That is, for treated cities, the treatment variable should take on the value 0 for periods prior to intervention and take on the value 1 thereafter, whereas control cities should have a 0 for all periods. Create a new variable that is the product of time (post vs pre) and treatment (treated vs control) and then use that with xtdidregress. Something like:
    Code:
    gen trt = time*treatment
    xtdidregress (outcome variable) (trt), group(town) time(time)

    Comment


    • #3
      Thank you very much Joerg. If I set my variable time to take on the value 0 for periods prior to intervention and take on the value 1 thereafter, only for the treated group and 0 for all periods for the control, I get this error message:
      model is not identified
      The treatment variable trt was omitted because of collinearity.
      However, If I set my variable time to take on the value 0 for periods prior to intervention and take on the value 1 thereafter for both control and treated group I get the results.

      Comment


      • #4
        Hard to say what went wrong without seeing your data and code. Please post a reproducible example here or get in touch with [email protected] and they will sort it out.

        Comment


        • #5
          Code:
          gen time = 0 
          replace time =1 if Year>2014 
          xtset comunenum Year
          xtreg variablename treatment##time, fe cluster(comunenum)
          But i get that the variable Test is omitted due to multicollinearity. I have run:
          Code:
          corr Test variablename time comunenum
          And these are the results:

          Code:
               Test
                  Test |   1.0000
          variablename |   0.0309 
                  time |  -0.0007
            comunenum |  -0.8675

          Comment


          • #6
            Originally posted by Ruggero De Blasi View Post
            Code:
            gen time = 0
            replace time =1 if Year>2014
            xtset comunenum Year
            xtreg variablename treatment##time, fe cluster(comunenum)
            But i get that the variable Test is omitted due to multicollinearity. I have run:
            Code:
            corr Test variablename time comunenum
            And these are the results:

            Code:
             Test
            Test | 1.0000
            variablename | 0.0309
            time | -0.0007
            comunenum | -0.8675
            To control for x and t you can run your DiD by reghdfe, too.

            Comment


            • #7
              What is the variable Test? Do you mean treatment? The command
              xtreg variablename treatment##time, fe cluster(comunenum) puts in all levels and interactions in treatment and time. So, if treatment is the time-constant indicator, it will be dropped. Is treatment constant (all zeros or all ones) or is it varying across time (sometimes changing from zero to one)? I would do this as Jorge suggested, with or without xtdidregress.
              Code:
               gen post = year > 2014 gen trt = treatment*post
              Code:
               xtreg variablename trt i.year, fe cluster(comunenum)

              Comment

              Working...
              X