Dear All
I am having some problems with my ado.file whenever I try to include
some egen functions like rowmax and rowtotal. I am currently using
Stata 10.0
My ado program is:
program mymean, rclass
1. syntax [varlist] [if]
2. tokenize "`varlist'"
3. forvalues s=9(1)20 {
4. forvalues sp=9(1)`s' {
5. qui summarize `1' if `sp'==u
6. local mean1_`s'`sp' =r(mean)
7. qui sum `1' if u==8
8. local mean2_`s'`sp' =r(mean)
9. scalar m_`s'`sp'=`mean1_`s'`sp'' + ((`mean1_`s'`sp'' -
`mean2_`s'`sp'')/(`sp'-8))*(9-`sp')
10. tempvar exem_`s' P1_`s' P_`s' ep_`s' ep2_`s'
11. qui egen `exem_`s''=max(m_`s'`sp')
12. return scalar exem2_`s'=`exem_`s''*1
13. qui gen `P1_`s''=sum(P) if `s'==u & id==1
14. qui egen `P_`s'' =max(`P1_`s'')
15. scalar ep_`s'=exem2_`s'*`P_`s''
16. qui gen `ep_`s''=exem2_`s'*`P_`s''
17. return scalar eq29=sum(ep_`s')
18. }
19. }
20. end
This program is running well. But in lines 11 and 17, I in fact need to
use the commands rowmax rather than max and rowtotal rather sum. So
when I use max and sum the program runs well but when I substitute this
commands whith rowmax and rowtotal stata gives me the following error
message after I typed mymean loghw:
program mymean, rclass
1. syntax [varlist] [if]
2. tokenize "`varlist'"
3. forvalues s=9(1)20 {
4. forvalues sp=9(1)`s' {
5. qui summarize `1' if `sp'==u
6. local mean1_`s'`sp' =r(mean)
7. qui sum `1' if u==8
8. local mean2_`s'`sp' =r(mean)
9. scalar m_`s'`sp'=`mean1_`s'`sp'' + ((`mean1_`s'`sp'' -
`mean2_`s'`sp'')/(`sp'-8))*(9-`sp')
10. tempvar exem_`s' P1_`s' P_`s' ep_`s' ep2_`s'
11. qui egen `exem_`s''=rowmax(m_`s'`sp')
12. return scalar exem2_`s'=`exem_`s''*1
13. qui gen `P1_`s''=sum(P) if `s'==u & id==1
14. qui egen `P_`s'' =max(`P1_`s'')
15. scalar ep_`s'=exem2_`s'*`P_`s''
16. qui gen `ep_`s''=exem2_`s'*`P_`s''
17. return scalar eq29=rowtotal(ep_`s')
18. }
19. }
20. end
.
end of do-file
. mymean loghw
variable m_99 not found
r(111);
So I would like to know why the program recognizes the max and sum egen
functions but do not recognize (or do not find my variable) when I use
the rowmax and rowtotal egen functions. Is there any programming
differences between these two kind of egen functons?
Thanks a lot
Anne
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/