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 |
Colin Campbell <col.campbell@rocketmail.com> |

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

Subject |
Re: st: Adding kwallis p value to multiple graphs |

Date |
Mon, 24 Sep 2012 04:00:22 -0700 (PDT) |

Thank you Nick, That works a treat, I see where I went wrong. I had tried something similar to your suggestion but had an extra ` in there. Colin p.s. apologies if the reply appears as a new post but I picked up your answer from the Statalist archives as it has not appeared in my inbox so I was not able to reply directly. I have copied the thread title of your answer in the hope it is filed correctly. On Mon, 24 Sep 2012 10:38:06 AM, Nick Cox <njcoxstata@gmail.com> wrote: Try this. Note that the local macro -p- referred to in your code segment does not appear to have been defined. levelsof new_diag, local(levels) foreach l of local levels { foreach var of varlist sex agegroup risk_group origen_redux education_bin { kwallis risk_score if new_diag ==`l', by(`var') local `l'_`var' = chi2tail(r(df), r(chi2)) } twoway kdensity risk_score if new_diag ==`l' & sex ==1 || /// (kdensity risk_score if new_diag ==`l' & sex ==2), /// title("Sexual risk score by sex", position(12)) /// ytitle("Density") /// xtitle("Risk score", size(small)) /// legend(cols(1) label(1 "Male") label(2 "Female") ring(0) position(10) size(small)) /// note("``l'_sex''", ring(0) position(6)) /// saving(`l'_1, replace) scheme(tufte) twoway kdensity risk_score if new_diag ==`l' & agegroup ==1 || /// (kdensity risk_score if new_diag ==`l' & agegroup ==2) || /// (kdensity risk_score if new_diag ==`l' & agegroup ==3) || /// (kdensity risk_score if new_diag ==`l' & agegroup ==4), /// title("Sexual risk score by age group", position(12)) /// ytitle("Density") /// xtitle("Risk score", size(small)) /// legend(cols(1) label(1 "<30") label(2 "30-39") label(3 "40-49") label(4 "50+") ring(0) position(10) size(small)) /// note("``l'_agegroup''", ring(0) position(2)) /// saving(`l'_2, replace) scheme(tufte) } On Mon, Sep 24, 2012 at 10:13 AM, Nick Cox <njcoxstata@gmail.com> wrote: > The problem with your code is that the local macro -var- is undefined, > equivalently empty, outside the -foreach- loop. > > Nick > > On Mon, Sep 24, 2012 at 10:03 AM, Colin Campbell > <col.campbell@rocketmail.com> wrote: > >> I am drawing several graphs within a loop and wish to insert a p value from kwallis into each one in the -note- option. >> How can this be achieved without sacrificing the loop? My attempt at this is shown below. >> I think the problem is in naming the macro(s) that hold(s) the individual p results. >> The new_diag variable take values of 0 or 1 so each graph is drawn twice and needs a different p value. >> >> Any assistance appreciated to face this challenge with fortitude. >> >> Colin >> >> levelsof new_diag, local(levels) >> foreach l of local levels { >> >> foreach var of varlist sex agegroup risk_group origen_redux education_bin { >> >> kwallis risk_score if new_diag ==`l', by(`var') >> local `l'_`var' = chi2tail(r(df), r(chi2)) >> } >> twoway kdensity risk_score if new_diag ==`l' & sex ==1 || /// >> (kdensity risk_score if new_diag ==`l' & sex ==2), /// >> title("Sexual risk score by sex", position(12)) /// >> ytitle("Density") /// >> xtitle("Risk score", size(small)) /// >> legend(cols(1) label(1 "Male") label(2 "Female") ring(0) position(10) size(small)) /// >> note("`l'_`var'", ring(0) position(6)) /// >> saving(`l'_1, replace) scheme(tufte) >> >> twoway kdensity risk_score if new_diag ==`l' & agegroup ==1 || /// >> (kdensity risk_score if new_diag ==`l' & agegroup ==2) || /// >> (kdensity risk_score if new_diag ==`l' & agegroup ==3) || /// >> (kdensity risk_score if new_diag ==`l' & agegroup ==4), /// >> title("Sexual risk score by age group", position(12)) /// >> ytitle("Density") /// >> xtitle("Risk score", size(small)) /// >> legend(cols(1) label(1 "<30") label(2 "30-39") label(3 "40-49") label(4 "50+") ring(0) position(10) size(small)) /// >> note("`p'", ring(0) position(2)) /// >> saving(`l'_2, replace) scheme(tufte) >> >> } >> * * 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/

**Follow-Ups**:**Re: st: Adding kwallis p value to multiple graphs***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**RE: st: Add new observations.** - Next by Date:
**Re: st: Adding kwallis p value to multiple graphs** - Previous by thread:
**Re: st: Adding kwallis p value to multiple graphs** - Next by thread:
**Re: st: Adding kwallis p value to multiple graphs** - Index(es):