Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: Programming stata using egen functions


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Programming stata using egen functions
Date   Tue, 28 Apr 2009 09:32:10 +0200

<> 

Other problems: 

You allow the [if] qualifier, but if the user did indeed specify it, the -program- would not respect it.

Seems redundant to say -syntax [varlist]- and to -tokenize- it as you merely process one variable in there. So it could be -syntax varname-, to which you would refer as `varname' later on. Do you really want to make the varlist/varname optional? (What would your -program- do w/o a variable?)




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Anne Resende
Gesendet: Dienstag, 28. April 2009 02:05
An: [email protected]
Betreff: st: Programming stata using egen functions

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/


*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index