Does this do it?
// ------------------------------------------------------------------------------
sysuse auto, clear
tostring rep78, replace
local scatter ""
levels rep78, local(rep78)
foreach r of local rep78 {
local scatter `"`scatter' (scatter mpg weight if rep78==`"`r'"', msize(large))"'
}
di `"`scatter'"'
// ------------------------------------------------------------------------------
Regards, Sergiy Radyakin
On 4/9/08, Friedrich Huebler <[email protected]> wrote:
> I am trying to build up a -scatter- command with a -foreach- loop. I
> need additional quotes but do not know where to place them. The
> problem can be reproduced with the auto data.
>
> . sysuse auto, clear
> . tostring rep78, replace
> . local scatter ""
> . levels rep78, local(rep78)
> . foreach r of local rep78 {
> local scatter `"`scatter' (scatter mpg weight if rep78=="`r'", msize(large))"'
> }
> . di "`scatter'"
> (scatter mpg weight if rep78==Unknown function .", msize()
> r(133);
>
> As the error message shows, I need additional quotes somewhere. How do
> I have to edit the definition of the macro "scatter"? In the end, the
> macro should contain the following string, so that I can draw a graph
> with the command -graph twoway "`scatter'"-.
>
> (scatter mpg weight if rep78==".", msize(large)) (scatter mpg weight
> if rep78=="1", msize(large)) (scatter mpg weight if rep78=="2",
> msize(large)) (scatter mpg weight if rep78=="3", msize(large))
> (scatter mpg weight if rep78=="4", msize(large)) (scatter mpg weight
> if rep78=="5", msize(large))
>
> Thanks,
>
> Friedrich
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/