Dear Stata listers:
Recently I wrote the following simple program
titled 'coefvar.ado' for the purpose of calculating
coefficients of variation.
----------coefvar.ado----------
program define coefvar, rclass byable(recall)
version 7
qui summ `1', det
local coefvar = r(mean)/r(sd)
di in green _col(8) `coefvar'
end
----------coefvar.ado----------
But somehow it doesn't work as expected.
More specifically, when typing like
'bys year : coefvar basepay'
using a data set containing multiple panels, following
results:are shown on the screen:
____________________________________________________________________________
___
-> year = 1989
3.7137332
____________________________________________________________________________
___
-> year = 1990
3.7137332
____________________________________________________________________________
___
-> year = 1991
3.7137332
____________________________________________________________________________
___
-> year = 1992
3.7137332
____________________________________________________________________________
___
-> year = 1993
....
and so on. Namely, they are all the same for
each year when they should vary from year
to year.
I guess something is wrong or missing with this
program, but I'm sorry I can't fix it.
Is there any better idea? Any suggestions welcome.
Thanks in advance.
K.I.
*
* 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/