Dear Statalist Community,
I am conducting research on the impact of an external shock (treatment) on firm characteristics (outcome). At this stage, I need to perform a placebo test to assess the baseline results. Specifically, the following steps need to be taken:
1. retain the distribution of treatment years but randomly assign a never-treated state to each of the passage years (without replacement);
2. regress the baseline model using the pseudo treatment variable and retain its coefficient and standard error;
3. compute t-stats;
4. repeat this procedure 5000 times and yield a distribution of placebo t-stat estimates, then plot the histogram with a density curve.
Below is a sample of my data and code, but STATA returned an error message: "invalid syntax; an error occurred when simulate executed myplacebo; r(198)." Beside, can the above mentioned steps be achieved using these commands? I would greatly appreciate it if you could review the code and offer any suggestions. Thank you in advance for your assistance.
The final product is expected to be look like this figure:
I am conducting research on the impact of an external shock (treatment) on firm characteristics (outcome). At this stage, I need to perform a placebo test to assess the baseline results. Specifically, the following steps need to be taken:
1. retain the distribution of treatment years but randomly assign a never-treated state to each of the passage years (without replacement);
2. regress the baseline model using the pseudo treatment variable and retain its coefficient and standard error;
3. compute t-stats;
4. repeat this procedure 5000 times and yield a distribution of placebo t-stat estimates, then plot the histogram with a density curve.
Below is a sample of my data and code, but STATA returned an error message: "invalid syntax; an error occurred when simulate executed myplacebo; r(198)." Beside, can the above mentioned steps be achieved using these commands? I would greatly appreciate it if you could review the code and offer any suggestions. Thank you in advance for your assistance.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double(gvkey fyear) str8 incorp float(treat treatyear outcome) 1004 1991 "DE" 0 2000 1.9301835 1004 1992 "DE" 0 2000 2.403937 1004 1993 "DE" 0 2000 1.8439943 1004 1994 "DE" 0 2000 1.8381265 1004 1995 "DE" 0 2000 2.1075902 1004 1996 "DE" 0 2000 3.0318136 1004 1997 "DE" 0 2000 1.359761 1004 1998 "DE" 0 2000 2.330347 1004 1999 "DE" 0 2000 2.665054 1004 2000 "DE" 1 2000 1.3347505 1004 2001 "DE" 1 2000 .652634 1004 2002 "DE" 1 2000 .11607568 1004 2003 "DE" 1 2000 0 1004 2004 "DE" 1 2000 0 1004 2005 "DE" 1 2000 0 1004 2006 "DE" 1 2000 0 1004 2007 "DE" 1 2000 .6994809 1004 2008 "DE" 1 2000 0 1004 2009 "DE" 1 2000 0 1004 2010 "DE" 1 2000 .324113 1004 2011 "DE" 1 2000 .716871 1004 2012 "DE" 1 2000 1.2401142 1004 2013 "DE" 1 2000 .5819505 1004 2014 "DE" 1 2000 10.78548 1004 2015 "DE" 1 2000 2.0248249 1004 2016 "DE" 1 2000 1.9945482 1004 2017 "DE" 1 2000 1.534728 1004 2018 "DE" 1 2000 1.3709465 1004 2019 "DE" 1 2000 .7118807 1004 2020 "DE" 1 2000 .006494772 1009 1991 "DE" 0 2000 2.27228 1009 1992 "DE" 0 2000 1.9249095 1009 1993 "DE" 0 2000 1.578199 1009 1994 "DE" 0 2000 1.0766329 1010 1991 "NJ" 0 2011 1.3870368 1010 1992 "NJ" 0 2011 0 1010 1993 "NJ" 0 2011 7.370338 1010 1994 "NJ" 0 2011 .4462564 1010 1995 "NJ" 0 2011 0 1010 1996 "NJ" 0 2011 0 1010 1997 "NJ" 0 2011 -.3528432 1010 1998 "NJ" 0 2011 0 1010 1999 "NJ" 0 2011 0 1010 2000 "NJ" 0 2011 0 1010 2001 "NJ" 0 2011 . 1010 2002 "NJ" 0 2011 . 1010 2003 "NJ" 0 2011 1.4550402 1011 1991 "PA" 0 . -.02293578 1011 1992 "PA" 0 . 0 1011 1993 "PA" 0 . -2.7942355 end
Code:
mkmat treatyear if treat, matrix(T) local ntreat = rowsof(T) cap program drop myplacebo program myplacebo, rclass drop _all set seed 347544 gen pseudo_year = T[runiformint(1,`ntreat'), 1] if !treat replace pseudo_year = treatyear if treat replace pseudo_year = . if !missing(treatyear) gen pseudo_treated = 0 replace pseudo_treated = 1 if fyear >= pseudo_year reg outcome pseudo_treated i.fyear, cluster(gvkey) return scalar rb0 = _b[pseudo_treated] return scalae rse0 = _se[pseudo_treated] end simulate rb0 =r(rb0) rse0=r(rse0), reps(5000) : myplacebo gen tstat = rb0/rse0 histogram tstat, normal width(0.4) xline(9.01) ytitle("Density") xtitle("t-statistics of the placebo estimates") title(Randomize only states)
Comment