I want to randomly assign treatment and then simulate it for 1000 times for all my y variables. I want the coefficient, standard error, and the confidence interval.


I am running the following code but STATA is issuing "varlist not allowed" after program NO treatment - Copy, rclass. Any help is appreciated. I am not sure if I am coding it correctly


drop random
drop post
set more off
set matsize 800


cap program drop NO treatment - Copy
set seed 6000
program NO treatment - Copy, rclass


unab y : wheat rice lentils
local l : word count `y'

generate random=uniform()
sort year random
generate post=0
replace post=1 in 1 in 1/29 // for year 2010
replace post=1 in 296/337 // for year 2011
replace post=1 in 578/619 // for year 2012

foreach var of local y {
quietly reg `var' post i.country_id i.year i.country#c.line_time_trend [aw=ypop], cluster( country_id )
}

return scalar tau_coeff = _b[post]
return scalar tau_se = _se[post]
end

simulate post= r(post)
tau_coeff = r(tau_coeff) ///
tau_se = r(tau_se) , reps(1000) saving(NO treatment - Copy.dta, replace): NO treatment - Copy

sum