eststo xtreg_robust: qui xtreg fte i.treated#i.t, fe robust eststo ols_robust: qui reg fte i.treated#i.t, robust table treated t, c(mean fte N fte) row col bysort id: keep if _N=2 // balance the panel Note that you can use factor variable notation to create the interactions rather than hard coding them. You may want to stick with clustered OLS if you have a repeated cross-section.
If the panel is unbalanced (consists of repeated cross-sections), xtreg, fe will drop some observations that appear in only one year and the estimates will no longer match OLS or manual calculations. Here I will balance the panel in order to get xtreg, fe and OLS to give the same coefficient estimates. The outcome fte is full-time equivalent employees. The DID parameter is the interaction of t = 1 and NJ = 1. February '92 (t=0) is pre and November '92 is post (t=1).
Here NJ restaurants are treated (become subject to the minimum wage increase) and PA restaurant are not. Here's an example of 2x2 DID on a public dataset demonstrating this. These coefficient equivalences are limited to two-period (one pre, and one post) datasets with treatment at the same time for all treated units. You need to compare apples to apples, so use clustering with OLS and clustering with xtreg, fe (or robust with xtreg, fe, which will default to clustering as Thomas pointed out). Of course year the variable "treat" denotes being assigned to the treatment group. Of course I was imprecise in saying the standard error was four times smaller, it's slightly less than tree, but it's the same thing. 91695247 (fraction of variance due to u_i) Group variable: id Number of groups = 2,284 Why is it so? And what does it suggest about the validity of the model and the command to use? What would be best to do when I am also adding covariates later?Įdit: I try to add an example from the code: gen y07=1 if year=2017įixed-effects (within) regression Number of obs = 4,568 It actually is so when I do this with my data, but the standard errors are completely different: when is use Stata's command "reg" i get absolutely no significance, when I use xtreg I get instead a t-statistic of more than 2, with standard errors being almost 4 times smaller. As I understand this, also from other questions, when there are no covariates, estimating the diff in diff using a regular regression (including dummy for year of treatment, dummy for treatment, and interaction) gives the same results as estimating it using a fixed effect command such as Stata's xtreg. I have a question on estimating a difference in differences model using Stata.