Re: AW: st: AW: Quotes for scalar within local (was efficiently run three loops (or do without them))

Re: AW: st: AW: Quotes for scalar within local (was efficiently run three loops (or do without them))

Date

Tue, 14 Apr 2009 15:03:45 +0700

True true, and Nick did propose something along those lines yesterday, however (and I may be wrong),
having the `i''s and `j''s gives me more documentation options so I can produce something like this
where product, unit, and price codes call come from these scalars

Anyway I think I can safely close this thread. As always, a great learning experience (and a
reminder that I should give back more to this great community)

Thank you.
Ronnie
Martin Weiss wrote:

<>
The line -g x = foreign == `i' & rep78 == `j'- smacks of

*************
egen mygroups=group(for rep)
*************
as a more easily intelligible alternative...
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Ronnie
Babigumira
Gesendet: Dienstag, 14. April 2009 09:36
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: AW: Quotes for scalar within local (was efficiently run
three loops (or do without them))
Thanks Martin.
That it is not a recommended strategy tells me I am doing something "wrong"
or that I need to be
careful. Might you know why it is not recommended.
Also, I am thinking that this revised code is closer to what Roy wrote only
I like to put this kind
of stuff out of the the main body of the code so that I can easily change
them (but I can live with
this anyway)
sysuse auto, clear
levelsof foreign, local(source)
foreach i of local source {
levelsof rep78 if foreign == `i', local(rep)
foreach j of local rep {
g x = foreign == `i' & rep78 == `j'
sum mpg if x
drop x
}
}
Martin Weiss wrote:

<>

If you wanted to make the -local- work here, you would have to delay
evaluation with the "\" character. This is not a recommended strategy, but
note the difference here:
*************
sysuse auto, clear
local x "foreign == `i' & rep78 == `j'"
local y "foreign == \`i' & rep78 == \`j'"
macro dir
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Ronnie
Babigumira
Gesendet: Dienstag, 14. April 2009 08:00
An: statalist@hsphsun2.harvard.edu
Betreff: st: Quotes for scalar within local (was efficiently run three

loops

(or do without them))
Thanks
Exploring your suggestion but wanting to put the checks in a macro rather
than a variable, however,
I am stuck (I have checked the archives but I cannot find a solution)
An illustration using the auto data
local x "foreign == `i' & rep78 == `j'"
sysuse auto, clear
levelsof foreign, local(source)
foreach i of local source {
levelsof rep78 if foreign == `i', local(rep)
foreach j of local rep {
sum mpg if `x'
}
}
I have set the trace on and this is where it fails
- sum mpg if `x'
= sum mpg if foreign == & rep78 ==
Looks like the `i' and `j' disappear. I have fiddled around with different
combinations of quotes
but no luck.
Ronnie
Roy Wada wrote:

gen check=1 if fup_pdt>`x' | fup_unit=`Y' | fup_qtycoll`x' &

fup_unit=`Y'

& fup_qtycoll

where x, y, z are some conditions to be met. Then you would list them,