Apologies if this is very basic, however I have spent the better part of a day going through the manuals and online forums with little progress.
I am trying to run a very simple bootstrap on a dataset. The data set has 3 variables; orgcode - group - perf
My ideal aim is:
- For each value of group - calculate the bootstrapped SD and IQR values
- Save the estimated values for that group to a unique file - my ultimate aim being to append all the files
- Move onto the next value of group
Code:
use dataset
drop if total<100
keep if standard=="Test"
keep if year=="2018"
drop year standard proportion total
rename withinstd value1
rename without value0
reshape long value, i(orgcode type) j(perf)
drop if value==0
expand value
drop value
egen group = group(type)
drop type
program boot, rclass
preserve
collapse perf, by(orgcode group)
sum perf if group==`x', d
local sd = r(sd)
local p25 = r(p25)
local p75 = r(p75)
return scalar sd = `sd'
return scalar iqr = `p75'-`p25'
restore
end
forvalues x = 1/14 {
bootstrap r(sd) r(iqr), reps(1) saving(data_`x', replace): boot
}
Code:
invalid syntax an error occurred when bootstrap executed boot r(198);
There are only 14 groups which are defined and dont change, so I could conceivably just manually type the bootstrap sequence out per group and go from there, but for the sake of elegance I wanted to know how to use a loop to accomplish the same thing.
Many thanks for your time,
0 Response to Help running a bootstrap within a forvalues loop
Post a Comment