[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: re: Programming stata using egen functions |

Date |
Tue, 28 Apr 2009 14:25:40 +0100 |

I have to guess that Anne is confused about some aspect of that report. As you say, that part of the code sounds fine -- although note that Anne does not report the exact code she used for -max()-. In addition, there is no way that I can see that -egen, rowtotal()- could be used to give the maximum of three scalars even if that -egen- function did accept scalars. Nick n.j.cox@durham.ac.uk Martin Weiss True! But what is your explanation for the failure of the -max()- function then? Seems to work fine... ************* scalar m_108 =2.33 scalar m_109 =3.4 scalar m_1010 =1.2 di max(m_108, m_109, m_1010) ************* Nick Cox Martin's guess is not to the point here. As Anne's code given earlier in the thread does show, she is using (permanent) names like m_108 for scalars, and not locals. The problem, already explained by Kit Baum (in the posting being replied to here) and also by myself, is that -egen, rowtotal()- does not accept scalars as arguments. It only feeds on variables. To spell it out once more: scalars in Stata are not variables. Martin Weiss Let me guess, you never dereferenced the -local-s for the -max- calculation? Note the difference here: ************* local m_108 2.33 local m_109 3.4 local m_1010 1.2 //with dereferencing di max(`m_108', `m_109', `m_1010') //w/o dereferencing di max(m_108, m_109, m_1010) ************* Anne Resende Thanks for your response. I am a beginner in stata programming but my aim is to create a “mean” of the variable logwage to after run the bootstrap. So when I use rowmax( ) I expect the program to calculate the maximum of the value of the variables in parenthesis. For each `s’ I need the maximum value between the `sp’ numbers. For example: m_108 = 2.33 m_109 = 3.4 m_1010= 1.2 So I want the program to return de value 3.4. When I use the function max the program returns me the value of m_1010 because it is considering the max between the values 108, 109, 1010. So after the program calculate the maximum value within it m_`s’`sp’ , I trying to use the rowtotal( ) to sum all of the maximum values and to end up with just one variable. Kit Baum wrote: >egen rowmax() and rowtotal() are meant to be used with more than one >variable (rather than a scalar) as an argument. > > qui egen `exem_`s''=rowmax(m_`s'`sp') > >if m_`s'`sp' is a scalar, its rowmax or rowtotal is itself--a constant >value for each row (observation). What are you trying to do? * * 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: re: Programming stata using egen functions***From:*Anne Resende <A.C.C.Resende@rhul.ac.uk>

**AW: st: re: Programming stata using egen functions***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**RE: st: re: Programming stata using egen functions***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**AW: st: re: Programming stata using egen functions***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**AW: st: re: Programming stata using egen functions** - Next by Date:
**Re: st: RE: AW: RE: Programming stata using egen functions** - Previous by thread:
**AW: st: re: Programming stata using egen functions** - Next by thread:
**st: defection rate and survival analysis** - Index(es):

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