Paswel Phiri Marenya asked:
> How do I get confidence bands around my -lowess- graphs?
This example may be a useful starting point
(note I use -locpoly- rather than -lowess-, but the idea is the same):
net inst st0053_3, replace
webuse nlswork, clear
gen work=wks_w>0 if !mi(wks_w)
keep work age id
save /out, replace
cap pr drop _all
pr eachone, rclass
drop _all
use /out
bsample, cluster(idcode)
gen x=_n in 20/40
locpoly work age, gen(sm) at(x) nog
forv a=20/40 {
return scalar a`a'=sm[`a']
}
end
gen x=_n in 20/40
locpoly work age, gen(sm) at(x) nog
qui reg work age
local n=e(N)
local rownames
local rnames
forv a=20/40 {
mat a=nullmat(a) , `=sm[`a']'
local rownames `rnames' a`a'
local rnames "`rnames' a`a'=r(a`a')"
}
simulate `rnames', reps(10) seed(12345): eachone
bstat, stat(a) n(`n')
mat b=e(b)
mat v=e(V)
drop _all
set obs 21
gen coef=.
gen ll=.
gen ul=.
forv i=1/21 {
qui replace coef=b[1,`i'] in `i'
qui replace ll=b[1,`i']-1.96*sqrt(v[`i',`i']) in `i'
qui replace ul=b[1,`i']+1.96*sqrt(v[`i',`i']) in `i'
}
g a=_n+19
la var a "Age in years"
tw rarea ll ul a || line coef a, leg(lab(1 "CI") lab(2 "Working"))
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/