Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Kamarul Imran <kim4597@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: loop for graphs |

Date |
Fri, 8 Jul 2011 18:42:17 +0800 |

Dear Marteen, It works wonderful. Thanks very2 much. I am very grateful Best regards Kamarul On Fri, Jul 8, 2011 at 3:39 PM, Maarten Buis <maartenlbuis@gmail.com> wrote: > On Fri, Jul 8, 2011 at 5:43 AM, Kamarul Imran wrote: >>I have 3 dependent variables (a1,b1,c1) that i want plot >> against 1 var (x). i will be using scatter plot and hope to use these >> commands >> >> foreach var of varlist a1-c1 { >> graph twoway (scatter `var' x ) (lfit `var' x), saving(gr.gph) >> } > > For each iteration of the loop you are using the same name to store > your graph, thus overwriting the previous graph. So at the end of the > loop you are left with only the last graph. If you change the name > during each iteration, you'll get what you want. A convenient way is > to use the local `var', as that will already change for each iteration > and later it will be easier for you to remember which file contains > which graph just by looking at the filenames (assuming you chose more > informative variable names than a1 b1 c1...). So the example below > should do what you want. (I use the -name()- option instead of the > -saving()- option as I do not wish to store these graphs on my > computer. You can of course change that.) > > *------------- begin example -------------- > sysuse nlsw88, clear > foreach var of varlist wage hours ttl_exp { > twoway scatter `var' grade || /// > lfit `var' grade, /// > name(gr`var', replace) > } > *--------------- end example -------------- > (For more on examples I sent to the Statalist see: > http://www.maartenbuis.nl/example_faq ) > > Hope this helps, > Maarten > > -------------------------- > Maarten L. Buis > Institut fuer Soziologie > Universitaet Tuebingen > Wilhelmstrasse 36 > 72074 Tuebingen > Germany > > > http://www.maartenbuis.nl > -------------------------- > > * > * 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/ > -- Kamarul Imran Musa mobile : 0192711175 / 0139302002 Kota Bharu Kelantan sype: drkamarul5683 * * 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**:**st: loop for graphs***From:*Kamarul Imran <kim4597@gmail.com>

**Re: st: loop for graphs***From:*Maarten Buis <maartenlbuis@gmail.com>

- Prev by Date:
**Re: st: loop for graphs** - Next by Date:
**st: RE: merge more than two database** - Previous by thread:
**Re: st: loop for graphs** - Next by thread:
**re: st: loop for graphs** - Index(es):