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"
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"
Comment