**announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
"Harris, Linda J" <ljharris@scharp.org> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Re: use loop to add plots to scatter plot |

Date |
Sun, 24 Mar 2013 04:34:30 +0000 |

Thanks Joseph. I'll give this a try on Monday. Linda ________________________________________ From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Joseph Coveney [stajc2@gmail.com] Sent: Saturday, March 23, 2013 8:40 PM To: statalist@hsphsun2.harvard.edu Subject: st: Re: use loop to add plots to scatter plot Linda J Harris wrote: I have macros with names `antigen01' to `antigen40' I want to create a two way graph with the following: 1) scatter plots with a variable # of these items (approx 5 and not in numeric order), each with a different marker 2) linear fits for the same items, with lines in the same color as the markers 3) a linear fit that is based on the aggregate selection of items following to a selection of these antigens (say approx 5): If possible, I would like to use a loop with a foreach statement rather than having to modify the specific items and # of items each time i ran this. I know that the last line is wrong - just have no idea how to accomplish this This is my first posting - hope I've done it right! I'm also new to Stata programming, so hope this isn't too trivial a question. example - say want `antigen01', `antigen04' `antigen05' twoway /// (scatter yvar xvar if ANTIGEN==`antigen01', mcolor(red)) /// (lfit yvar xvar if ANTIGEN==`antigen01', lcolor (red)) /// (scatter yvar xvar if ANTIGEN==`antigen04', mcolor(green)) /// (lfit yvar xvar if ANTIGEN==`antigen04'), lcolor(green) /// (scatter yvar xvar if ANTIGEN==`antigen05', mcolor(blue)) /// (lfit yvar xvar if ANTIGEN==`antigen05', lcolor(blue)) /// (lift yvar xvar if ANTIGEN oneof [`antigen01' `antigen04' `antigen5'], lcolor(black)) -------------------------------------------------------------------------------- If I understand what you're trying to do correctly, then you'll probably want to write a little ditty ado-file to call with your desired list of antigens as the argument. Something like that below. It will create the bunch of individual-antigen scatterplots and line-fit plots and the pooled-data line-fit plot and leave them all behind in memory, each with a unique name that you can then refer to them by. Usage would be something like: graphem my_antigen40 my_antigen2 my_antigen35 <do what you want to do with the graphs> graphem my_antigen2 my_antigen5 my_antigen18 my_antigen29 <do what you want to do with the graphs> and so on. Joseph Coveney program define graphem version <insert your Stata version here> syntax varlist local color_list red green blue // fill out with your preferences local graph_nr 1 foreach antigen of varlist `varlist' { // Pick color in sequence of color list local marker_color : word `graph_nr' of `color_list' // Make individual-antigen scatterplot graph twoway scatter yvar xvar if ANTIGEN == `antigen', /// mcolor(`marker_color') name("`antigen'_scatter") // Make plot of individual-antigen linear regression fit graph twoway lfit yvar xvar if ANTIGEN == `antigen', /// lcolor(`marker_color') name("`antigen'_linear_fit") // Concatenate list for "aggregate selection of items" local aggregate_antigens `aggregate_antigens' `antigen' // Next set of individual-antigen graphs local ++graph_nr } // Plot for pooled-data linear regression fit local pooled_fit : subinstr local aggregate_antigens " ", "_", all local aggregate_antigens : subinstr local aggregate_antigens " ", ", ", all graph twoway lfit yvar xvar if inlist(ANTIGEN, `aggregate_antigens'), /// lcolor(black) name("`pooled_fit'") end * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: use loop to add plots to scatter plot***From:*"Harris, Linda J" <ljharris@scharp.org>

**st: Re: use loop to add plots to scatter plot***From:*"Joseph Coveney" <stajc2@gmail.com>

- Prev by Date:
**st: Re: use loop to add plots to scatter plot** - Next by Date:
**Re: st: Levpet and Time Dummies.** - Previous by thread:
**st: Re: use loop to add plots to scatter plot** - Next by thread:
**Re: st: use loop to add plots to scatter plot** - Index(es):