Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: How do i substitute the return local of program in the if expression of the egen command?


From   A Loumiotis <[email protected]>
To   [email protected]
Subject   Re: st: How do i substitute the return local of program in the if expression of the egen command?
Date   Tue, 30 Mar 2010 14:29:16 +0300

Sorry.... I mistyped the wrong left single quotation mark in my email
reply, but in my code I used the correct left quotation mark "`" and I
still get for the !(`r(andpve)') if expression

invalid syntax
r(198);


On Tue, Mar 30, 2010 at 1:55 PM, Martin Weiss <[email protected]> wrote:
>
> <>
>
>
>
> Seems the left single quote is not correct. Replace "'" with "`", w/o the
> quotation marks, of course...
>
>
>
> HTH
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected]
> [mailto:[email protected]] Im Auftrag von A Loumiotis
> Gesendet: Dienstag, 30. März 2010 12:27
> An: [email protected]
> Betreff: Re: st: How do i substitute the return local of program in the if
> expression of the egen command?
>
> Thanks for your help!
>
> using `r(andpve)' resolves the first problem...
>
> but for !('r(andpve)') i get the following
>
> invalid syntax
> r(198);
>
> any ideas?
>
> Best,
> Antonis
>
> On Tue, Mar 30, 2010 at 12:57 PM, Maarten buis <[email protected]>
> wrote:
>> --- On Tue, 30/3/10, A Loumiotis wrote:
>>> I have written a program (with the name andpve) that
>>> generates an expression of the form:
>>>
>>> var1>=0 & var2>=0 & ... & varN>=0
>>>
>>> and returns this value as a local with name r(andpve).
>>>
>>> I then want to use r(andpve) in another progam (rowctotal)
>>> where U substitute it in the if expression of the egen command.
>>>
>>> egen `left'_a = rowtotal(`right') if r(andpve), missing
>>> egen `left'_b = rowmin(`right') if !(r(andpve))
>>
>> egen `left'_a = rowtotal(`right') if `r(andpve)', missing
>> egen `left'_b = rowmin(`right') if !(`r(andpve)')
>>
>> Hope this helps,
>> Maarten
>>
>> --------------------------
>> Maarten L. Buis
>> Institut fuer Soziologie
>> Universitaet Tuebingen
>> Wilhelmstrasse 36
>> 72074 Tuebingen
>> Germany
>>
>> http://www.maartenbuis.nl
>> --------------------------
>>
>>
>>
>>>
>>> But the egen command does not seem understand the r(andpve)
>>> as an if
>>> expression or the !(r(andpve)) as an if expression.
>>>
>>> What did I do wrong?  I'm new to Stata.  The code is
>>> below.
>>>
>>> Best regards,
>>>
>>> Antonis Loumiotis
>>> Athens, Greece
>>>
>>>
>>> ------------------------------
>>> ---------
>>> program rowctotal, rclass
>>>     version 11
>>> gettoken left right: 0
>>> capture drop `left'
>>> andpve `right'
>>>     di r(andpve)
>>>     egen `left'_a = rowtotal(`right') if r(andpve),
>>> missing
>>>     egen `left'_b = rowmin(`right') if !(r(andpve))
>>>     egen `left' = rowtotal(`left'_*), missing
>>>     *drop `left'_*
>>> end
>>>
>>> program andpve, rclass
>>>     local k = 1
>>>     while "``k''" != "" {
>>>     local ++k
>>>     }
>>> local --k
>>> local i = 1
>>> local andpve ""
>>> while `i' <= `k'-1 {
>>>     local andpve "`andpve'``i''>=0 & "
>>>     local ++i
>>> }
>>> local andpve "`andpve'``i''>=0"
>>> return local andpve `andpve'
>>> end
>>>
>>> -----------------------------------------------------------
>>>
>>> *
>>> *   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/
>>
>
> *
> *   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/
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index