Hi Statalisters

I was wondering if anyone can share example codes for graphing Exponentially Weighted Moving Average (EWMA) Control Chart in Stata?

I have searched endlessly online without some success. Example data is below:

Code:
clear
set obs 50
gen month = _n
gen infect =  runiformint(3,12)
My interest is to overlay an EWMA control chart with a Stewart control chart. Stata already has a command for Stewart control chart (-cchart-). Since -cchart- is not a -two way- graph, I have constructed mine as below (just as example only):

Code:
sum infect
local u = r(mean) + 1 * r(sd)  
local t = r(mean) - 1 * r(sd)  
display "mean `r(mean)' lower `t' upper `u'"
tw connected infect month, sort yline(`r(mean)' `u' `t')
Now my major challenge is the ewma control chart.

Nick Cox please are you able to provide some advice as to how to make work your very old ewma code, possibly made for Stata 6.0?

When I try to use it to generate a new variable like
Code:
ewma infect, generate(ewm)
It returns an error that says

Code:
infect not found
r(111);
Any advice will be highly appreciated.

Madu