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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Programming stata using egen functions |

Date |
Tue, 28 Apr 2009 18:51:12 +0100 |

At the simplest, there are two generic problems in this thread: 1. Those people who are attending and know more Stata than you do don't understand what you are trying to do. 2. You don't know enough Stata to do what you want without help. These problems don't cancel. Several points have been made already and I don't think that you have paid attention to them all. I won't repeat any here but will add another: It appears that you want to compare results in a list, to get the maximum or whatever. You won't do that _inside_ your loops, as your double loop just produces one result at a time. If your comparison makes sense, then you probably need to move it outside your loops. Nick n.j.cox@durham.ac.uk Anne Resende Thanks a lot for all answers!! Just to clarify some points: I understood that the egen functions rowmax() and rowtotal() did not accept scalar. So in line 9 I substitute `scalar’ for `local’ hoping that rowmax() could now recognize the varlist. But stata returns de same error message. I need the rowmax() function to returns the maximum values between the varilist. (the maximum values within each `s’) So I have tried: 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. local m_`s'`sp'=`mean1_`s'`sp'' + ((`mean1_`s'`sp'' - `mean2_`s'`sp'')/(`sp'-8))*(9-`sp') 10. tempvar exem_`s' P_`s' ep_`s' ep2_`s' 11. qui egen `exem_`s''=rowmax(m_`s'`sp') 12. qui gen `P_`s''=sum(P) if `s'==u & id==1 13. qui sum `P_`s'', meanonly 14. local P1_`s'=r(max) 15. scalar ep_`s'=exem2_`s'*`P1_`s'' 16. qui egen `ep2_`s''=rowtotal(ep_`s') 17. return scalar eq2=`ep2_`s'' 18. } 19. } 20. end end of do-file . mymean loghw variable m_99 not found r(111); 1) I understand the differences between egen sum( )and stata fuctions sum(), but neither gives me what I need. I intend to use rowtotal() because it sums the observations on the rows not on the columns as egen sum() and sum() do. 2) Sorry about: return scalar eq29=rowtotal(ep_`s') that I wrote in the other email.. I know that it’s wrong 3)What is my aim? As I told I need to end up with one variable in order to run the bootstrap. I want to the create the program mymean and then run: bootstrap r(eq2), reps(#) seed(#) : mymean loghw (I am following the idea on: http://www.stata.com/capabilities/boot.html) 4)I think that I cannot use a do.file because I will end up with a constant (I also tried) and so I could not run the bootstrap. Creating and ado file the program allows me to use the boots after. So all I want to do is to write a program to calculate my statistics of interest and then apply the bootstrap. And my problem is how I can construct a varlist in order to run my program using rowmax() and rowtotal(). Or maybe there is another way to do that without having to use rowmax() and rowtotal() functions. I hope that is clearer now, * * 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/

**References**:**Re: st: Programming stata using egen functions***From:*Anne Resende <A.C.C.Resende@rhul.ac.uk>

- Prev by Date:
**RE: st: Programming stata using egen functions** - Next by Date:
**AW: st: Programming stata using egen functions** - Previous by thread:
**RE: st: Programming stata using egen functions** - Next by thread:
**st: re: overid test** - Index(es):

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