I am trying to run a cluster bootstrap to calculate the standard error for several variables in Stata. Here is my code. It appears that Stata can not access the variable or the weight related to the variable. The exact error message is "can not find site_weight" I will appreciate any tip on solving the problem.
capture program drop bootstrap_se
program bootstrap_se, rclass
syntax varname [if] [in]
local weight_var site_`varname'_weight // Construct weight variable name dynamically
reghdfe `varname' treatment [pweight=`weight_var'], absorb(cohort_site week_type) noconstant
return scalar effect=_b[treatment]
end
bootstrap r(effect), reps(100) cluster(cohort_site) idcluster(new_cohort_site) seed(1234) : bootstrap_se avg_labor_cost
I also tried
capture program drop bootstrap_se
program bootstrap_se, rclass
syntax varlist [if] [in]
reghdfe `varlist'[1] treatment [pweight=`varlist'[2], absorb(cohort_site week_type) noconstant
return scalar effect=_b[treatment]
end
bootstrap r(effect), reps(100) cluster(cohort_site) idcluster(new_cohort_site) seed(1234) : bootstrap_se avg_labor_cost site_avg_labor_cost_weight
capture program drop bootstrap_se
program bootstrap_se, rclass
syntax varname [if] [in]
local weight_var site_`varname'_weight // Construct weight variable name dynamically
reghdfe `varname' treatment [pweight=`weight_var'], absorb(cohort_site week_type) noconstant
return scalar effect=_b[treatment]
end
bootstrap r(effect), reps(100) cluster(cohort_site) idcluster(new_cohort_site) seed(1234) : bootstrap_se avg_labor_cost
I also tried
capture program drop bootstrap_se
program bootstrap_se, rclass
syntax varlist [if] [in]
reghdfe `varlist'[1] treatment [pweight=`varlist'[2], absorb(cohort_site week_type) noconstant
return scalar effect=_b[treatment]
end
bootstrap r(effect), reps(100) cluster(cohort_site) idcluster(new_cohort_site) seed(1234) : bootstrap_se avg_labor_cost site_avg_labor_cost_weight
Comment