Hello everyone,
First my dataset: The bins were created by recoding my initial x for a specific date:
When running my whole code and using dataex it looks like this: I dont know if this is useful for you, since the bins have these values and not the ones above, but my code seems to work nevertheless.
My dataset includes the bin variable and the change variable, which is constructed by the change to x from x-1. For each bin I plotted the change variable through a connected graph
Now, I want to include for each bin confidence intervals (with rcap design) by using bootstrapping. I have looked at @Clyde Schechter approach from #6:
https://www.statalist.org/forums/for...dence-interval
, but I havent been able to produce any fruitful result for my context using this approach. Either I get error messages like "invalid syntax" "not valid command" or in case of graphs, they looked completely desastrous.
Really hope someone can help me. If you need more information about the code or the dataset, I will try to provide it as good as possible.
First my dataset: The bins were created by recoding my initial x for a specific date:
Code:
recode x*2012xxxx (2000/2500=2500)(2500/3000=3000)(3000/3500=3500)(3500/4000=4000)(4000/4500=4500)(4500/5000=5000)(5000/5500=5000)(5500/6000=5500)(6000/6500=6000)(6500/7000=6500)(7000/max=7000), gen(bin)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(bin change) 0 .08722616 1.9073486e-06 .20833333 .000014781952 .08333334 .000061035156 .125 .01 .28812057 .01999919 .08333334 .02 .2240991 .03 .19109195 .0390625 .6666667 .04 .1875 .04999995 .125 .05 .2847222 .05 .2872807 .06 .2847222 .06 .125 .07 .23214285 .08 .20833333 .09 .28030303 .1 .3333333 .11 .29166666 .12 .24358974 .13 .23958333 .14 .2857143 .15 .3090278 .16 .24264705 .17 .21666667 .18 .19791667 .19 .25462964 .2 .25 .2 .29166666 .21 .21666667 .22 .26190478 .23 .15277778 .24 .20833333 .25 .28333333 .26 .23148148 .26999998 .08333334 .27 .3166667 .28 .20833333 .29 .27314815 .3 .25 .3 .19791667 .31 .30555555 .32 .3583333 .33 .4583333 .33 .27604166 .34 .22222222 .35 .29166666 .36 .08333334 .36 .25833333 .37 .20833333 .38 .22916667 .39 .20833333 .4 .25 .4 .2559524 .41 .2638889 .42 .11111111 .43 .22916667 .44 .29166666 .45 .30555555 .45 .08333334 .46 .20833333 .47 .18333334 .48 .22916667 .49 .30555555 .5 .25 .51 .20833333 .52 .22916667 .53 .40625 .54 .08333334 .55 .20833333 .56 .2 .57 .22916667 .58 .15833333 .59 .2 .6 .20833333 .6 .3020833 .61 .5 .62 .15833333 .63 .4166667 .64 .3333333 .65 .21875 .66 .29166666 .67 .15625 .68 .2777778 .69 .125 .7 .29166666 .71 .4583333 .72 .20833333 .72 .29166666 .73 .08333334 .75 .23333333 .76 .08333334 .77 .4166667 .78 .25 .79 .4583333 .8 .3020833 .81 .22916667 .82 .3333333 .83 .125 end
Code:
gen low_limit = change if bin< 4750 & bin> 2000 gen big_limit = change if bin> 5250 twoway connected low_limit big_limit bin if bin != 5000 & bin > 2000, msymbol(D D) xlabel(2500(500)7500) xtitle("") xlabel(3000 "3000" 4000 "4000" 5000 "5000" 6000 "6000" 7000 "7000") ylabel(.30(.10)0.7) ytitle("change") xline(5000) color(red) title("")
https://www.statalist.org/forums/for...dence-interval
, but I havent been able to produce any fruitful result for my context using this approach. Either I get error messages like "invalid syntax" "not valid command" or in case of graphs, they looked completely desastrous.
Code:
use temp_data, clear set seed 756124839 levelsof bin_debt, local(bins) /*Bootstrapping*/ foreach b of local bins { bootstrap _b, reps(1000) bca: mean change if bin == `b' estat bootstrap bysort bin: egen upperConf = pctile(change), p(95) bysort bin: egen lowerConf = pctile(change), p(5) } collapse (mean) change (p5) lowerConf = change (p95) upperConf = change, by(bin) /*Graph*/ gen low_limit = change if bin< 4750 & bin> 2000 gen big_limit = change if bin> 5250 local xmin = r(min) local xmax = r(max) twoway (rcap upperConf lowerConf bin, lcolor(gs6) lwidth(medthick)) /// (connected low_limit big_limit bin, mcolor(navy)) /// , xlabel(`bins', valuelabel) graphregion(color(white) icolor(white) lwidth(0)) xtitle("") ytitle("%{&Delta} change") /// legend(off) xscale(alt range(`=`xmin'-0.5' `=`xmax'+0.5')) bgcolor(white) title("`title'")
Comment