Announcement

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

  • Error with binary treatment variable with xtreg DiD code

    I am running a Diff-in-Diff fixed effects model with the commonly used Stata DiD command:
    xtreg depvar i.treatment i.year, fe cluster(clustervar)


    However, I am struggling in preparing my variables correctly before running my DiD fe model. My time variable is month, while my place variable is neighborhood and I would like to cluster my results at the neighborhood-level. Here is a data example: ''' dataex price numeric_neighborhood DiD_implementation treated_neighborhood treatment_time month * Example generated by -dataex-. For more info, type help dataex clear input double area_small long numeric_neighborhood float(DiD_implementation treated_neighborhood treatment_time month) 412 629 0 1 0 19 33 2157 1 1 1 77 455 340 0 1 0 10 732 1168 0 1 0 14 307 314 0 1 0 53 '''
    Here is how I am preparing my data:

    '''
    preserve
    qui sum month
    local min= r(min)
    gen max= r(max)
    gen treatment_time=(month>=ym(2013, 11) & !missing(month))
    gen treated_neighborhood = 1 if city_trans=="Glendale"
    replace treated_neighborhood=0 if treated_neighborhood==.
    gen DiD_implementation= treatment_time*treated_neighborhood

    collapse (mean) area_small, by(numeric_neighborhood month)
    xtset numeric_neighborhood month, monthly
    xtreg area_small i.DiD_implementation i.month, fe cluster(month)
    restore
    '''

    Lastly, here is the error that I receive when running the codes above "variable DiD_implementation not found"
    Last edited by Paolo Maldini; 01 Apr 2022, 11:31.

  • #2
    Your immediate problem arises because of the way you -collapse-d the data. After that command, the only variables left in the data set are numeric_neighborhood, month, and area_small_MoH. You didn't include DID_implementation anywhere in the command, so it is gone.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Your immediate problem arises because of the way you -collapse-d the data. After that command, the only variables left in the data set are numeric_neighborhood, month, and area_small_MoH. You didn't include DID_implementation anywhere in the command, so it is gone.
      Thanks, I should have mentioned that I ran both codes:
      preserve
      qui sum month
      local min= r(min)
      gen max= r(max)
      collapse (sum) area_small DID_implementation, by(numeric_neighborhood month)
      xtset numeric_neighborhood month, monthly
      xtreg area_small DiD_i month, fe cluster(numeric_neighborhood)
      restore

      And still receiving the same error "variable DID_implementation not found
      r(111);
      "

      Comment


      • #4
        DID_implementation is the name you are using but later you refer to DiD_i. Stata is case-sensitive and won't regard any name beginning DID as pointing towards any name beginning DiD.

        Comment

        Working...
        X