Hi everyone
I'm having a problem with running a loop xbar control chart. What i'm trying to do is produce a control chart for every week of my observations. And i want to output the number of violations for each week and the number of observations to give me a score of [1-(violations/observations)*100]
The code i'm using is the following:
foreach i of local levels {
summarize AM if week==`i'
local x=`r(mean)'
display `x'
local s=`r(sd)'
display `s'
local u=`x'+(3*`s')
display `u'
local t=`x'-(3*`s')
display `t'
local z=`x'-(100*`s')
replace AM=0 if AM==. & week==`i'
xchart days AM if week==`i', lower(`t') upper(`u')
gen total`i'=`r(N)'
gen violations`i'=`r(out_x)'
gen AMscore`i'=(1-(violations`i'/total`i'))*100
}
I'm running into three problems:
1. For some reason the local values aren't being saved properly and the control charts are being produced with limits based on the last week of observations
2. For some reason the values being plotted in the control chart don't match the actual values in my database
3. The output from the control chart, ie. the number of observations, is saving as total observations, not number of observations per week.
If anyone has any advice i'd really appreciate. I've spent the whole day today trying to figure this out;
I'm sure its some simple mistake i'm making.
thanks everyone
imran
I'm having a problem with running a loop xbar control chart. What i'm trying to do is produce a control chart for every week of my observations. And i want to output the number of violations for each week and the number of observations to give me a score of [1-(violations/observations)*100]
The code i'm using is the following:
foreach i of local levels {
summarize AM if week==`i'
local x=`r(mean)'
display `x'
local s=`r(sd)'
display `s'
local u=`x'+(3*`s')
display `u'
local t=`x'-(3*`s')
display `t'
local z=`x'-(100*`s')
replace AM=0 if AM==. & week==`i'
xchart days AM if week==`i', lower(`t') upper(`u')
gen total`i'=`r(N)'
gen violations`i'=`r(out_x)'
gen AMscore`i'=(1-(violations`i'/total`i'))*100
}
I'm running into three problems:
1. For some reason the local values aren't being saved properly and the control charts are being produced with limits based on the last week of observations
2. For some reason the values being plotted in the control chart don't match the actual values in my database
3. The output from the control chart, ie. the number of observations, is saving as total observations, not number of observations per week.
If anyone has any advice i'd really appreciate. I've spent the whole day today trying to figure this out;
I'm sure its some simple mistake i'm making.
thanks everyone
imran
Comment